@mui/system 5.10.13 → 5.10.15
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.js +1 -10
- package/Box/index.js +0 -2
- package/CHANGELOG.md +132 -2
- package/Container/Container.js +2 -17
- package/Container/containerClasses.js +0 -3
- package/Container/createContainer.js +15 -37
- package/Container/index.js +0 -6
- package/Stack/Stack.js +1 -12
- package/Stack/createStack.js +10 -48
- package/Stack/index.js +0 -9
- package/Stack/stackClasses.js +0 -3
- package/ThemeProvider/ThemeProvider.js +2 -22
- package/ThemeProvider/index.js +0 -2
- package/Unstable_Grid/Grid.js +6 -42
- package/Unstable_Grid/createGrid.js +19 -49
- package/Unstable_Grid/gridClasses.js +8 -7
- package/Unstable_Grid/gridGenerator.d.ts +4 -3
- package/Unstable_Grid/gridGenerator.js +22 -63
- package/Unstable_Grid/index.js +0 -9
- package/borders.js +0 -14
- package/breakpoints.js +3 -32
- package/colorManipulator.js +13 -55
- package/compose.js +0 -7
- package/createBox.js +5 -20
- package/createStyled.js +27 -71
- package/createTheme/createBreakpoints.js +22 -37
- package/createTheme/createSpacing.js +4 -8
- package/createTheme/createTheme.js +6 -16
- package/createTheme/index.js +0 -2
- package/cssGrid.js +0 -21
- package/cssVars/createCssVarsProvider.js +33 -74
- package/cssVars/createGetCssVar.js +2 -7
- package/cssVars/cssVarsParser.js +3 -15
- package/cssVars/getInitColorSchemeScript.js +0 -6
- package/cssVars/index.js +0 -3
- package/cssVars/useCurrentColorScheme.js +20 -49
- package/display.js +0 -6
- package/esm/Box/Box.js +1 -6
- package/esm/Container/Container.js +3 -14
- package/esm/Container/createContainer.js +15 -25
- package/esm/Stack/Stack.js +1 -9
- package/esm/Stack/createStack.js +10 -29
- package/esm/ThemeProvider/ThemeProvider.js +2 -11
- package/esm/Unstable_Grid/Grid.js +6 -39
- package/esm/Unstable_Grid/createGrid.js +18 -35
- package/esm/Unstable_Grid/gridClasses.js +8 -4
- package/esm/Unstable_Grid/gridGenerator.js +20 -38
- package/esm/borders.js +0 -6
- package/esm/breakpoints.js +7 -22
- package/esm/colorManipulator.js +13 -43
- package/esm/compose.js +0 -5
- package/esm/createBox.js +5 -7
- package/esm/createStyled.js +27 -64
- package/esm/createTheme/createBreakpoints.js +22 -34
- package/esm/createTheme/createSpacing.js +4 -7
- package/esm/createTheme/createTheme.js +6 -9
- package/esm/cssGrid.js +0 -9
- package/esm/cssVars/createCssVarsProvider.js +33 -60
- package/esm/cssVars/createGetCssVar.js +2 -6
- package/esm/cssVars/cssVarsParser.js +3 -11
- package/esm/cssVars/useCurrentColorScheme.js +20 -44
- package/esm/getThemeValue.js +0 -2
- package/esm/index.js +3 -3
- package/esm/memoize.js +0 -1
- package/esm/merge.js +0 -3
- package/esm/palette.js +0 -3
- package/esm/propsToClassKey.js +4 -7
- package/esm/sizing.js +0 -5
- package/esm/spacing.js +3 -23
- package/esm/style.js +5 -22
- package/esm/styleFunctionSx/extendSxProp.js +3 -10
- package/esm/styleFunctionSx/styleFunctionSx.js +3 -16
- package/esm/sx/sx.js +0 -2
- package/esm/useTheme.js +0 -2
- package/esm/useThemeProps/getThemeProps.js +0 -2
- package/esm/useThemeWithoutDefault.js +0 -3
- package/flexbox.js +0 -4
- package/getThemeValue.js +0 -14
- package/index.d.ts +2 -0
- package/index.js +16 -55
- package/legacy/Box/Box.js +1 -6
- package/legacy/Container/Container.js +3 -14
- package/legacy/Container/createContainer.js +29 -39
- package/legacy/Stack/Stack.js +1 -9
- package/legacy/Stack/createStack.js +17 -37
- package/legacy/ThemeProvider/ThemeProvider.js +3 -12
- package/legacy/Unstable_Grid/Grid.js +6 -39
- package/legacy/Unstable_Grid/createGrid.js +34 -53
- package/legacy/Unstable_Grid/gridGenerator.js +36 -58
- package/legacy/borders.js +0 -6
- package/legacy/breakpoints.js +9 -28
- package/legacy/colorManipulator.js +16 -48
- package/legacy/compose.js +0 -6
- package/legacy/createBox.js +9 -11
- package/legacy/createStyled.js +27 -68
- package/legacy/createTheme/createBreakpoints.js +20 -33
- package/legacy/createTheme/createSpacing.js +4 -9
- package/legacy/createTheme/createTheme.js +7 -13
- package/legacy/cssGrid.js +0 -9
- package/legacy/cssVars/createCssVarsProvider.js +98 -130
- package/legacy/cssVars/createGetCssVar.js +2 -10
- package/legacy/cssVars/cssVarsParser.js +7 -20
- package/legacy/cssVars/getInitColorSchemeScript.js +14 -15
- package/legacy/cssVars/useCurrentColorScheme.js +43 -69
- package/legacy/getThemeValue.js +0 -3
- package/legacy/index.js +4 -4
- package/legacy/memoize.js +0 -1
- package/legacy/merge.js +0 -3
- package/legacy/palette.js +0 -3
- package/legacy/propsToClassKey.js +2 -5
- package/legacy/sizing.js +0 -5
- package/legacy/spacing.js +6 -27
- package/legacy/style.js +9 -27
- package/legacy/styleFunctionSx/extendSxProp.js +3 -11
- package/legacy/styleFunctionSx/styleFunctionSx.js +6 -21
- package/legacy/sx/sx.js +0 -2
- package/legacy/useTheme.js +0 -2
- package/legacy/useThemeProps/getThemeProps.js +2 -4
- package/legacy/useThemeProps/useThemeProps.js +2 -2
- package/legacy/useThemeWithoutDefault.js +0 -3
- package/memoize.js +0 -2
- package/merge.js +0 -5
- package/modern/Box/Box.js +1 -6
- package/modern/Container/Container.js +3 -14
- package/modern/Container/createContainer.js +15 -25
- package/modern/Stack/Stack.js +1 -9
- package/modern/Stack/createStack.js +10 -29
- package/modern/ThemeProvider/ThemeProvider.js +2 -11
- package/modern/Unstable_Grid/Grid.js +6 -39
- package/modern/Unstable_Grid/createGrid.js +18 -34
- package/modern/Unstable_Grid/gridClasses.js +8 -4
- package/modern/Unstable_Grid/gridGenerator.js +20 -36
- package/modern/borders.js +0 -6
- package/modern/breakpoints.js +7 -21
- package/modern/colorManipulator.js +13 -43
- package/modern/compose.js +0 -5
- package/modern/createBox.js +5 -7
- package/modern/createStyled.js +27 -63
- package/modern/createTheme/createBreakpoints.js +22 -34
- package/modern/createTheme/createSpacing.js +4 -7
- package/modern/createTheme/createTheme.js +6 -9
- package/modern/cssGrid.js +0 -9
- package/modern/cssVars/createCssVarsProvider.js +33 -60
- package/modern/cssVars/createGetCssVar.js +2 -6
- package/modern/cssVars/cssVarsParser.js +3 -11
- package/modern/cssVars/useCurrentColorScheme.js +20 -44
- package/modern/getThemeValue.js +0 -2
- package/modern/index.js +4 -4
- package/modern/memoize.js +0 -1
- package/modern/merge.js +0 -3
- package/modern/palette.js +0 -3
- package/modern/propsToClassKey.js +4 -7
- package/modern/sizing.js +0 -4
- package/modern/spacing.js +3 -22
- package/modern/style.js +5 -22
- package/modern/styleFunctionSx/extendSxProp.js +3 -10
- package/modern/styleFunctionSx/styleFunctionSx.js +3 -16
- package/modern/sx/sx.js +0 -2
- package/modern/useTheme.js +0 -2
- package/modern/useThemeProps/getThemeProps.js +0 -2
- package/modern/useThemeWithoutDefault.js +0 -3
- package/package.json +6 -6
- package/palette.js +0 -6
- package/positions.js +0 -6
- package/propsToClassKey.js +4 -10
- package/responsivePropType.d.ts +3 -0
- package/responsivePropType.js +0 -3
- package/shadows.js +0 -3
- package/sizing.js +0 -11
- package/spacing.d.ts +14 -0
- package/spacing.js +3 -37
- package/style.d.ts +6 -0
- package/style.js +6 -27
- package/styleFunctionSx/extendSxProp.js +3 -15
- package/styleFunctionSx/index.js +0 -5
- package/styleFunctionSx/styleFunctionSx.js +3 -21
- package/styled.js +0 -3
- package/sx/index.js +0 -2
- package/sx/sx.js +0 -4
- package/typography.js +0 -4
- package/useTheme.js +0 -6
- package/useThemeProps/getThemeProps.js +0 -4
- package/useThemeProps/index.js +0 -3
- package/useThemeProps/useThemeProps.js +0 -4
- package/useThemeWithoutDefault.js +0 -4
package/esm/breakpoints.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { deepmerge } from '@mui/utils';
|
|
4
|
-
import merge from './merge';
|
|
5
|
-
// For instance with the first breakpoint xs: [xs, sm[.
|
|
4
|
+
import merge from './merge';
|
|
6
5
|
|
|
6
|
+
// The breakpoint **start** at this value.
|
|
7
|
+
// For instance with the first breakpoint xs: [xs, sm[.
|
|
7
8
|
export const values = {
|
|
8
9
|
xs: 0,
|
|
9
10
|
// phone
|
|
@@ -14,8 +15,8 @@ export const values = {
|
|
|
14
15
|
lg: 1200,
|
|
15
16
|
// desktop
|
|
16
17
|
xl: 1536 // large screen
|
|
17
|
-
|
|
18
18
|
};
|
|
19
|
+
|
|
19
20
|
const defaultBreakpoints = {
|
|
20
21
|
// Sorted ASC by size. That's important.
|
|
21
22
|
// It can't be configured as it's used statically for propTypes.
|
|
@@ -24,7 +25,6 @@ const defaultBreakpoints = {
|
|
|
24
25
|
};
|
|
25
26
|
export function handleBreakpoints(props, propValue, styleFromPropValue) {
|
|
26
27
|
const theme = props.theme || {};
|
|
27
|
-
|
|
28
28
|
if (Array.isArray(propValue)) {
|
|
29
29
|
const themeBreakpoints = theme.breakpoints || defaultBreakpoints;
|
|
30
30
|
return propValue.reduce((acc, item, index) => {
|
|
@@ -32,7 +32,6 @@ export function handleBreakpoints(props, propValue, styleFromPropValue) {
|
|
|
32
32
|
return acc;
|
|
33
33
|
}, {});
|
|
34
34
|
}
|
|
35
|
-
|
|
36
35
|
if (typeof propValue === 'object') {
|
|
37
36
|
const themeBreakpoints = theme.breakpoints || defaultBreakpoints;
|
|
38
37
|
return Object.keys(propValue).reduce((acc, breakpoint) => {
|
|
@@ -44,15 +43,12 @@ export function handleBreakpoints(props, propValue, styleFromPropValue) {
|
|
|
44
43
|
const cssKey = breakpoint;
|
|
45
44
|
acc[cssKey] = propValue[cssKey];
|
|
46
45
|
}
|
|
47
|
-
|
|
48
46
|
return acc;
|
|
49
47
|
}, {});
|
|
50
48
|
}
|
|
51
|
-
|
|
52
49
|
const output = styleFromPropValue(propValue);
|
|
53
50
|
return output;
|
|
54
51
|
}
|
|
55
|
-
|
|
56
52
|
function breakpoints(styleFunction) {
|
|
57
53
|
const newStyleFunction = props => {
|
|
58
54
|
const theme = props.theme || {};
|
|
@@ -65,12 +61,10 @@ function breakpoints(styleFunction) {
|
|
|
65
61
|
theme
|
|
66
62
|
}, props[key]));
|
|
67
63
|
}
|
|
68
|
-
|
|
69
64
|
return acc;
|
|
70
65
|
}, null);
|
|
71
66
|
return merge(base, extended);
|
|
72
67
|
};
|
|
73
|
-
|
|
74
68
|
newStyleFunction.propTypes = process.env.NODE_ENV !== 'production' ? _extends({}, styleFunction.propTypes, {
|
|
75
69
|
xs: PropTypes.object,
|
|
76
70
|
sm: PropTypes.object,
|
|
@@ -81,10 +75,8 @@ function breakpoints(styleFunction) {
|
|
|
81
75
|
newStyleFunction.filterProps = ['xs', 'sm', 'md', 'lg', 'xl', ...styleFunction.filterProps];
|
|
82
76
|
return newStyleFunction;
|
|
83
77
|
}
|
|
84
|
-
|
|
85
78
|
export function createEmptyBreakpointObject(breakpointsInput = {}) {
|
|
86
79
|
var _breakpointsInput$key;
|
|
87
|
-
|
|
88
80
|
const breakpointsInOrder = (_breakpointsInput$key = breakpointsInput.keys) == null ? void 0 : _breakpointsInput$key.reduce((acc, key) => {
|
|
89
81
|
const breakpointStyleKey = breakpointsInput.up(key);
|
|
90
82
|
acc[breakpointStyleKey] = {};
|
|
@@ -96,11 +88,9 @@ export function removeUnusedBreakpoints(breakpointKeys, style) {
|
|
|
96
88
|
return breakpointKeys.reduce((acc, key) => {
|
|
97
89
|
const breakpointOutput = acc[key];
|
|
98
90
|
const isBreakpointUnused = !breakpointOutput || Object.keys(breakpointOutput).length === 0;
|
|
99
|
-
|
|
100
91
|
if (isBreakpointUnused) {
|
|
101
92
|
delete acc[key];
|
|
102
93
|
}
|
|
103
|
-
|
|
104
94
|
return acc;
|
|
105
95
|
}, style);
|
|
106
96
|
}
|
|
@@ -108,19 +98,18 @@ export function mergeBreakpointsInOrder(breakpointsInput, ...styles) {
|
|
|
108
98
|
const emptyBreakpoints = createEmptyBreakpointObject(breakpointsInput);
|
|
109
99
|
const mergedOutput = [emptyBreakpoints, ...styles].reduce((prev, next) => deepmerge(prev, next), {});
|
|
110
100
|
return removeUnusedBreakpoints(Object.keys(emptyBreakpoints), mergedOutput);
|
|
111
|
-
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// compute base for responsive values; e.g.,
|
|
112
104
|
// [1,2,3] => {xs: true, sm: true, md: true}
|
|
113
105
|
// {xs: 1, sm: 2, md: 3} => {xs: true, sm: true, md: true}
|
|
114
|
-
|
|
115
106
|
export function computeBreakpointsBase(breakpointValues, themeBreakpoints) {
|
|
116
107
|
// fixed value
|
|
117
108
|
if (typeof breakpointValues !== 'object') {
|
|
118
109
|
return {};
|
|
119
110
|
}
|
|
120
|
-
|
|
121
111
|
const base = {};
|
|
122
112
|
const breakpointsKeys = Object.keys(themeBreakpoints);
|
|
123
|
-
|
|
124
113
|
if (Array.isArray(breakpointValues)) {
|
|
125
114
|
breakpointsKeys.forEach((breakpoint, i) => {
|
|
126
115
|
if (i < breakpointValues.length) {
|
|
@@ -134,7 +123,6 @@ export function computeBreakpointsBase(breakpointValues, themeBreakpoints) {
|
|
|
134
123
|
}
|
|
135
124
|
});
|
|
136
125
|
}
|
|
137
|
-
|
|
138
126
|
return base;
|
|
139
127
|
}
|
|
140
128
|
export function resolveBreakpointValues({
|
|
@@ -144,11 +132,9 @@ export function resolveBreakpointValues({
|
|
|
144
132
|
}) {
|
|
145
133
|
const base = customBase || computeBreakpointsBase(breakpointValues, themeBreakpoints);
|
|
146
134
|
const keys = Object.keys(base);
|
|
147
|
-
|
|
148
135
|
if (keys.length === 0) {
|
|
149
136
|
return breakpointValues;
|
|
150
137
|
}
|
|
151
|
-
|
|
152
138
|
let previous;
|
|
153
139
|
return keys.reduce((acc, breakpoint, i) => {
|
|
154
140
|
if (Array.isArray(breakpointValues)) {
|
|
@@ -160,7 +146,6 @@ export function resolveBreakpointValues({
|
|
|
160
146
|
} else {
|
|
161
147
|
acc[breakpoint] = breakpointValues;
|
|
162
148
|
}
|
|
163
|
-
|
|
164
149
|
return acc;
|
|
165
150
|
}, {});
|
|
166
151
|
}
|
package/esm/colorManipulator.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { formatMuiErrorMessage as _formatMuiErrorMessage } from "@mui/utils";
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* Returns a number whose value is limited to the given range.
|
|
5
4
|
* @param {number} value The value to be clamped
|
|
@@ -13,34 +12,30 @@ function clamp(value, min = 0, max = 1) {
|
|
|
13
12
|
console.error(`MUI: The value provided ${value} is out of range [${min}, ${max}].`);
|
|
14
13
|
}
|
|
15
14
|
}
|
|
16
|
-
|
|
17
15
|
return Math.min(Math.max(min, value), max);
|
|
18
16
|
}
|
|
17
|
+
|
|
19
18
|
/**
|
|
20
19
|
* Converts a color from CSS hex format to CSS rgb format.
|
|
21
20
|
* @param {string} color - Hex color, i.e. #nnn or #nnnnnn
|
|
22
21
|
* @returns {string} A CSS rgb color string
|
|
23
22
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
23
|
export function hexToRgb(color) {
|
|
27
24
|
color = color.slice(1);
|
|
28
25
|
const re = new RegExp(`.{1,${color.length >= 6 ? 2 : 1}}`, 'g');
|
|
29
26
|
let colors = color.match(re);
|
|
30
|
-
|
|
31
27
|
if (colors && colors[0].length === 1) {
|
|
32
28
|
colors = colors.map(n => n + n);
|
|
33
29
|
}
|
|
34
|
-
|
|
35
30
|
return colors ? `rgb${colors.length === 4 ? 'a' : ''}(${colors.map((n, index) => {
|
|
36
31
|
return index < 3 ? parseInt(n, 16) : Math.round(parseInt(n, 16) / 255 * 1000) / 1000;
|
|
37
32
|
}).join(', ')})` : '';
|
|
38
33
|
}
|
|
39
|
-
|
|
40
34
|
function intToHex(int) {
|
|
41
35
|
const hex = int.toString(16);
|
|
42
36
|
return hex.length === 1 ? `0${hex}` : hex;
|
|
43
37
|
}
|
|
38
|
+
|
|
44
39
|
/**
|
|
45
40
|
* Returns an object with the type and values of a color.
|
|
46
41
|
*
|
|
@@ -48,37 +43,28 @@ function intToHex(int) {
|
|
|
48
43
|
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color()
|
|
49
44
|
* @returns {object} - A MUI color object: {type: string, values: number[]}
|
|
50
45
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
46
|
export function decomposeColor(color) {
|
|
54
47
|
// Idempotent
|
|
55
48
|
if (color.type) {
|
|
56
49
|
return color;
|
|
57
50
|
}
|
|
58
|
-
|
|
59
51
|
if (color.charAt(0) === '#') {
|
|
60
52
|
return decomposeColor(hexToRgb(color));
|
|
61
53
|
}
|
|
62
|
-
|
|
63
54
|
const marker = color.indexOf('(');
|
|
64
55
|
const type = color.substring(0, marker);
|
|
65
|
-
|
|
66
56
|
if (['rgb', 'rgba', 'hsl', 'hsla', 'color'].indexOf(type) === -1) {
|
|
67
57
|
throw new Error(process.env.NODE_ENV !== "production" ? `MUI: Unsupported \`${color}\` color.
|
|
68
58
|
The following formats are supported: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color().` : _formatMuiErrorMessage(9, color));
|
|
69
59
|
}
|
|
70
|
-
|
|
71
60
|
let values = color.substring(marker + 1, color.length - 1);
|
|
72
61
|
let colorSpace;
|
|
73
|
-
|
|
74
62
|
if (type === 'color') {
|
|
75
63
|
values = values.split(' ');
|
|
76
64
|
colorSpace = values.shift();
|
|
77
|
-
|
|
78
65
|
if (values.length === 4 && values[3].charAt(0) === '/') {
|
|
79
66
|
values[3] = values[3].slice(1);
|
|
80
67
|
}
|
|
81
|
-
|
|
82
68
|
if (['srgb', 'display-p3', 'a98-rgb', 'prophoto-rgb', 'rec-2020'].indexOf(colorSpace) === -1) {
|
|
83
69
|
throw new Error(process.env.NODE_ENV !== "production" ? `MUI: unsupported \`${colorSpace}\` color space.
|
|
84
70
|
The following color spaces are supported: srgb, display-p3, a98-rgb, prophoto-rgb, rec-2020.` : _formatMuiErrorMessage(10, colorSpace));
|
|
@@ -86,7 +72,6 @@ The following color spaces are supported: srgb, display-p3, a98-rgb, prophoto-rg
|
|
|
86
72
|
} else {
|
|
87
73
|
values = values.split(',');
|
|
88
74
|
}
|
|
89
|
-
|
|
90
75
|
values = values.map(value => parseFloat(value));
|
|
91
76
|
return {
|
|
92
77
|
type,
|
|
@@ -94,17 +79,18 @@ The following color spaces are supported: srgb, display-p3, a98-rgb, prophoto-rg
|
|
|
94
79
|
colorSpace
|
|
95
80
|
};
|
|
96
81
|
}
|
|
82
|
+
|
|
97
83
|
/**
|
|
98
84
|
* Returns a channel created from the input color.
|
|
99
85
|
*
|
|
100
86
|
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color()
|
|
101
87
|
* @returns {string} - The channel for the color, that can be used in rgba or hsla colors
|
|
102
88
|
*/
|
|
103
|
-
|
|
104
89
|
export const colorChannel = color => {
|
|
105
90
|
const decomposedColor = decomposeColor(color);
|
|
106
91
|
return decomposedColor.values.slice(0, 3).map((val, idx) => decomposedColor.type.indexOf('hsl') !== -1 && idx !== 0 ? `${val}%` : val).join(' ');
|
|
107
92
|
};
|
|
93
|
+
|
|
108
94
|
/**
|
|
109
95
|
* Converts a color object with type and values to a string.
|
|
110
96
|
* @param {object} color - Decomposed color
|
|
@@ -112,7 +98,6 @@ export const colorChannel = color => {
|
|
|
112
98
|
* @param {array} color.values - [n,n,n] or [n,n,n,n]
|
|
113
99
|
* @returns {string} A CSS color string
|
|
114
100
|
*/
|
|
115
|
-
|
|
116
101
|
export function recomposeColor(color) {
|
|
117
102
|
const {
|
|
118
103
|
type,
|
|
@@ -121,7 +106,6 @@ export function recomposeColor(color) {
|
|
|
121
106
|
let {
|
|
122
107
|
values
|
|
123
108
|
} = color;
|
|
124
|
-
|
|
125
109
|
if (type.indexOf('rgb') !== -1) {
|
|
126
110
|
// Only convert the first 3 values to int (i.e. not alpha)
|
|
127
111
|
values = values.map((n, i) => i < 3 ? parseInt(n, 10) : n);
|
|
@@ -129,38 +113,35 @@ export function recomposeColor(color) {
|
|
|
129
113
|
values[1] = `${values[1]}%`;
|
|
130
114
|
values[2] = `${values[2]}%`;
|
|
131
115
|
}
|
|
132
|
-
|
|
133
116
|
if (type.indexOf('color') !== -1) {
|
|
134
117
|
values = `${colorSpace} ${values.join(' ')}`;
|
|
135
118
|
} else {
|
|
136
119
|
values = `${values.join(', ')}`;
|
|
137
120
|
}
|
|
138
|
-
|
|
139
121
|
return `${type}(${values})`;
|
|
140
122
|
}
|
|
123
|
+
|
|
141
124
|
/**
|
|
142
125
|
* Converts a color from CSS rgb format to CSS hex format.
|
|
143
126
|
* @param {string} color - RGB color, i.e. rgb(n, n, n)
|
|
144
127
|
* @returns {string} A CSS rgb color string, i.e. #nnnnnn
|
|
145
128
|
*/
|
|
146
|
-
|
|
147
129
|
export function rgbToHex(color) {
|
|
148
130
|
// Idempotent
|
|
149
131
|
if (color.indexOf('#') === 0) {
|
|
150
132
|
return color;
|
|
151
133
|
}
|
|
152
|
-
|
|
153
134
|
const {
|
|
154
135
|
values
|
|
155
136
|
} = decomposeColor(color);
|
|
156
137
|
return `#${values.map((n, i) => intToHex(i === 3 ? Math.round(255 * n) : n)).join('')}`;
|
|
157
138
|
}
|
|
139
|
+
|
|
158
140
|
/**
|
|
159
141
|
* Converts a color from hsl format to rgb format.
|
|
160
142
|
* @param {string} color - HSL color values
|
|
161
143
|
* @returns {string} rgb color values
|
|
162
144
|
*/
|
|
163
|
-
|
|
164
145
|
export function hslToRgb(color) {
|
|
165
146
|
color = decomposeColor(color);
|
|
166
147
|
const {
|
|
@@ -170,17 +151,13 @@ export function hslToRgb(color) {
|
|
|
170
151
|
const s = values[1] / 100;
|
|
171
152
|
const l = values[2] / 100;
|
|
172
153
|
const a = s * Math.min(l, 1 - l);
|
|
173
|
-
|
|
174
154
|
const f = (n, k = (n + h / 30) % 12) => l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
|
|
175
|
-
|
|
176
155
|
let type = 'rgb';
|
|
177
156
|
const rgb = [Math.round(f(0) * 255), Math.round(f(8) * 255), Math.round(f(4) * 255)];
|
|
178
|
-
|
|
179
157
|
if (color.type === 'hsla') {
|
|
180
158
|
type += 'a';
|
|
181
159
|
rgb.push(values[3]);
|
|
182
160
|
}
|
|
183
|
-
|
|
184
161
|
return recomposeColor({
|
|
185
162
|
type,
|
|
186
163
|
values: rgb
|
|
@@ -194,7 +171,6 @@ export function hslToRgb(color) {
|
|
|
194
171
|
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color()
|
|
195
172
|
* @returns {number} The relative brightness of the color in the range 0 - 1
|
|
196
173
|
*/
|
|
197
|
-
|
|
198
174
|
export function getLuminance(color) {
|
|
199
175
|
color = decomposeColor(color);
|
|
200
176
|
let rgb = color.type === 'hsl' || color.type === 'hsla' ? decomposeColor(hslToRgb(color)).values : color.values;
|
|
@@ -204,10 +180,12 @@ export function getLuminance(color) {
|
|
|
204
180
|
}
|
|
205
181
|
|
|
206
182
|
return val <= 0.03928 ? val / 12.92 : ((val + 0.055) / 1.055) ** 2.4;
|
|
207
|
-
});
|
|
183
|
+
});
|
|
208
184
|
|
|
185
|
+
// Truncate at 3 digits
|
|
209
186
|
return Number((0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2]).toFixed(3));
|
|
210
187
|
}
|
|
188
|
+
|
|
211
189
|
/**
|
|
212
190
|
* Calculates the contrast ratio between two colors.
|
|
213
191
|
*
|
|
@@ -216,12 +194,12 @@ export function getLuminance(color) {
|
|
|
216
194
|
* @param {string} background - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
217
195
|
* @returns {number} A contrast ratio value in the range 0 - 21.
|
|
218
196
|
*/
|
|
219
|
-
|
|
220
197
|
export function getContrastRatio(foreground, background) {
|
|
221
198
|
const lumA = getLuminance(foreground);
|
|
222
199
|
const lumB = getLuminance(background);
|
|
223
200
|
return (Math.max(lumA, lumB) + 0.05) / (Math.min(lumA, lumB) + 0.05);
|
|
224
201
|
}
|
|
202
|
+
|
|
225
203
|
/**
|
|
226
204
|
* Sets the absolute transparency of a color.
|
|
227
205
|
* Any existing alpha values are overwritten.
|
|
@@ -229,34 +207,29 @@ export function getContrastRatio(foreground, background) {
|
|
|
229
207
|
* @param {number} value - value to set the alpha channel to in the range 0 - 1
|
|
230
208
|
* @returns {string} A CSS color string. Hex input values are returned as rgb
|
|
231
209
|
*/
|
|
232
|
-
|
|
233
210
|
export function alpha(color, value) {
|
|
234
211
|
color = decomposeColor(color);
|
|
235
212
|
value = clamp(value);
|
|
236
|
-
|
|
237
213
|
if (color.type === 'rgb' || color.type === 'hsl') {
|
|
238
214
|
color.type += 'a';
|
|
239
215
|
}
|
|
240
|
-
|
|
241
216
|
if (color.type === 'color') {
|
|
242
217
|
color.values[3] = `/${value}`;
|
|
243
218
|
} else {
|
|
244
219
|
color.values[3] = value;
|
|
245
220
|
}
|
|
246
|
-
|
|
247
221
|
return recomposeColor(color);
|
|
248
222
|
}
|
|
223
|
+
|
|
249
224
|
/**
|
|
250
225
|
* Darkens a color.
|
|
251
226
|
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color()
|
|
252
227
|
* @param {number} coefficient - multiplier in the range 0 - 1
|
|
253
228
|
* @returns {string} A CSS color string. Hex input values are returned as rgb
|
|
254
229
|
*/
|
|
255
|
-
|
|
256
230
|
export function darken(color, coefficient) {
|
|
257
231
|
color = decomposeColor(color);
|
|
258
232
|
coefficient = clamp(coefficient);
|
|
259
|
-
|
|
260
233
|
if (color.type.indexOf('hsl') !== -1) {
|
|
261
234
|
color.values[2] *= 1 - coefficient;
|
|
262
235
|
} else if (color.type.indexOf('rgb') !== -1 || color.type.indexOf('color') !== -1) {
|
|
@@ -264,20 +237,18 @@ export function darken(color, coefficient) {
|
|
|
264
237
|
color.values[i] *= 1 - coefficient;
|
|
265
238
|
}
|
|
266
239
|
}
|
|
267
|
-
|
|
268
240
|
return recomposeColor(color);
|
|
269
241
|
}
|
|
242
|
+
|
|
270
243
|
/**
|
|
271
244
|
* Lightens a color.
|
|
272
245
|
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color()
|
|
273
246
|
* @param {number} coefficient - multiplier in the range 0 - 1
|
|
274
247
|
* @returns {string} A CSS color string. Hex input values are returned as rgb
|
|
275
248
|
*/
|
|
276
|
-
|
|
277
249
|
export function lighten(color, coefficient) {
|
|
278
250
|
color = decomposeColor(color);
|
|
279
251
|
coefficient = clamp(coefficient);
|
|
280
|
-
|
|
281
252
|
if (color.type.indexOf('hsl') !== -1) {
|
|
282
253
|
color.values[2] += (100 - color.values[2]) * coefficient;
|
|
283
254
|
} else if (color.type.indexOf('rgb') !== -1) {
|
|
@@ -289,9 +260,9 @@ export function lighten(color, coefficient) {
|
|
|
289
260
|
color.values[i] += (1 - color.values[i]) * coefficient;
|
|
290
261
|
}
|
|
291
262
|
}
|
|
292
|
-
|
|
293
263
|
return recomposeColor(color);
|
|
294
264
|
}
|
|
265
|
+
|
|
295
266
|
/**
|
|
296
267
|
* Darken or lighten a color, depending on its luminance.
|
|
297
268
|
* Light colors are darkened, dark colors are lightened.
|
|
@@ -299,7 +270,6 @@ export function lighten(color, coefficient) {
|
|
|
299
270
|
* @param {number} coefficient=0.15 - multiplier in the range 0 - 1
|
|
300
271
|
* @returns {string} A CSS color string. Hex input values are returned as rgb
|
|
301
272
|
*/
|
|
302
|
-
|
|
303
273
|
export function emphasize(color, coefficient = 0.15) {
|
|
304
274
|
return getLuminance(color) > 0.5 ? darken(color, coefficient) : lighten(color, coefficient);
|
|
305
275
|
}
|
package/esm/compose.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import merge from './merge';
|
|
2
|
-
|
|
3
2
|
function compose(...styles) {
|
|
4
3
|
const handlers = styles.reduce((acc, style) => {
|
|
5
4
|
style.filterProps.forEach(prop => {
|
|
@@ -7,20 +6,16 @@ function compose(...styles) {
|
|
|
7
6
|
});
|
|
8
7
|
return acc;
|
|
9
8
|
}, {});
|
|
10
|
-
|
|
11
9
|
const fn = props => {
|
|
12
10
|
return Object.keys(props).reduce((acc, prop) => {
|
|
13
11
|
if (handlers[prop]) {
|
|
14
12
|
return merge(acc, handlers[prop](props));
|
|
15
13
|
}
|
|
16
|
-
|
|
17
14
|
return acc;
|
|
18
15
|
}, {});
|
|
19
16
|
};
|
|
20
|
-
|
|
21
17
|
fn.propTypes = process.env.NODE_ENV !== 'production' ? styles.reduce((acc, style) => Object.assign(acc, style.propTypes), {}) : {};
|
|
22
18
|
fn.filterProps = styles.reduce((acc, style) => acc.concat(style.filterProps), []);
|
|
23
19
|
return fn;
|
|
24
20
|
}
|
|
25
|
-
|
|
26
21
|
export default compose;
|
package/esm/createBox.js
CHANGED
|
@@ -19,14 +19,12 @@ export default function createBox(options = {}) {
|
|
|
19
19
|
})(styleFunctionSx);
|
|
20
20
|
const Box = /*#__PURE__*/React.forwardRef(function Box(inProps, ref) {
|
|
21
21
|
const theme = useTheme(defaultTheme);
|
|
22
|
-
|
|
23
22
|
const _extendSxProp = extendSxProp(inProps),
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
{
|
|
24
|
+
className,
|
|
25
|
+
component = 'div'
|
|
26
|
+
} = _extendSxProp,
|
|
27
|
+
other = _objectWithoutPropertiesLoose(_extendSxProp, _excluded);
|
|
30
28
|
return /*#__PURE__*/_jsx(BoxRoot, _extends({
|
|
31
29
|
as: component,
|
|
32
30
|
ref: ref,
|