@mui/system 5.11.11 → 5.11.12
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/Box/Box.spec.d.ts +1 -1
- package/CHANGELOG.md +144 -0
- package/Container/Container.d.ts +13 -13
- package/Container/ContainerProps.d.ts +40 -40
- package/Container/containerClasses.d.ts +22 -22
- package/Container/createContainer.d.ts +18 -18
- package/Stack/Stack.d.ts +13 -13
- package/Stack/StackProps.d.ts +42 -42
- package/Stack/createStack.d.ts +21 -21
- package/Stack/index.d.ts +5 -5
- package/Stack/stackClasses.d.ts +8 -8
- package/Unstable_Grid/Grid.d.ts +12 -12
- package/Unstable_Grid/GridProps.d.ts +173 -173
- package/Unstable_Grid/createGrid.d.ts +11 -11
- package/Unstable_Grid/gridClasses.d.ts +20 -20
- package/Unstable_Grid/gridGenerator.d.ts +33 -33
- package/Unstable_Grid/index.d.ts +5 -5
- package/createBox.spec.d.ts +1 -1
- package/createTheme/createSpacing.d.ts +10 -10
- package/cssVars/createCssVarsProvider.d.ts +0 -8
- package/cssVars/createCssVarsProvider.js +8 -16
- package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
- package/cssVars/createCssVarsTheme.d.ts +10 -0
- package/cssVars/createCssVarsTheme.js +24 -0
- package/cssVars/createGetCssVar.d.ts +5 -5
- package/cssVars/createGetCssVar.js +1 -1
- package/cssVars/cssVarsParser.d.ts +64 -63
- package/cssVars/cssVarsParser.js +4 -1
- package/cssVars/getInitColorSchemeScript.d.ts +42 -42
- package/cssVars/index.d.ts +5 -3
- package/cssVars/index.js +15 -1
- package/cssVars/prepareCssVars.d.ts +11 -0
- package/cssVars/prepareCssVars.js +70 -0
- package/cssVars/useCurrentColorScheme.d.ts +53 -53
- package/esm/cssVars/createCssVarsProvider.js +8 -16
- package/esm/cssVars/createCssVarsTheme.js +16 -0
- package/esm/cssVars/createGetCssVar.js +1 -1
- package/esm/cssVars/cssVarsParser.js +4 -1
- package/esm/cssVars/index.js +3 -1
- package/esm/cssVars/prepareCssVars.js +62 -0
- package/esm/index.js +3 -0
- package/index.d.ts +3 -0
- package/index.js +25 -1
- package/index.spec.d.ts +1 -1
- package/legacy/cssVars/createCssVarsProvider.js +15 -21
- package/legacy/cssVars/createCssVarsTheme.js +13 -0
- package/legacy/cssVars/createGetCssVar.js +1 -1
- package/legacy/cssVars/cssVarsParser.js +4 -1
- package/legacy/cssVars/index.js +3 -1
- package/legacy/cssVars/prepareCssVars.js +59 -0
- package/legacy/index.js +4 -1
- package/modern/cssVars/createCssVarsProvider.js +8 -16
- package/modern/cssVars/createCssVarsTheme.js +16 -0
- package/modern/cssVars/createGetCssVar.js +1 -1
- package/modern/cssVars/cssVarsParser.js +4 -1
- package/modern/cssVars/index.js +3 -1
- package/modern/cssVars/prepareCssVars.js +62 -0
- package/modern/index.js +4 -1
- package/package.json +3 -3
- package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
10
|
+
var _prepareCssVars = _interopRequireDefault(require("./prepareCssVars"));
|
|
11
|
+
const _excluded = ["cssVarPrefix", "shouldSkipGeneratingVar"];
|
|
12
|
+
function createCssVarsTheme(theme) {
|
|
13
|
+
const {
|
|
14
|
+
cssVarPrefix,
|
|
15
|
+
shouldSkipGeneratingVar
|
|
16
|
+
} = theme,
|
|
17
|
+
otherTheme = (0, _objectWithoutPropertiesLoose2.default)(theme, _excluded);
|
|
18
|
+
return (0, _extends2.default)({}, theme, (0, _prepareCssVars.default)(otherTheme, {
|
|
19
|
+
prefix: cssVarPrefix,
|
|
20
|
+
shouldSkipGeneratingVar
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
var _default = createCssVarsTheme;
|
|
24
|
+
exports.default = _default;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The benefit of this function is to help developers get CSS var from theme without specifying the whole variable
|
|
3
|
-
* and they does not need to remember the prefix (defined once).
|
|
4
|
-
*/
|
|
5
|
-
export default function createGetCssVar<T extends string = string>(prefix?: string): <AdditionalVars extends string = never>(field: T | AdditionalVars, ...fallbacks: (T | AdditionalVars)[]) => string;
|
|
1
|
+
/**
|
|
2
|
+
* The benefit of this function is to help developers get CSS var from theme without specifying the whole variable
|
|
3
|
+
* and they does not need to remember the prefix (defined once).
|
|
4
|
+
*/
|
|
5
|
+
export default function createGetCssVar<T extends string = string>(prefix?: string): <AdditionalVars extends string = never>(field: T | AdditionalVars, ...fallbacks: (T | AdditionalVars)[]) => string;
|
|
@@ -14,7 +14,7 @@ function createGetCssVar(prefix = '') {
|
|
|
14
14
|
return '';
|
|
15
15
|
}
|
|
16
16
|
const value = vars[0];
|
|
17
|
-
if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))/)) {
|
|
17
|
+
if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))|^(-?(\d*\.)?\d+)$|(\d+ \d+ \d+)/)) {
|
|
18
18
|
return `, var(--${prefix ? `${prefix}-` : ''}${value}${appendVar(...vars.slice(1))})`;
|
|
19
19
|
}
|
|
20
20
|
return `, ${value}`;
|
|
@@ -1,63 +1,64 @@
|
|
|
1
|
-
type NestedRecord<V = any> = {
|
|
2
|
-
[k: string | number]: NestedRecord<V> | V;
|
|
3
|
-
};
|
|
4
|
-
/**
|
|
5
|
-
* This function create an object from keys, value and then assign to target
|
|
6
|
-
*
|
|
7
|
-
* @param {Object} obj : the target object to be assigned
|
|
8
|
-
* @param {string[]} keys
|
|
9
|
-
* @param {string | number} value
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* const source = {}
|
|
13
|
-
* assignNestedKeys(source, ['palette', 'primary'], 'var(--palette-primary)')
|
|
14
|
-
* console.log(source) // { palette: { primary: 'var(--palette-primary)' } }
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* const source = { palette: { primary: 'var(--palette-primary)' } }
|
|
18
|
-
* assignNestedKeys(source, ['palette', 'secondary'], 'var(--palette-secondary)')
|
|
19
|
-
* console.log(source) // { palette: { primary: 'var(--palette-primary)', secondary: 'var(--palette-secondary)' } }
|
|
20
|
-
*/
|
|
21
|
-
export declare const assignNestedKeys: <T extends string | Record<string, any> | null | undefined = NestedRecord<any>, Value = any>(obj: T, keys: Array<string>, value: Value, arrayKeys?: Array<string>) => void;
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
* @param {Object} obj : source object
|
|
25
|
-
* @param {Function} callback : a function that will be called when
|
|
26
|
-
* - the deepest key in source object is reached
|
|
27
|
-
* - the value of the deepest key is NOT `undefined` | `null`
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* walkObjectDeep({ palette: { primary: { main: '#000000' } } }, console.log)
|
|
31
|
-
* // ['palette', 'primary', 'main'] '#000000'
|
|
32
|
-
*/
|
|
33
|
-
export declare const walkObjectDeep: <Value, T = Record<string, any>>(obj: T, callback: (keys: Array<string>, value: Value, arrayKeys: Array<string>) => void, shouldSkipPaths?: ((keys: Array<string>) => boolean) | undefined) => void;
|
|
34
|
-
/**
|
|
35
|
-
* a function that parse theme and return { css, vars }
|
|
36
|
-
*
|
|
37
|
-
* @param {Object} theme
|
|
38
|
-
* @param {{
|
|
39
|
-
* prefix?: string,
|
|
40
|
-
* shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean
|
|
41
|
-
* }} options.
|
|
42
|
-
* `prefix`: The prefix of the generated CSS variables. This function does not change the value.
|
|
43
|
-
*
|
|
44
|
-
* @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme).
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* const { css, vars } = parser({
|
|
48
|
-
* fontSize: 12,
|
|
49
|
-
* lineHeight: 1.2,
|
|
50
|
-
* palette: { primary: { 500: 'var(--color)' } }
|
|
51
|
-
* }, { prefix: 'foo' })
|
|
52
|
-
*
|
|
53
|
-
* console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--color)' }
|
|
54
|
-
* console.log(vars) // { fontSize: 'var(--foo-fontSize)', lineHeight: 'var(--foo-lineHeight)', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
|
|
55
|
-
*/
|
|
56
|
-
export default function cssVarsParser<T extends Record<string, any>>(theme: T, options?: {
|
|
57
|
-
prefix?: string;
|
|
58
|
-
shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
|
|
59
|
-
}): {
|
|
60
|
-
css: Record<string, string | number>;
|
|
61
|
-
vars: NestedRecord<string>;
|
|
62
|
-
};
|
|
63
|
-
|
|
1
|
+
type NestedRecord<V = any> = {
|
|
2
|
+
[k: string | number]: NestedRecord<V> | V;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* This function create an object from keys, value and then assign to target
|
|
6
|
+
*
|
|
7
|
+
* @param {Object} obj : the target object to be assigned
|
|
8
|
+
* @param {string[]} keys
|
|
9
|
+
* @param {string | number} value
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const source = {}
|
|
13
|
+
* assignNestedKeys(source, ['palette', 'primary'], 'var(--palette-primary)')
|
|
14
|
+
* console.log(source) // { palette: { primary: 'var(--palette-primary)' } }
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const source = { palette: { primary: 'var(--palette-primary)' } }
|
|
18
|
+
* assignNestedKeys(source, ['palette', 'secondary'], 'var(--palette-secondary)')
|
|
19
|
+
* console.log(source) // { palette: { primary: 'var(--palette-primary)', secondary: 'var(--palette-secondary)' } }
|
|
20
|
+
*/
|
|
21
|
+
export declare const assignNestedKeys: <T extends string | Record<string, any> | null | undefined = NestedRecord<any>, Value = any>(obj: T, keys: Array<string>, value: Value, arrayKeys?: Array<string>) => void;
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @param {Object} obj : source object
|
|
25
|
+
* @param {Function} callback : a function that will be called when
|
|
26
|
+
* - the deepest key in source object is reached
|
|
27
|
+
* - the value of the deepest key is NOT `undefined` | `null`
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* walkObjectDeep({ palette: { primary: { main: '#000000' } } }, console.log)
|
|
31
|
+
* // ['palette', 'primary', 'main'] '#000000'
|
|
32
|
+
*/
|
|
33
|
+
export declare const walkObjectDeep: <Value, T = Record<string, any>>(obj: T, callback: (keys: Array<string>, value: Value, arrayKeys: Array<string>) => void, shouldSkipPaths?: ((keys: Array<string>) => boolean) | undefined) => void;
|
|
34
|
+
/**
|
|
35
|
+
* a function that parse theme and return { css, vars }
|
|
36
|
+
*
|
|
37
|
+
* @param {Object} theme
|
|
38
|
+
* @param {{
|
|
39
|
+
* prefix?: string,
|
|
40
|
+
* shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean
|
|
41
|
+
* }} options.
|
|
42
|
+
* `prefix`: The prefix of the generated CSS variables. This function does not change the value.
|
|
43
|
+
*
|
|
44
|
+
* @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme).
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* const { css, vars } = parser({
|
|
48
|
+
* fontSize: 12,
|
|
49
|
+
* lineHeight: 1.2,
|
|
50
|
+
* palette: { primary: { 500: 'var(--color)' } }
|
|
51
|
+
* }, { prefix: 'foo' })
|
|
52
|
+
*
|
|
53
|
+
* console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--color)' }
|
|
54
|
+
* console.log(vars) // { fontSize: 'var(--foo-fontSize)', lineHeight: 'var(--foo-lineHeight)', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
|
|
55
|
+
*/
|
|
56
|
+
export default function cssVarsParser<T extends Record<string, any>>(theme: T, options?: {
|
|
57
|
+
prefix?: string;
|
|
58
|
+
shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
|
|
59
|
+
}): {
|
|
60
|
+
css: Record<string, string | number>;
|
|
61
|
+
vars: NestedRecord<string>;
|
|
62
|
+
varsWithDefaults: {};
|
|
63
|
+
};
|
|
64
|
+
export {};
|
package/cssVars/cssVarsParser.js
CHANGED
|
@@ -115,6 +115,7 @@ function cssVarsParser(theme, options) {
|
|
|
115
115
|
} = options || {};
|
|
116
116
|
const css = {};
|
|
117
117
|
const vars = {};
|
|
118
|
+
const varsWithDefaults = {};
|
|
118
119
|
walkObjectDeep(theme, (keys, value, arrayKeys) => {
|
|
119
120
|
if (typeof value === 'string' || typeof value === 'number') {
|
|
120
121
|
if (!shouldSkipGeneratingVar || !shouldSkipGeneratingVar(keys, value)) {
|
|
@@ -124,6 +125,7 @@ function cssVarsParser(theme, options) {
|
|
|
124
125
|
[cssVar]: getCssValue(keys, value)
|
|
125
126
|
});
|
|
126
127
|
assignNestedKeys(vars, keys, `var(${cssVar})`, arrayKeys);
|
|
128
|
+
assignNestedKeys(varsWithDefaults, keys, `var(${cssVar}, ${value})`, arrayKeys);
|
|
127
129
|
}
|
|
128
130
|
}
|
|
129
131
|
}, keys => keys[0] === 'vars' // skip 'vars/*' paths
|
|
@@ -131,6 +133,7 @@ function cssVarsParser(theme, options) {
|
|
|
131
133
|
|
|
132
134
|
return {
|
|
133
135
|
css,
|
|
134
|
-
vars
|
|
136
|
+
vars,
|
|
137
|
+
varsWithDefaults
|
|
135
138
|
};
|
|
136
139
|
}
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
export declare const DEFAULT_MODE_STORAGE_KEY = "mode";
|
|
3
|
-
export declare const DEFAULT_COLOR_SCHEME_STORAGE_KEY = "color-scheme";
|
|
4
|
-
export declare const DEFAULT_ATTRIBUTE = "data-color-scheme";
|
|
5
|
-
export interface GetInitColorSchemeScriptOptions {
|
|
6
|
-
/**
|
|
7
|
-
* The mode to be used for the first visit
|
|
8
|
-
* @default 'light'
|
|
9
|
-
*/
|
|
10
|
-
defaultMode?: 'light' | 'dark' | 'system';
|
|
11
|
-
/**
|
|
12
|
-
* The default color scheme to be used on the light mode
|
|
13
|
-
* @default 'light'
|
|
14
|
-
*/
|
|
15
|
-
defaultLightColorScheme?: string;
|
|
16
|
-
/**
|
|
17
|
-
* The default color scheme to be used on the dark mode
|
|
18
|
-
* * @default 'dark'
|
|
19
|
-
*/
|
|
20
|
-
defaultDarkColorScheme?: string;
|
|
21
|
-
/**
|
|
22
|
-
* The node (provided as string) used to attach the color-scheme attribute
|
|
23
|
-
* @default 'document.documentElement'
|
|
24
|
-
*/
|
|
25
|
-
colorSchemeNode?: string;
|
|
26
|
-
/**
|
|
27
|
-
* localStorage key used to store `mode`
|
|
28
|
-
* @default 'mode'
|
|
29
|
-
*/
|
|
30
|
-
modeStorageKey?: string;
|
|
31
|
-
/**
|
|
32
|
-
* localStorage key used to store `colorScheme`
|
|
33
|
-
* @default 'color-scheme'
|
|
34
|
-
*/
|
|
35
|
-
colorSchemeStorageKey?: string;
|
|
36
|
-
/**
|
|
37
|
-
* DOM attribute for applying color scheme
|
|
38
|
-
* @default 'data-color-scheme'
|
|
39
|
-
*/
|
|
40
|
-
attribute?: string;
|
|
41
|
-
}
|
|
42
|
-
export default function getInitColorSchemeScript(options?: GetInitColorSchemeScriptOptions): JSX.Element;
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const DEFAULT_MODE_STORAGE_KEY = "mode";
|
|
3
|
+
export declare const DEFAULT_COLOR_SCHEME_STORAGE_KEY = "color-scheme";
|
|
4
|
+
export declare const DEFAULT_ATTRIBUTE = "data-color-scheme";
|
|
5
|
+
export interface GetInitColorSchemeScriptOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The mode to be used for the first visit
|
|
8
|
+
* @default 'light'
|
|
9
|
+
*/
|
|
10
|
+
defaultMode?: 'light' | 'dark' | 'system';
|
|
11
|
+
/**
|
|
12
|
+
* The default color scheme to be used on the light mode
|
|
13
|
+
* @default 'light'
|
|
14
|
+
*/
|
|
15
|
+
defaultLightColorScheme?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The default color scheme to be used on the dark mode
|
|
18
|
+
* * @default 'dark'
|
|
19
|
+
*/
|
|
20
|
+
defaultDarkColorScheme?: string;
|
|
21
|
+
/**
|
|
22
|
+
* The node (provided as string) used to attach the color-scheme attribute
|
|
23
|
+
* @default 'document.documentElement'
|
|
24
|
+
*/
|
|
25
|
+
colorSchemeNode?: string;
|
|
26
|
+
/**
|
|
27
|
+
* localStorage key used to store `mode`
|
|
28
|
+
* @default 'mode'
|
|
29
|
+
*/
|
|
30
|
+
modeStorageKey?: string;
|
|
31
|
+
/**
|
|
32
|
+
* localStorage key used to store `colorScheme`
|
|
33
|
+
* @default 'color-scheme'
|
|
34
|
+
*/
|
|
35
|
+
colorSchemeStorageKey?: string;
|
|
36
|
+
/**
|
|
37
|
+
* DOM attribute for applying color scheme
|
|
38
|
+
* @default 'data-color-scheme'
|
|
39
|
+
*/
|
|
40
|
+
attribute?: string;
|
|
41
|
+
}
|
|
42
|
+
export default function getInitColorSchemeScript(options?: GetInitColorSchemeScriptOptions): JSX.Element;
|
package/cssVars/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export { default } from './createCssVarsProvider';
|
|
2
|
-
export type { CreateCssVarsProviderResult, CssVarsProviderConfig, ColorSchemeContextValue, } from './createCssVarsProvider';
|
|
3
|
-
export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
|
|
1
|
+
export { default } from './createCssVarsProvider';
|
|
2
|
+
export type { CreateCssVarsProviderResult, CssVarsProviderConfig, ColorSchemeContextValue, } from './createCssVarsProvider';
|
|
3
|
+
export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
|
|
4
|
+
export { default as prepareCssVars } from './prepareCssVars';
|
|
5
|
+
export { default as createCssVarsTheme } from './createCssVarsTheme';
|
package/cssVars/index.js
CHANGED
|
@@ -4,6 +4,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
+
Object.defineProperty(exports, "createCssVarsTheme", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _createCssVarsTheme.default;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
7
13
|
Object.defineProperty(exports, "default", {
|
|
8
14
|
enumerable: true,
|
|
9
15
|
get: function () {
|
|
@@ -16,5 +22,13 @@ Object.defineProperty(exports, "getInitColorSchemeScript", {
|
|
|
16
22
|
return _getInitColorSchemeScript.default;
|
|
17
23
|
}
|
|
18
24
|
});
|
|
25
|
+
Object.defineProperty(exports, "prepareCssVars", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return _prepareCssVars.default;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
19
31
|
var _createCssVarsProvider = _interopRequireDefault(require("./createCssVarsProvider"));
|
|
20
|
-
var _getInitColorSchemeScript = _interopRequireDefault(require("./getInitColorSchemeScript"));
|
|
32
|
+
var _getInitColorSchemeScript = _interopRequireDefault(require("./getInitColorSchemeScript"));
|
|
33
|
+
var _prepareCssVars = _interopRequireDefault(require("./prepareCssVars"));
|
|
34
|
+
var _createCssVarsTheme = _interopRequireDefault(require("./createCssVarsTheme"));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface DefaultCssVarsTheme {
|
|
2
|
+
colorSchemes: Record<string, any>;
|
|
3
|
+
}
|
|
4
|
+
declare function prepareCssVars<T extends DefaultCssVarsTheme, ThemeVars>(theme: T, parserConfig?: {
|
|
5
|
+
prefix?: string;
|
|
6
|
+
shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
|
|
7
|
+
}): {
|
|
8
|
+
vars: ThemeVars;
|
|
9
|
+
generateCssVars: (colorScheme?: string) => any;
|
|
10
|
+
};
|
|
11
|
+
export default prepareCssVars;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
9
|
+
var _utils = require("@mui/utils");
|
|
10
|
+
var _cssVarsParser = _interopRequireDefault(require("./cssVarsParser"));
|
|
11
|
+
const _excluded = ["colorSchemes", "components"],
|
|
12
|
+
_excluded2 = ["light"];
|
|
13
|
+
function prepareCssVars(theme, parserConfig) {
|
|
14
|
+
// @ts-ignore - ignore components do not exist
|
|
15
|
+
const {
|
|
16
|
+
colorSchemes = {}
|
|
17
|
+
} = theme,
|
|
18
|
+
otherTheme = (0, _objectWithoutPropertiesLoose2.default)(theme, _excluded);
|
|
19
|
+
const {
|
|
20
|
+
vars: rootVars,
|
|
21
|
+
css: rootCss,
|
|
22
|
+
varsWithDefaults: rootVarsWithDefaults
|
|
23
|
+
} = (0, _cssVarsParser.default)(otherTheme, parserConfig);
|
|
24
|
+
let themeVars = rootVarsWithDefaults;
|
|
25
|
+
const colorSchemesMap = {};
|
|
26
|
+
const {
|
|
27
|
+
light
|
|
28
|
+
} = colorSchemes,
|
|
29
|
+
otherColorSchemes = (0, _objectWithoutPropertiesLoose2.default)(colorSchemes, _excluded2);
|
|
30
|
+
Object.entries(otherColorSchemes || {}).forEach(([key, scheme]) => {
|
|
31
|
+
const {
|
|
32
|
+
vars,
|
|
33
|
+
css,
|
|
34
|
+
varsWithDefaults
|
|
35
|
+
} = (0, _cssVarsParser.default)(scheme, parserConfig);
|
|
36
|
+
themeVars = (0, _utils.deepmerge)(themeVars, varsWithDefaults);
|
|
37
|
+
colorSchemesMap[key] = {
|
|
38
|
+
css,
|
|
39
|
+
vars
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
if (light) {
|
|
43
|
+
// light color scheme vars should be merged last to set as default
|
|
44
|
+
const {
|
|
45
|
+
css,
|
|
46
|
+
vars,
|
|
47
|
+
varsWithDefaults
|
|
48
|
+
} = (0, _cssVarsParser.default)(light, parserConfig);
|
|
49
|
+
themeVars = (0, _utils.deepmerge)(themeVars, varsWithDefaults);
|
|
50
|
+
colorSchemesMap.light = {
|
|
51
|
+
css,
|
|
52
|
+
vars
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const generateCssVars = colorScheme => {
|
|
56
|
+
if (!colorScheme) {
|
|
57
|
+
return {
|
|
58
|
+
css: rootCss,
|
|
59
|
+
vars: rootVars
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return colorSchemesMap[colorScheme];
|
|
63
|
+
};
|
|
64
|
+
return {
|
|
65
|
+
vars: themeVars,
|
|
66
|
+
generateCssVars
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
var _default = prepareCssVars;
|
|
70
|
+
exports.default = _default;
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
export type Mode = 'light' | 'dark' | 'system';
|
|
2
|
-
export type SystemMode = Exclude<Mode, 'system'>;
|
|
3
|
-
export interface State<SupportedColorScheme extends string> {
|
|
4
|
-
/**
|
|
5
|
-
* User selected mode.
|
|
6
|
-
* Note: on the server, mode is always undefined
|
|
7
|
-
*/
|
|
8
|
-
mode: Mode | undefined;
|
|
9
|
-
/**
|
|
10
|
-
* Only valid if `mode: 'system'`, either 'light' | 'dark'.
|
|
11
|
-
*/
|
|
12
|
-
systemMode: SystemMode | undefined;
|
|
13
|
-
/**
|
|
14
|
-
* The color scheme for the light mode.
|
|
15
|
-
*/
|
|
16
|
-
lightColorScheme: SupportedColorScheme;
|
|
17
|
-
/**
|
|
18
|
-
* The color scheme for the dark mode.
|
|
19
|
-
*/
|
|
20
|
-
darkColorScheme: SupportedColorScheme;
|
|
21
|
-
}
|
|
22
|
-
export type Result<SupportedColorScheme extends string> = State<SupportedColorScheme> & {
|
|
23
|
-
/**
|
|
24
|
-
* The current application color scheme. It is always `undefined` on the server.
|
|
25
|
-
*/
|
|
26
|
-
colorScheme: SupportedColorScheme | undefined;
|
|
27
|
-
/**
|
|
28
|
-
* `mode` is saved to internal state and localStorage
|
|
29
|
-
* If `mode` is null, it will be reset to the defaultMode
|
|
30
|
-
*/
|
|
31
|
-
setMode: (mode: Mode | null) => void;
|
|
32
|
-
/**
|
|
33
|
-
* `colorScheme` is saved to internal state and localStorage
|
|
34
|
-
* If `colorScheme` is null, it will be reset to the defaultColorScheme (light | dark)
|
|
35
|
-
*/
|
|
36
|
-
setColorScheme: (colorScheme: SupportedColorScheme | Partial<{
|
|
37
|
-
light: SupportedColorScheme | null;
|
|
38
|
-
dark: SupportedColorScheme | null;
|
|
39
|
-
}> | null) => void;
|
|
40
|
-
};
|
|
41
|
-
export declare function getSystemMode(mode: undefined | string): SystemMode | undefined;
|
|
42
|
-
export declare function getColorScheme<SupportedColorScheme extends string>(state: State<SupportedColorScheme>): SupportedColorScheme | undefined;
|
|
43
|
-
interface UseCurrentColoSchemeOptions<SupportedColorScheme extends string> {
|
|
44
|
-
defaultLightColorScheme: SupportedColorScheme;
|
|
45
|
-
defaultDarkColorScheme: SupportedColorScheme;
|
|
46
|
-
supportedColorSchemes: Array<SupportedColorScheme>;
|
|
47
|
-
defaultMode?: Mode;
|
|
48
|
-
modeStorageKey?: string;
|
|
49
|
-
colorSchemeStorageKey?: string;
|
|
50
|
-
storageWindow?: Window | null;
|
|
51
|
-
}
|
|
52
|
-
export default function useCurrentColorScheme<SupportedColorScheme extends string>(options: UseCurrentColoSchemeOptions<SupportedColorScheme>): Result<SupportedColorScheme>;
|
|
53
|
-
export {};
|
|
1
|
+
export type Mode = 'light' | 'dark' | 'system';
|
|
2
|
+
export type SystemMode = Exclude<Mode, 'system'>;
|
|
3
|
+
export interface State<SupportedColorScheme extends string> {
|
|
4
|
+
/**
|
|
5
|
+
* User selected mode.
|
|
6
|
+
* Note: on the server, mode is always undefined
|
|
7
|
+
*/
|
|
8
|
+
mode: Mode | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Only valid if `mode: 'system'`, either 'light' | 'dark'.
|
|
11
|
+
*/
|
|
12
|
+
systemMode: SystemMode | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* The color scheme for the light mode.
|
|
15
|
+
*/
|
|
16
|
+
lightColorScheme: SupportedColorScheme;
|
|
17
|
+
/**
|
|
18
|
+
* The color scheme for the dark mode.
|
|
19
|
+
*/
|
|
20
|
+
darkColorScheme: SupportedColorScheme;
|
|
21
|
+
}
|
|
22
|
+
export type Result<SupportedColorScheme extends string> = State<SupportedColorScheme> & {
|
|
23
|
+
/**
|
|
24
|
+
* The current application color scheme. It is always `undefined` on the server.
|
|
25
|
+
*/
|
|
26
|
+
colorScheme: SupportedColorScheme | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* `mode` is saved to internal state and localStorage
|
|
29
|
+
* If `mode` is null, it will be reset to the defaultMode
|
|
30
|
+
*/
|
|
31
|
+
setMode: (mode: Mode | null) => void;
|
|
32
|
+
/**
|
|
33
|
+
* `colorScheme` is saved to internal state and localStorage
|
|
34
|
+
* If `colorScheme` is null, it will be reset to the defaultColorScheme (light | dark)
|
|
35
|
+
*/
|
|
36
|
+
setColorScheme: (colorScheme: SupportedColorScheme | Partial<{
|
|
37
|
+
light: SupportedColorScheme | null;
|
|
38
|
+
dark: SupportedColorScheme | null;
|
|
39
|
+
}> | null) => void;
|
|
40
|
+
};
|
|
41
|
+
export declare function getSystemMode(mode: undefined | string): SystemMode | undefined;
|
|
42
|
+
export declare function getColorScheme<SupportedColorScheme extends string>(state: State<SupportedColorScheme>): SupportedColorScheme | undefined;
|
|
43
|
+
interface UseCurrentColoSchemeOptions<SupportedColorScheme extends string> {
|
|
44
|
+
defaultLightColorScheme: SupportedColorScheme;
|
|
45
|
+
defaultDarkColorScheme: SupportedColorScheme;
|
|
46
|
+
supportedColorSchemes: Array<SupportedColorScheme>;
|
|
47
|
+
defaultMode?: Mode;
|
|
48
|
+
modeStorageKey?: string;
|
|
49
|
+
colorSchemeStorageKey?: string;
|
|
50
|
+
storageWindow?: Window | null;
|
|
51
|
+
}
|
|
52
|
+
export default function useCurrentColorScheme<SupportedColorScheme extends string>(options: UseCurrentColoSchemeOptions<SupportedColorScheme>): Result<SupportedColorScheme>;
|
|
53
|
+
export {};
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
3
|
import { formatMuiErrorMessage as _formatMuiErrorMessage } from "@mui/utils";
|
|
4
|
-
const _excluded = ["colorSchemes", "components", "cssVarPrefix"];
|
|
4
|
+
const _excluded = ["colorSchemes", "components", "generateCssVars", "cssVarPrefix"];
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
7
7
|
import { deepmerge } from '@mui/utils';
|
|
8
8
|
import { GlobalStyles } from '@mui/styled-engine';
|
|
9
9
|
import { useTheme as muiUseTheme } from '@mui/private-theming';
|
|
10
|
-
import cssVarsParser from './cssVarsParser';
|
|
11
10
|
import ThemeProvider from '../ThemeProvider';
|
|
12
11
|
import systemGetInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_COLOR_SCHEME_STORAGE_KEY, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
|
|
13
12
|
import useCurrentColorScheme from './useCurrentColorScheme';
|
|
@@ -23,7 +22,6 @@ export default function createCssVarsProvider(options) {
|
|
|
23
22
|
defaultMode: designSystemMode = 'light',
|
|
24
23
|
defaultColorScheme: designSystemColorScheme,
|
|
25
24
|
disableTransitionOnChange: designSystemTransitionOnChange = false,
|
|
26
|
-
shouldSkipGeneratingVar: designSystemShouldSkipGeneratingVar,
|
|
27
25
|
resolveTheme,
|
|
28
26
|
excludeVariablesFromRoot
|
|
29
27
|
} = options;
|
|
@@ -51,7 +49,6 @@ export default function createCssVarsProvider(options) {
|
|
|
51
49
|
documentNode = typeof document === 'undefined' ? undefined : document,
|
|
52
50
|
colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
|
|
53
51
|
colorSchemeSelector = ':root',
|
|
54
|
-
shouldSkipGeneratingVar = designSystemShouldSkipGeneratingVar,
|
|
55
52
|
disableNestedContext = false,
|
|
56
53
|
disableStyleSheetGeneration = false
|
|
57
54
|
}) {
|
|
@@ -62,6 +59,10 @@ export default function createCssVarsProvider(options) {
|
|
|
62
59
|
const {
|
|
63
60
|
colorSchemes = {},
|
|
64
61
|
components = {},
|
|
62
|
+
generateCssVars = () => ({
|
|
63
|
+
vars: {},
|
|
64
|
+
css: {}
|
|
65
|
+
}),
|
|
65
66
|
cssVarPrefix
|
|
66
67
|
} = themeProp,
|
|
67
68
|
restThemeProp = _objectWithoutPropertiesLoose(themeProp, _excluded);
|
|
@@ -119,10 +120,7 @@ export default function createCssVarsProvider(options) {
|
|
|
119
120
|
const {
|
|
120
121
|
css: rootCss,
|
|
121
122
|
vars: rootVars
|
|
122
|
-
} =
|
|
123
|
-
prefix: cssVarPrefix,
|
|
124
|
-
shouldSkipGeneratingVar
|
|
125
|
-
});
|
|
123
|
+
} = generateCssVars();
|
|
126
124
|
|
|
127
125
|
// 3. Start composing the theme object
|
|
128
126
|
const theme = _extends({}, restThemeProp, {
|
|
@@ -142,10 +140,7 @@ export default function createCssVarsProvider(options) {
|
|
|
142
140
|
const {
|
|
143
141
|
css,
|
|
144
142
|
vars
|
|
145
|
-
} =
|
|
146
|
-
prefix: cssVarPrefix,
|
|
147
|
-
shouldSkipGeneratingVar
|
|
148
|
-
});
|
|
143
|
+
} = generateCssVars(key);
|
|
149
144
|
theme.vars = deepmerge(theme.vars, vars);
|
|
150
145
|
if (key === calculatedColorScheme) {
|
|
151
146
|
// 4.1 Merge the selected color scheme to the theme
|
|
@@ -184,6 +179,7 @@ export default function createCssVarsProvider(options) {
|
|
|
184
179
|
otherColorSchemesStyleSheet[`${colorSchemeSelector === ':root' ? '' : colorSchemeSelector}[${attribute}="${key}"]`] = css;
|
|
185
180
|
}
|
|
186
181
|
});
|
|
182
|
+
theme.vars = deepmerge(theme.vars, rootVars);
|
|
187
183
|
|
|
188
184
|
// 5. Declaring effects
|
|
189
185
|
// 5.1 Updates the selector value to use the current color scheme which tells CSS to use the proper stylesheet.
|
|
@@ -308,10 +304,6 @@ export default function createCssVarsProvider(options) {
|
|
|
308
304
|
* The key in the local storage used to store current color scheme.
|
|
309
305
|
*/
|
|
310
306
|
modeStorageKey: PropTypes.string,
|
|
311
|
-
/**
|
|
312
|
-
* A function to determine if the key, value should be attached as CSS Variable
|
|
313
|
-
*/
|
|
314
|
-
shouldSkipGeneratingVar: PropTypes.func,
|
|
315
307
|
/**
|
|
316
308
|
* The window that attaches the 'storage' event listener
|
|
317
309
|
* @default window
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["cssVarPrefix", "shouldSkipGeneratingVar"];
|
|
4
|
+
import prepareCssVars from './prepareCssVars';
|
|
5
|
+
function createCssVarsTheme(theme) {
|
|
6
|
+
const {
|
|
7
|
+
cssVarPrefix,
|
|
8
|
+
shouldSkipGeneratingVar
|
|
9
|
+
} = theme,
|
|
10
|
+
otherTheme = _objectWithoutPropertiesLoose(theme, _excluded);
|
|
11
|
+
return _extends({}, theme, prepareCssVars(otherTheme, {
|
|
12
|
+
prefix: cssVarPrefix,
|
|
13
|
+
shouldSkipGeneratingVar
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
export default createCssVarsTheme;
|
|
@@ -8,7 +8,7 @@ export default function createGetCssVar(prefix = '') {
|
|
|
8
8
|
return '';
|
|
9
9
|
}
|
|
10
10
|
const value = vars[0];
|
|
11
|
-
if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))/)) {
|
|
11
|
+
if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))|^(-?(\d*\.)?\d+)$|(\d+ \d+ \d+)/)) {
|
|
12
12
|
return `, var(--${prefix ? `${prefix}-` : ''}${value}${appendVar(...vars.slice(1))})`;
|
|
13
13
|
}
|
|
14
14
|
return `, ${value}`;
|
|
@@ -105,6 +105,7 @@ export default function cssVarsParser(theme, options) {
|
|
|
105
105
|
} = options || {};
|
|
106
106
|
const css = {};
|
|
107
107
|
const vars = {};
|
|
108
|
+
const varsWithDefaults = {};
|
|
108
109
|
walkObjectDeep(theme, (keys, value, arrayKeys) => {
|
|
109
110
|
if (typeof value === 'string' || typeof value === 'number') {
|
|
110
111
|
if (!shouldSkipGeneratingVar || !shouldSkipGeneratingVar(keys, value)) {
|
|
@@ -114,6 +115,7 @@ export default function cssVarsParser(theme, options) {
|
|
|
114
115
|
[cssVar]: getCssValue(keys, value)
|
|
115
116
|
});
|
|
116
117
|
assignNestedKeys(vars, keys, `var(${cssVar})`, arrayKeys);
|
|
118
|
+
assignNestedKeys(varsWithDefaults, keys, `var(${cssVar}, ${value})`, arrayKeys);
|
|
117
119
|
}
|
|
118
120
|
}
|
|
119
121
|
}, keys => keys[0] === 'vars' // skip 'vars/*' paths
|
|
@@ -121,6 +123,7 @@ export default function cssVarsParser(theme, options) {
|
|
|
121
123
|
|
|
122
124
|
return {
|
|
123
125
|
css,
|
|
124
|
-
vars
|
|
126
|
+
vars,
|
|
127
|
+
varsWithDefaults
|
|
125
128
|
};
|
|
126
129
|
}
|
package/esm/cssVars/index.js
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export { default } from './createCssVarsProvider';
|
|
2
|
-
export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
|
|
2
|
+
export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
|
|
3
|
+
export { default as prepareCssVars } from './prepareCssVars';
|
|
4
|
+
export { default as createCssVarsTheme } from './createCssVarsTheme';
|