@mui/system 5.4.1 → 5.4.4
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.d.ts +1 -1
- package/Box/Box.spec.d.ts +1 -1
- package/CHANGELOG.md +177 -0
- package/createBox.d.ts +2 -0
- package/createBox.js +3 -2
- package/createBox.spec.d.ts +1 -1
- package/createStyled.d.ts +2 -1
- package/createStyled.js +12 -6
- package/createTheme/createBreakpoints.js +21 -6
- package/createTheme/createSpacing.d.ts +10 -10
- package/cssVars/createCssVarsProvider.d.ts +59 -95
- package/cssVars/createCssVarsProvider.js +32 -15
- package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
- package/cssVars/createGetCssVar.d.ts +5 -5
- package/cssVars/createGetCssVar.js +7 -1
- package/cssVars/cssVarsParser.d.ts +70 -68
- package/cssVars/cssVarsParser.js +21 -20
- package/cssVars/getInitColorSchemeScript.d.ts +12 -12
- package/cssVars/index.d.ts +1 -2
- package/cssVars/useCurrentColorScheme.d.ts +50 -50
- package/esm/createBox.js +3 -2
- package/esm/createStyled.js +10 -4
- package/esm/createTheme/createBreakpoints.js +20 -4
- package/esm/cssVars/createCssVarsProvider.js +32 -16
- package/esm/cssVars/createGetCssVar.js +7 -1
- package/esm/cssVars/cssVarsParser.js +21 -20
- package/esm/getThemeValue.js +1 -1
- package/esm/index.js +1 -1
- package/esm/styleFunctionSx/index.js +1 -0
- package/esm/styleFunctionSx/styleFunctionSx.js +78 -51
- package/getThemeValue.js +2 -1
- package/index.d.ts +1 -0
- package/index.js +8 -1
- package/index.spec.d.ts +1 -1
- package/legacy/createBox.js +4 -2
- package/legacy/createStyled.js +11 -4
- package/legacy/createTheme/createBreakpoints.js +23 -4
- package/legacy/cssVars/createCssVarsProvider.js +35 -18
- package/legacy/cssVars/createGetCssVar.js +7 -1
- package/legacy/cssVars/cssVarsParser.js +23 -22
- package/legacy/getThemeValue.js +1 -1
- package/legacy/index.js +2 -2
- package/legacy/styleFunctionSx/index.js +1 -0
- package/legacy/styleFunctionSx/styleFunctionSx.js +76 -51
- package/modern/createBox.js +3 -2
- package/modern/createStyled.js +10 -4
- package/modern/createTheme/createBreakpoints.js +20 -4
- package/modern/cssVars/createCssVarsProvider.js +32 -16
- package/modern/cssVars/createGetCssVar.js +7 -1
- package/modern/cssVars/cssVarsParser.js +21 -20
- package/modern/getThemeValue.js +1 -1
- package/modern/index.js +2 -2
- package/modern/styleFunctionSx/index.js +1 -0
- package/modern/styleFunctionSx/styleFunctionSx.js +78 -51
- package/package.json +6 -6
- package/style.d.ts +1 -1
- package/styleFunctionSx/index.js +12 -2
- package/styleFunctionSx/styleFunctionSx.d.ts +25 -3
- package/styleFunctionSx/styleFunctionSx.js +79 -54
- package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
|
@@ -85,19 +85,20 @@ const getCssValue = (keys, value) => {
|
|
|
85
85
|
* `basePrefix`: defined by design system.
|
|
86
86
|
* `prefix`: defined by application
|
|
87
87
|
*
|
|
88
|
-
*
|
|
88
|
+
* the CSS variable value will be adjusted based on the provided `basePrefix` & `prefix` which can be found in `parsedTheme`.
|
|
89
89
|
*
|
|
90
|
-
* @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme)
|
|
90
|
+
* @returns {{ css: Object, vars: Object, parsedTheme: typeof theme }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme), and `parsedTheme` is the cloned version of theme.
|
|
91
91
|
*
|
|
92
92
|
* @example
|
|
93
|
-
* const { css, vars } = parser({
|
|
93
|
+
* const { css, vars, parsedTheme } = parser({
|
|
94
94
|
* fontSize: 12,
|
|
95
95
|
* lineHeight: 1.2,
|
|
96
|
-
* palette: { primary: { 500: '
|
|
97
|
-
* })
|
|
96
|
+
* palette: { primary: { 500: 'var(--color)' } }
|
|
97
|
+
* }, { prefix: 'foo' })
|
|
98
98
|
*
|
|
99
|
-
* console.log(css) // { '--fontSize': '12px', '--lineHeight': 1.2, '--palette-primary-500': '
|
|
100
|
-
* console.log(vars) // { fontSize: '--fontSize', lineHeight: '--lineHeight', palette: { primary: { 500: 'var(--palette-primary-500)' } } }
|
|
99
|
+
* console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--foo-color)' }
|
|
100
|
+
* console.log(vars) // { fontSize: '--foo-fontSize', lineHeight: '--foo-lineHeight', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
|
|
101
|
+
* console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--foo-color)' } } }
|
|
101
102
|
*/
|
|
102
103
|
|
|
103
104
|
|
|
@@ -109,20 +110,17 @@ export default function cssVarsParser(theme, options) {
|
|
|
109
110
|
} = options || {};
|
|
110
111
|
const css = {};
|
|
111
112
|
const vars = {};
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
// replace the value of the `scope` object with the prefix or remove basePrefix from the value
|
|
113
|
+
const parsedTheme = {};
|
|
114
|
+
walkObjectDeep(theme, (keys, value) => {
|
|
115
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
116
|
+
if (typeof value === 'string' && value.match(/var\(\s*--/)) {
|
|
117
|
+
// for CSS variable, apply prefix or remove basePrefix from the variable
|
|
118
118
|
if (!basePrefix && prefix) {
|
|
119
|
-
value = value.replace(/var\(
|
|
119
|
+
value = value.replace(/var\(\s*--/g, `var(--${prefix}-`);
|
|
120
120
|
} else {
|
|
121
|
-
value = prefix ? value.replace(new RegExp(basePrefix
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
scope[keys.slice(-1)[0]] = value;
|
|
121
|
+
value = prefix ? value.replace(new RegExp(`var\\(\\s*--${basePrefix}`, 'g'), `var(--${prefix}`) // removing spaces
|
|
122
|
+
: value.replace(new RegExp(`var\\(\\s*--${basePrefix}-`, 'g'), 'var(--');
|
|
123
|
+
}
|
|
126
124
|
}
|
|
127
125
|
|
|
128
126
|
if (!shouldSkipGeneratingVar || shouldSkipGeneratingVar && !shouldSkipGeneratingVar(keys, value)) {
|
|
@@ -134,10 +132,13 @@ export default function cssVarsParser(theme, options) {
|
|
|
134
132
|
assignNestedKeys(vars, keys, `var(${cssVar})`);
|
|
135
133
|
}
|
|
136
134
|
}
|
|
135
|
+
|
|
136
|
+
assignNestedKeys(parsedTheme, keys, value);
|
|
137
137
|
}, keys => keys[0] === 'vars' // skip 'vars/*' paths
|
|
138
138
|
);
|
|
139
139
|
return {
|
|
140
140
|
css,
|
|
141
|
-
vars
|
|
141
|
+
vars,
|
|
142
|
+
parsedTheme
|
|
142
143
|
};
|
|
143
144
|
}
|
package/modern/getThemeValue.js
CHANGED
package/modern/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license MUI v5.4.
|
|
1
|
+
/** @license MUI v5.4.4
|
|
2
2
|
*
|
|
3
3
|
* This source code is licensed under the MIT license found in the
|
|
4
4
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -26,7 +26,7 @@ export * from './spacing';
|
|
|
26
26
|
export { default as style, getPath } from './style';
|
|
27
27
|
export { default as typography } from './typography';
|
|
28
28
|
export * from './typography';
|
|
29
|
-
export { default as unstable_styleFunctionSx, extendSxProp as unstable_extendSxProp } from './styleFunctionSx';
|
|
29
|
+
export { default as unstable_styleFunctionSx, unstable_createStyleFunctionSx, extendSxProp as unstable_extendSxProp } from './styleFunctionSx';
|
|
30
30
|
export { default as experimental_sx } from './sx';
|
|
31
31
|
export { default as unstable_getThemeValue } from './getThemeValue';
|
|
32
32
|
export { default as Box } from './Box';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import merge from '../merge';
|
|
2
|
-
import
|
|
2
|
+
import { styleFunctionMapping as defaultStyleFunctionMapping } from '../getThemeValue';
|
|
3
3
|
import { handleBreakpoints, createEmptyBreakpointObject, removeUnusedBreakpoints } from '../breakpoints';
|
|
4
4
|
|
|
5
5
|
function objectsHaveSameKeys(...objects) {
|
|
@@ -10,70 +10,97 @@ function objectsHaveSameKeys(...objects) {
|
|
|
10
10
|
|
|
11
11
|
function callIfFn(maybeFn, arg) {
|
|
12
12
|
return typeof maybeFn === 'function' ? maybeFn(arg) : maybeFn;
|
|
13
|
-
}
|
|
13
|
+
} // eslint-disable-next-line @typescript-eslint/naming-convention
|
|
14
14
|
|
|
15
|
-
function styleFunctionSx(props) {
|
|
16
|
-
const {
|
|
17
|
-
sx,
|
|
18
|
-
theme = {}
|
|
19
|
-
} = props || {};
|
|
20
15
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*/
|
|
16
|
+
export function unstable_createStyleFunctionSx(styleFunctionMapping = defaultStyleFunctionMapping) {
|
|
17
|
+
const propToStyleFunction = Object.keys(styleFunctionMapping).reduce((acc, styleFnName) => {
|
|
18
|
+
styleFunctionMapping[styleFnName].filterProps.forEach(propName => {
|
|
19
|
+
acc[propName] = styleFunctionMapping[styleFnName];
|
|
20
|
+
});
|
|
21
|
+
return acc;
|
|
22
|
+
}, {});
|
|
29
23
|
|
|
24
|
+
function getThemeValue(prop, value, theme) {
|
|
25
|
+
const inputProps = {
|
|
26
|
+
[prop]: value,
|
|
27
|
+
theme
|
|
28
|
+
};
|
|
29
|
+
const styleFunction = propToStyleFunction[prop];
|
|
30
|
+
return styleFunction ? styleFunction(inputProps) : {
|
|
31
|
+
[prop]: value
|
|
32
|
+
};
|
|
33
|
+
}
|
|
30
34
|
|
|
31
|
-
function
|
|
32
|
-
|
|
35
|
+
function styleFunctionSx(props) {
|
|
36
|
+
const {
|
|
37
|
+
sx,
|
|
38
|
+
theme = {}
|
|
39
|
+
} = props || {};
|
|
33
40
|
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
} else if (typeof sxInput !== 'object') {
|
|
37
|
-
// value
|
|
38
|
-
return sxInput;
|
|
41
|
+
if (!sx) {
|
|
42
|
+
return null; // emotion & styled-components will neglect null
|
|
39
43
|
}
|
|
44
|
+
/*
|
|
45
|
+
* Receive `sxInput` as object or callback
|
|
46
|
+
* and then recursively check keys & values to create media query object styles.
|
|
47
|
+
* (the result will be used in `styled`)
|
|
48
|
+
*/
|
|
40
49
|
|
|
41
|
-
const emptyBreakpoints = createEmptyBreakpointObject(theme.breakpoints);
|
|
42
|
-
const breakpointsKeys = Object.keys(emptyBreakpoints);
|
|
43
|
-
let css = emptyBreakpoints;
|
|
44
|
-
Object.keys(sxObject).forEach(styleKey => {
|
|
45
|
-
const value = callIfFn(sxObject[styleKey], theme);
|
|
46
50
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
51
|
+
function traverse(sxInput) {
|
|
52
|
+
let sxObject = sxInput;
|
|
53
|
+
|
|
54
|
+
if (typeof sxInput === 'function') {
|
|
55
|
+
sxObject = sxInput(theme);
|
|
56
|
+
} else if (typeof sxInput !== 'object') {
|
|
57
|
+
// value
|
|
58
|
+
return sxInput;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!sxObject) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const emptyBreakpoints = createEmptyBreakpointObject(theme.breakpoints);
|
|
66
|
+
const breakpointsKeys = Object.keys(emptyBreakpoints);
|
|
67
|
+
let css = emptyBreakpoints;
|
|
68
|
+
Object.keys(sxObject).forEach(styleKey => {
|
|
69
|
+
const value = callIfFn(sxObject[styleKey], theme);
|
|
70
|
+
|
|
71
|
+
if (value !== null && value !== undefined) {
|
|
72
|
+
if (typeof value === 'object') {
|
|
73
|
+
if (propToStyleFunction[styleKey]) {
|
|
74
|
+
css = merge(css, getThemeValue(styleKey, value, theme));
|
|
63
75
|
} else {
|
|
64
|
-
|
|
76
|
+
const breakpointsValues = handleBreakpoints({
|
|
77
|
+
theme
|
|
78
|
+
}, value, x => ({
|
|
79
|
+
[styleKey]: x
|
|
80
|
+
}));
|
|
81
|
+
|
|
82
|
+
if (objectsHaveSameKeys(breakpointsValues, value)) {
|
|
83
|
+
css[styleKey] = styleFunctionSx({
|
|
84
|
+
sx: value,
|
|
85
|
+
theme
|
|
86
|
+
});
|
|
87
|
+
} else {
|
|
88
|
+
css = merge(css, breakpointsValues);
|
|
89
|
+
}
|
|
65
90
|
}
|
|
91
|
+
} else {
|
|
92
|
+
css = merge(css, getThemeValue(styleKey, value, theme));
|
|
66
93
|
}
|
|
67
|
-
} else {
|
|
68
|
-
css = merge(css, getThemeValue(styleKey, value, theme));
|
|
69
94
|
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
95
|
+
});
|
|
96
|
+
return removeUnusedBreakpoints(breakpointsKeys, css);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return Array.isArray(sx) ? sx.map(traverse) : traverse(sx);
|
|
73
100
|
}
|
|
74
101
|
|
|
75
|
-
return
|
|
102
|
+
return styleFunctionSx;
|
|
76
103
|
}
|
|
77
|
-
|
|
104
|
+
const styleFunctionSx = unstable_createStyleFunctionSx();
|
|
78
105
|
styleFunctionSx.filterProps = ['sx'];
|
|
79
106
|
export default styleFunctionSx;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/system",
|
|
3
|
-
"version": "5.4.
|
|
3
|
+
"version": "5.4.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"description": "CSS utilities for rapidly laying out custom designs.",
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@babel/runtime": "^7.17.
|
|
47
|
-
"@mui/private-theming": "^5.4.
|
|
48
|
-
"@mui/styled-engine": "^5.4.
|
|
49
|
-
"@mui/types": "^7.1.
|
|
50
|
-
"@mui/utils": "^5.4.
|
|
46
|
+
"@babel/runtime": "^7.17.2",
|
|
47
|
+
"@mui/private-theming": "^5.4.4",
|
|
48
|
+
"@mui/styled-engine": "^5.4.4",
|
|
49
|
+
"@mui/types": "^7.1.2",
|
|
50
|
+
"@mui/utils": "^5.4.4",
|
|
51
51
|
"clsx": "^1.1.1",
|
|
52
52
|
"csstype": "^3.0.10",
|
|
53
53
|
"prop-types": "^15.7.2"
|
package/style.d.ts
CHANGED
|
@@ -12,4 +12,4 @@ export interface StyleOptions<PropKey> {
|
|
|
12
12
|
}
|
|
13
13
|
export function style<PropKey extends string, Theme extends object>(
|
|
14
14
|
options: StyleOptions<PropKey>,
|
|
15
|
-
): StyleFunction<{ [K in PropKey]?: unknown } & { theme?: Theme }
|
|
15
|
+
): StyleFunction<{ [K in PropKey]?: unknown } & { theme?: Theme }> & { filterProps: string[] };
|
package/styleFunctionSx/index.js
CHANGED
|
@@ -17,7 +17,17 @@ Object.defineProperty(exports, "extendSxProp", {
|
|
|
17
17
|
return _extendSxProp.default;
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
|
+
Object.defineProperty(exports, "unstable_createStyleFunctionSx", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () {
|
|
23
|
+
return _styleFunctionSx.unstable_createStyleFunctionSx;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
var _styleFunctionSx = _interopRequireWildcard(require("./styleFunctionSx"));
|
|
28
|
+
|
|
29
|
+
var _extendSxProp = _interopRequireDefault(require("./extendSxProp"));
|
|
20
30
|
|
|
21
|
-
var
|
|
31
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
22
32
|
|
|
23
|
-
var
|
|
33
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -24,6 +24,18 @@ export interface CSSSelectorObject<Theme extends object = {}> {
|
|
|
24
24
|
[cssSelector: string]: ((theme: Theme) => SystemStyleObject<Theme>) | SystemStyleObject<Theme>;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
type CssVariableType = string | number;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Map all nested selectors and CSS variables.
|
|
31
|
+
*/
|
|
32
|
+
export interface CSSSelectorObjectOrCssVariables<Theme extends object = {}> {
|
|
33
|
+
[cssSelectorOrVariable: string]:
|
|
34
|
+
| ((theme: Theme) => SystemStyleObject<Theme> | string | number)
|
|
35
|
+
| SystemStyleObject<Theme>
|
|
36
|
+
| CssVariableType;
|
|
37
|
+
}
|
|
38
|
+
|
|
27
39
|
/**
|
|
28
40
|
* Map of all available CSS properties (including aliases) and their raw value.
|
|
29
41
|
* Only used internally to map CSS properties to input types (responsive value,
|
|
@@ -48,8 +60,7 @@ export type SystemCssProperties<Theme extends object = {}> = {
|
|
|
48
60
|
export type SystemStyleObject<Theme extends object = {}> =
|
|
49
61
|
| SystemCssProperties<Theme>
|
|
50
62
|
| CSSPseudoSelectorProps<Theme>
|
|
51
|
-
|
|
|
52
|
-
| { [cssVariable: string]: string | number }
|
|
63
|
+
| CSSSelectorObjectOrCssVariables<Theme>
|
|
53
64
|
| null;
|
|
54
65
|
|
|
55
66
|
/**
|
|
@@ -60,5 +71,16 @@ export type SxProps<Theme extends object = {}> =
|
|
|
60
71
|
| ((theme: Theme) => SystemStyleObject<Theme>)
|
|
61
72
|
| Array<boolean | SystemStyleObject<Theme> | ((theme: Theme) => SystemStyleObject<Theme>)>;
|
|
62
73
|
|
|
74
|
+
export interface StyleFunctionSx {
|
|
75
|
+
(props: object): object;
|
|
76
|
+
filterProps?: string[];
|
|
77
|
+
}
|
|
78
|
+
|
|
63
79
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
64
|
-
export
|
|
80
|
+
export function unstable_createStyleFunctionSx(
|
|
81
|
+
styleFunctionMapping: Record<string, StyleFunctionSx>,
|
|
82
|
+
): StyleFunctionSx;
|
|
83
|
+
|
|
84
|
+
declare const styleFunctionSx: StyleFunctionSx;
|
|
85
|
+
|
|
86
|
+
export default styleFunctionSx;
|
|
@@ -6,17 +6,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
|
+
exports.unstable_createStyleFunctionSx = unstable_createStyleFunctionSx;
|
|
9
10
|
|
|
10
11
|
var _merge = _interopRequireDefault(require("../merge"));
|
|
11
12
|
|
|
12
|
-
var _getThemeValue =
|
|
13
|
+
var _getThemeValue = require("../getThemeValue");
|
|
13
14
|
|
|
14
15
|
var _breakpoints = require("../breakpoints");
|
|
15
16
|
|
|
16
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
|
-
|
|
18
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
19
|
-
|
|
20
17
|
function objectsHaveSameKeys(...objects) {
|
|
21
18
|
const allKeys = objects.reduce((keys, object) => keys.concat(Object.keys(object)), []);
|
|
22
19
|
const union = new Set(allKeys);
|
|
@@ -25,71 +22,99 @@ function objectsHaveSameKeys(...objects) {
|
|
|
25
22
|
|
|
26
23
|
function callIfFn(maybeFn, arg) {
|
|
27
24
|
return typeof maybeFn === 'function' ? maybeFn(arg) : maybeFn;
|
|
28
|
-
}
|
|
25
|
+
} // eslint-disable-next-line @typescript-eslint/naming-convention
|
|
29
26
|
|
|
30
|
-
function styleFunctionSx(props) {
|
|
31
|
-
const {
|
|
32
|
-
sx,
|
|
33
|
-
theme = {}
|
|
34
|
-
} = props || {};
|
|
35
27
|
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
function unstable_createStyleFunctionSx(styleFunctionMapping = _getThemeValue.styleFunctionMapping) {
|
|
29
|
+
const propToStyleFunction = Object.keys(styleFunctionMapping).reduce((acc, styleFnName) => {
|
|
30
|
+
styleFunctionMapping[styleFnName].filterProps.forEach(propName => {
|
|
31
|
+
acc[propName] = styleFunctionMapping[styleFnName];
|
|
32
|
+
});
|
|
33
|
+
return acc;
|
|
34
|
+
}, {});
|
|
35
|
+
|
|
36
|
+
function getThemeValue(prop, value, theme) {
|
|
37
|
+
const inputProps = {
|
|
38
|
+
[prop]: value,
|
|
39
|
+
theme
|
|
40
|
+
};
|
|
41
|
+
const styleFunction = propToStyleFunction[prop];
|
|
42
|
+
return styleFunction ? styleFunction(inputProps) : {
|
|
43
|
+
[prop]: value
|
|
44
|
+
};
|
|
38
45
|
}
|
|
39
|
-
/*
|
|
40
|
-
* Receive `sxInput` as object or callback
|
|
41
|
-
* and then recursively check keys & values to create media query object styles.
|
|
42
|
-
* (the result will be used in `styled`)
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
46
|
|
|
46
|
-
function
|
|
47
|
-
|
|
47
|
+
function styleFunctionSx(props) {
|
|
48
|
+
const {
|
|
49
|
+
sx,
|
|
50
|
+
theme = {}
|
|
51
|
+
} = props || {};
|
|
48
52
|
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
} else if (typeof sxInput !== 'object') {
|
|
52
|
-
// value
|
|
53
|
-
return sxInput;
|
|
53
|
+
if (!sx) {
|
|
54
|
+
return null; // emotion & styled-components will neglect null
|
|
54
55
|
}
|
|
56
|
+
/*
|
|
57
|
+
* Receive `sxInput` as object or callback
|
|
58
|
+
* and then recursively check keys & values to create media query object styles.
|
|
59
|
+
* (the result will be used in `styled`)
|
|
60
|
+
*/
|
|
55
61
|
|
|
56
|
-
const emptyBreakpoints = (0, _breakpoints.createEmptyBreakpointObject)(theme.breakpoints);
|
|
57
|
-
const breakpointsKeys = Object.keys(emptyBreakpoints);
|
|
58
|
-
let css = emptyBreakpoints;
|
|
59
|
-
Object.keys(sxObject).forEach(styleKey => {
|
|
60
|
-
const value = callIfFn(sxObject[styleKey], theme);
|
|
61
62
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
63
|
+
function traverse(sxInput) {
|
|
64
|
+
let sxObject = sxInput;
|
|
65
|
+
|
|
66
|
+
if (typeof sxInput === 'function') {
|
|
67
|
+
sxObject = sxInput(theme);
|
|
68
|
+
} else if (typeof sxInput !== 'object') {
|
|
69
|
+
// value
|
|
70
|
+
return sxInput;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!sxObject) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const emptyBreakpoints = (0, _breakpoints.createEmptyBreakpointObject)(theme.breakpoints);
|
|
78
|
+
const breakpointsKeys = Object.keys(emptyBreakpoints);
|
|
79
|
+
let css = emptyBreakpoints;
|
|
80
|
+
Object.keys(sxObject).forEach(styleKey => {
|
|
81
|
+
const value = callIfFn(sxObject[styleKey], theme);
|
|
82
|
+
|
|
83
|
+
if (value !== null && value !== undefined) {
|
|
84
|
+
if (typeof value === 'object') {
|
|
85
|
+
if (propToStyleFunction[styleKey]) {
|
|
86
|
+
css = (0, _merge.default)(css, getThemeValue(styleKey, value, theme));
|
|
78
87
|
} else {
|
|
79
|
-
|
|
88
|
+
const breakpointsValues = (0, _breakpoints.handleBreakpoints)({
|
|
89
|
+
theme
|
|
90
|
+
}, value, x => ({
|
|
91
|
+
[styleKey]: x
|
|
92
|
+
}));
|
|
93
|
+
|
|
94
|
+
if (objectsHaveSameKeys(breakpointsValues, value)) {
|
|
95
|
+
css[styleKey] = styleFunctionSx({
|
|
96
|
+
sx: value,
|
|
97
|
+
theme
|
|
98
|
+
});
|
|
99
|
+
} else {
|
|
100
|
+
css = (0, _merge.default)(css, breakpointsValues);
|
|
101
|
+
}
|
|
80
102
|
}
|
|
103
|
+
} else {
|
|
104
|
+
css = (0, _merge.default)(css, getThemeValue(styleKey, value, theme));
|
|
81
105
|
}
|
|
82
|
-
} else {
|
|
83
|
-
css = (0, _merge.default)(css, (0, _getThemeValue.default)(styleKey, value, theme));
|
|
84
106
|
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
107
|
+
});
|
|
108
|
+
return (0, _breakpoints.removeUnusedBreakpoints)(breakpointsKeys, css);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return Array.isArray(sx) ? sx.map(traverse) : traverse(sx);
|
|
88
112
|
}
|
|
89
113
|
|
|
90
|
-
return
|
|
114
|
+
return styleFunctionSx;
|
|
91
115
|
}
|
|
92
116
|
|
|
117
|
+
const styleFunctionSx = unstable_createStyleFunctionSx();
|
|
93
118
|
styleFunctionSx.filterProps = ['sx'];
|
|
94
119
|
var _default = styleFunctionSx;
|
|
95
120
|
exports.default = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|