@mui/system 5.10.13 → 5.10.14

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.
Files changed (206) hide show
  1. package/Box/Box.js +1 -10
  2. package/Box/Box.spec.d.ts +1 -1
  3. package/Box/index.js +0 -2
  4. package/CHANGELOG.md +70 -2
  5. package/Container/Container.d.ts +13 -13
  6. package/Container/Container.js +2 -17
  7. package/Container/ContainerProps.d.ts +40 -40
  8. package/Container/containerClasses.d.ts +22 -22
  9. package/Container/containerClasses.js +0 -3
  10. package/Container/createContainer.d.ts +18 -18
  11. package/Container/createContainer.js +15 -37
  12. package/Container/index.js +0 -6
  13. package/Stack/Stack.d.ts +13 -13
  14. package/Stack/Stack.js +1 -12
  15. package/Stack/StackProps.d.ts +42 -42
  16. package/Stack/createStack.d.ts +21 -21
  17. package/Stack/createStack.js +10 -48
  18. package/Stack/index.d.ts +5 -5
  19. package/Stack/index.js +0 -9
  20. package/Stack/stackClasses.d.ts +8 -8
  21. package/Stack/stackClasses.js +0 -3
  22. package/ThemeProvider/ThemeProvider.js +2 -22
  23. package/ThemeProvider/index.js +0 -2
  24. package/Unstable_Grid/Grid.d.ts +12 -12
  25. package/Unstable_Grid/Grid.js +6 -42
  26. package/Unstable_Grid/GridProps.d.ts +162 -162
  27. package/Unstable_Grid/createGrid.d.ts +11 -11
  28. package/Unstable_Grid/createGrid.js +19 -49
  29. package/Unstable_Grid/gridClasses.d.ts +20 -20
  30. package/Unstable_Grid/gridClasses.js +8 -7
  31. package/Unstable_Grid/gridGenerator.d.ts +29 -28
  32. package/Unstable_Grid/gridGenerator.js +22 -63
  33. package/Unstable_Grid/index.d.ts +5 -5
  34. package/Unstable_Grid/index.js +0 -9
  35. package/borders.js +0 -14
  36. package/breakpoints.js +3 -32
  37. package/colorManipulator.js +13 -55
  38. package/compose.js +0 -7
  39. package/createBox.js +5 -20
  40. package/createBox.spec.d.ts +1 -1
  41. package/createStyled.js +27 -71
  42. package/createTheme/createBreakpoints.js +22 -37
  43. package/createTheme/createSpacing.d.ts +10 -10
  44. package/createTheme/createSpacing.js +4 -8
  45. package/createTheme/createTheme.js +6 -16
  46. package/createTheme/index.js +0 -2
  47. package/cssGrid.js +0 -21
  48. package/cssVars/createCssVarsProvider.js +24 -72
  49. package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
  50. package/cssVars/createGetCssVar.d.ts +5 -5
  51. package/cssVars/createGetCssVar.js +2 -7
  52. package/cssVars/cssVarsParser.d.ts +65 -65
  53. package/cssVars/cssVarsParser.js +3 -15
  54. package/cssVars/getInitColorSchemeScript.d.ts +42 -42
  55. package/cssVars/getInitColorSchemeScript.js +0 -6
  56. package/cssVars/index.d.ts +3 -3
  57. package/cssVars/index.js +0 -3
  58. package/cssVars/useCurrentColorScheme.d.ts +53 -53
  59. package/cssVars/useCurrentColorScheme.js +20 -49
  60. package/display.js +0 -6
  61. package/esm/Box/Box.js +1 -6
  62. package/esm/Container/Container.js +3 -14
  63. package/esm/Container/createContainer.js +15 -25
  64. package/esm/Stack/Stack.js +1 -9
  65. package/esm/Stack/createStack.js +10 -29
  66. package/esm/ThemeProvider/ThemeProvider.js +2 -11
  67. package/esm/Unstable_Grid/Grid.js +6 -39
  68. package/esm/Unstable_Grid/createGrid.js +18 -35
  69. package/esm/Unstable_Grid/gridClasses.js +8 -4
  70. package/esm/Unstable_Grid/gridGenerator.js +20 -38
  71. package/esm/borders.js +0 -6
  72. package/esm/breakpoints.js +7 -22
  73. package/esm/colorManipulator.js +13 -43
  74. package/esm/compose.js +0 -5
  75. package/esm/createBox.js +5 -7
  76. package/esm/createStyled.js +27 -64
  77. package/esm/createTheme/createBreakpoints.js +22 -34
  78. package/esm/createTheme/createSpacing.js +4 -7
  79. package/esm/createTheme/createTheme.js +6 -9
  80. package/esm/cssGrid.js +0 -9
  81. package/esm/cssVars/createCssVarsProvider.js +24 -58
  82. package/esm/cssVars/createGetCssVar.js +2 -6
  83. package/esm/cssVars/cssVarsParser.js +3 -11
  84. package/esm/cssVars/useCurrentColorScheme.js +20 -44
  85. package/esm/getThemeValue.js +0 -2
  86. package/esm/index.js +1 -2
  87. package/esm/memoize.js +0 -1
  88. package/esm/merge.js +0 -3
  89. package/esm/palette.js +0 -3
  90. package/esm/propsToClassKey.js +4 -7
  91. package/esm/sizing.js +0 -5
  92. package/esm/spacing.js +3 -23
  93. package/esm/style.js +2 -19
  94. package/esm/styleFunctionSx/extendSxProp.js +3 -10
  95. package/esm/styleFunctionSx/styleFunctionSx.js +3 -16
  96. package/esm/sx/sx.js +0 -2
  97. package/esm/useTheme.js +0 -2
  98. package/esm/useThemeProps/getThemeProps.js +0 -2
  99. package/esm/useThemeWithoutDefault.js +0 -3
  100. package/flexbox.js +0 -4
  101. package/getThemeValue.js +0 -14
  102. package/index.js +1 -55
  103. package/index.spec.d.ts +1 -1
  104. package/legacy/Box/Box.js +1 -6
  105. package/legacy/Container/Container.js +3 -14
  106. package/legacy/Container/createContainer.js +29 -39
  107. package/legacy/Stack/Stack.js +1 -9
  108. package/legacy/Stack/createStack.js +17 -37
  109. package/legacy/ThemeProvider/ThemeProvider.js +3 -12
  110. package/legacy/Unstable_Grid/Grid.js +6 -39
  111. package/legacy/Unstable_Grid/createGrid.js +34 -53
  112. package/legacy/Unstable_Grid/gridGenerator.js +36 -58
  113. package/legacy/borders.js +0 -6
  114. package/legacy/breakpoints.js +9 -28
  115. package/legacy/colorManipulator.js +16 -48
  116. package/legacy/compose.js +0 -6
  117. package/legacy/createBox.js +9 -11
  118. package/legacy/createStyled.js +27 -68
  119. package/legacy/createTheme/createBreakpoints.js +20 -33
  120. package/legacy/createTheme/createSpacing.js +4 -9
  121. package/legacy/createTheme/createTheme.js +7 -13
  122. package/legacy/cssGrid.js +0 -9
  123. package/legacy/cssVars/createCssVarsProvider.js +90 -129
  124. package/legacy/cssVars/createGetCssVar.js +2 -10
  125. package/legacy/cssVars/cssVarsParser.js +7 -20
  126. package/legacy/cssVars/getInitColorSchemeScript.js +14 -15
  127. package/legacy/cssVars/useCurrentColorScheme.js +43 -69
  128. package/legacy/getThemeValue.js +0 -3
  129. package/legacy/index.js +2 -3
  130. package/legacy/memoize.js +0 -1
  131. package/legacy/merge.js +0 -3
  132. package/legacy/palette.js +0 -3
  133. package/legacy/propsToClassKey.js +2 -5
  134. package/legacy/sizing.js +0 -5
  135. package/legacy/spacing.js +6 -27
  136. package/legacy/style.js +6 -24
  137. package/legacy/styleFunctionSx/extendSxProp.js +3 -11
  138. package/legacy/styleFunctionSx/styleFunctionSx.js +6 -21
  139. package/legacy/sx/sx.js +0 -2
  140. package/legacy/useTheme.js +0 -2
  141. package/legacy/useThemeProps/getThemeProps.js +2 -4
  142. package/legacy/useThemeProps/useThemeProps.js +2 -2
  143. package/legacy/useThemeWithoutDefault.js +0 -3
  144. package/memoize.js +0 -2
  145. package/merge.js +0 -5
  146. package/modern/Box/Box.js +1 -6
  147. package/modern/Container/Container.js +3 -14
  148. package/modern/Container/createContainer.js +15 -25
  149. package/modern/Stack/Stack.js +1 -9
  150. package/modern/Stack/createStack.js +10 -29
  151. package/modern/ThemeProvider/ThemeProvider.js +2 -11
  152. package/modern/Unstable_Grid/Grid.js +6 -39
  153. package/modern/Unstable_Grid/createGrid.js +18 -34
  154. package/modern/Unstable_Grid/gridClasses.js +8 -4
  155. package/modern/Unstable_Grid/gridGenerator.js +20 -36
  156. package/modern/borders.js +0 -6
  157. package/modern/breakpoints.js +7 -21
  158. package/modern/colorManipulator.js +13 -43
  159. package/modern/compose.js +0 -5
  160. package/modern/createBox.js +5 -7
  161. package/modern/createStyled.js +27 -63
  162. package/modern/createTheme/createBreakpoints.js +22 -34
  163. package/modern/createTheme/createSpacing.js +4 -7
  164. package/modern/createTheme/createTheme.js +6 -9
  165. package/modern/cssGrid.js +0 -9
  166. package/modern/cssVars/createCssVarsProvider.js +24 -58
  167. package/modern/cssVars/createGetCssVar.js +2 -6
  168. package/modern/cssVars/cssVarsParser.js +3 -11
  169. package/modern/cssVars/useCurrentColorScheme.js +20 -44
  170. package/modern/getThemeValue.js +0 -2
  171. package/modern/index.js +2 -3
  172. package/modern/memoize.js +0 -1
  173. package/modern/merge.js +0 -3
  174. package/modern/palette.js +0 -3
  175. package/modern/propsToClassKey.js +4 -7
  176. package/modern/sizing.js +0 -4
  177. package/modern/spacing.js +3 -22
  178. package/modern/style.js +2 -19
  179. package/modern/styleFunctionSx/extendSxProp.js +3 -10
  180. package/modern/styleFunctionSx/styleFunctionSx.js +3 -16
  181. package/modern/sx/sx.js +0 -2
  182. package/modern/useTheme.js +0 -2
  183. package/modern/useThemeProps/getThemeProps.js +0 -2
  184. package/modern/useThemeWithoutDefault.js +0 -3
  185. package/package.json +6 -6
  186. package/palette.js +0 -6
  187. package/positions.js +0 -6
  188. package/propsToClassKey.js +4 -10
  189. package/responsivePropType.js +0 -3
  190. package/shadows.js +0 -3
  191. package/sizing.js +0 -11
  192. package/spacing.js +3 -37
  193. package/style.js +2 -24
  194. package/styleFunctionSx/extendSxProp.js +3 -15
  195. package/styleFunctionSx/index.js +0 -5
  196. package/styleFunctionSx/styleFunctionSx.js +3 -21
  197. package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
  198. package/styled.js +0 -3
  199. package/sx/index.js +0 -2
  200. package/sx/sx.js +0 -4
  201. package/typography.js +0 -4
  202. package/useTheme.js +0 -6
  203. package/useThemeProps/getThemeProps.js +0 -4
  204. package/useThemeProps/index.js +0 -3
  205. package/useThemeProps/useThemeProps.js +0 -4
  206. package/useThemeWithoutDefault.js +0 -4
@@ -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
- }); // Truncate at 3 digits
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/modern/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;
@@ -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
- className,
26
- component = 'div'
27
- } = _extendSxProp,
28
- other = _objectWithoutPropertiesLoose(_extendSxProp, _excluded);
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,
@@ -1,43 +1,37 @@
1
1
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
3
  const _excluded = ["name", "slot", "skipVariantsResolver", "skipSx", "overridesResolver"],
4
- _excluded2 = ["theme"],
5
- _excluded3 = ["theme"];
6
-
4
+ _excluded2 = ["theme"],
5
+ _excluded3 = ["theme"];
7
6
  /* eslint-disable no-underscore-dangle */
8
7
  import styledEngineStyled, { internal_processStyles as processStyles } from '@mui/styled-engine';
9
8
  import { getDisplayName } from '@mui/utils';
10
9
  import createTheme from './createTheme';
11
10
  import propsToClassKey from './propsToClassKey';
12
11
  import defaultStyleFunctionSx from './styleFunctionSx';
13
-
14
12
  function isEmpty(obj) {
15
13
  return Object.keys(obj).length === 0;
16
- } // https://github.com/emotion-js/emotion/blob/26ded6109fcd8ca9875cc2ce4564fee678a3f3c5/packages/styled/src/utils.js#L40
17
-
14
+ }
18
15
 
16
+ // https://github.com/emotion-js/emotion/blob/26ded6109fcd8ca9875cc2ce4564fee678a3f3c5/packages/styled/src/utils.js#L40
19
17
  function isStringTag(tag) {
20
- return typeof tag === 'string' && // 96 is one less than the char code
18
+ return typeof tag === 'string' &&
19
+ // 96 is one less than the char code
21
20
  // for "a" so this is checking that
22
21
  // it's a lowercase character
23
22
  tag.charCodeAt(0) > 96;
24
23
  }
25
-
26
24
  const getStyleOverrides = (name, theme) => {
27
25
  if (theme.components && theme.components[name] && theme.components[name].styleOverrides) {
28
26
  return theme.components[name].styleOverrides;
29
27
  }
30
-
31
28
  return null;
32
29
  };
33
-
34
30
  const getVariantStyles = (name, theme) => {
35
31
  let variants = [];
36
-
37
32
  if (theme && theme.components && theme.components[name] && theme.components[name].variants) {
38
33
  variants = theme.components[name].variants;
39
34
  }
40
-
41
35
  const variantsStyles = {};
42
36
  variants.forEach(definition => {
43
37
  const key = propsToClassKey(definition.props);
@@ -45,14 +39,12 @@ const getVariantStyles = (name, theme) => {
45
39
  });
46
40
  return variantsStyles;
47
41
  };
48
-
49
42
  const variantsResolver = (props, styles, theme, name) => {
50
43
  const {
51
44
  ownerState = {}
52
45
  } = props;
53
46
  const variantsStyles = [];
54
47
  const themeVariants = theme?.components?.[name]?.variants;
55
-
56
48
  if (themeVariants) {
57
49
  themeVariants.forEach(themeVariant => {
58
50
  let isMatch = true;
@@ -61,26 +53,22 @@ const variantsResolver = (props, styles, theme, name) => {
61
53
  isMatch = false;
62
54
  }
63
55
  });
64
-
65
56
  if (isMatch) {
66
57
  variantsStyles.push(styles[propsToClassKey(themeVariant.props)]);
67
58
  }
68
59
  });
69
60
  }
70
-
71
61
  return variantsStyles;
72
- }; // Update /system/styled/#api in case if this changes
73
-
62
+ };
74
63
 
64
+ // Update /system/styled/#api in case if this changes
75
65
  export function shouldForwardProp(prop) {
76
66
  return prop !== 'ownerState' && prop !== 'theme' && prop !== 'sx' && prop !== 'as';
77
67
  }
78
68
  export const systemDefaultTheme = createTheme();
79
-
80
69
  const lowercaseFirstLetter = string => {
81
70
  return string.charAt(0).toLowerCase() + string.slice(1);
82
71
  };
83
-
84
72
  export default function createStyled(input = {}) {
85
73
  const {
86
74
  defaultTheme = systemDefaultTheme,
@@ -88,41 +76,35 @@ export default function createStyled(input = {}) {
88
76
  slotShouldForwardProp = shouldForwardProp,
89
77
  styleFunctionSx = defaultStyleFunctionSx
90
78
  } = input;
91
-
92
79
  const systemSx = props => {
93
80
  const theme = isEmpty(props.theme) ? defaultTheme : props.theme;
94
81
  return styleFunctionSx(_extends({}, props, {
95
82
  theme
96
83
  }));
97
84
  };
98
-
99
85
  systemSx.__mui_systemSx = true;
100
86
  return (tag, inputOptions = {}) => {
101
87
  // Filter out the `sx` style function from the previous styled component to prevent unnecessary styles generated by the composite components.
102
88
  processStyles(tag, styles => styles.filter(style => !style?.__mui_systemSx));
103
-
104
89
  const {
105
- name: componentName,
106
- slot: componentSlot,
107
- skipVariantsResolver: inputSkipVariantsResolver,
108
- skipSx: inputSkipSx,
109
- overridesResolver
110
- } = inputOptions,
111
- options = _objectWithoutPropertiesLoose(inputOptions, _excluded); // if skipVariantsResolver option is defined, take the value, otherwise, true for root and false for other slots.
112
-
113
-
90
+ name: componentName,
91
+ slot: componentSlot,
92
+ skipVariantsResolver: inputSkipVariantsResolver,
93
+ skipSx: inputSkipSx,
94
+ overridesResolver
95
+ } = inputOptions,
96
+ options = _objectWithoutPropertiesLoose(inputOptions, _excluded);
97
+
98
+ // if skipVariantsResolver option is defined, take the value, otherwise, true for root and false for other slots.
114
99
  const skipVariantsResolver = inputSkipVariantsResolver !== undefined ? inputSkipVariantsResolver : componentSlot && componentSlot !== 'Root' || false;
115
100
  const skipSx = inputSkipSx || false;
116
101
  let label;
117
-
118
102
  if (process.env.NODE_ENV !== 'production') {
119
103
  if (componentName) {
120
104
  label = `${componentName}-${lowercaseFirstLetter(componentSlot || 'Root')}`;
121
105
  }
122
106
  }
123
-
124
107
  let shouldForwardPropOption = shouldForwardProp;
125
-
126
108
  if (componentSlot === 'Root') {
127
109
  shouldForwardPropOption = rootShouldForwardProp;
128
110
  } else if (componentSlot) {
@@ -132,12 +114,10 @@ export default function createStyled(input = {}) {
132
114
  // for string (html) tag, preserve the behavior in emotion & styled-components.
133
115
  shouldForwardPropOption = undefined;
134
116
  }
135
-
136
117
  const defaultStyledResolver = styledEngineStyled(tag, _extends({
137
118
  shouldForwardProp: shouldForwardPropOption,
138
119
  label
139
120
  }, options));
140
-
141
121
  const muiStyledResolver = (styleArg, ...expressions) => {
142
122
  const expressionsWithDefaultTheme = expressions ? expressions.map(stylesArg => {
143
123
  // On the server Emotion doesn't use React.forwardRef for creating components, so the created
@@ -145,22 +125,19 @@ export default function createStyled(input = {}) {
145
125
  // which are basically components used as a selectors.
146
126
  return typeof stylesArg === 'function' && stylesArg.__emotion_real !== stylesArg ? _ref => {
147
127
  let {
148
- theme: themeInput
149
- } = _ref,
150
- other = _objectWithoutPropertiesLoose(_ref, _excluded2);
151
-
128
+ theme: themeInput
129
+ } = _ref,
130
+ other = _objectWithoutPropertiesLoose(_ref, _excluded2);
152
131
  return stylesArg(_extends({
153
132
  theme: isEmpty(themeInput) ? defaultTheme : themeInput
154
133
  }, other));
155
134
  } : stylesArg;
156
135
  }) : [];
157
136
  let transformedStyleArg = styleArg;
158
-
159
137
  if (componentName && overridesResolver) {
160
138
  expressionsWithDefaultTheme.push(props => {
161
139
  const theme = isEmpty(props.theme) ? defaultTheme : props.theme;
162
140
  const styleOverrides = getStyleOverrides(componentName, theme);
163
-
164
141
  if (styleOverrides) {
165
142
  const resolvedStyleOverrides = {};
166
143
  Object.entries(styleOverrides).forEach(([slotKey, slotStyle]) => {
@@ -170,69 +147,56 @@ export default function createStyled(input = {}) {
170
147
  });
171
148
  return overridesResolver(props, resolvedStyleOverrides);
172
149
  }
173
-
174
150
  return null;
175
151
  });
176
152
  }
177
-
178
153
  if (componentName && !skipVariantsResolver) {
179
154
  expressionsWithDefaultTheme.push(props => {
180
155
  const theme = isEmpty(props.theme) ? defaultTheme : props.theme;
181
156
  return variantsResolver(props, getVariantStyles(componentName, theme), theme, componentName);
182
157
  });
183
158
  }
184
-
185
159
  if (!skipSx) {
186
160
  expressionsWithDefaultTheme.push(systemSx);
187
161
  }
188
-
189
162
  const numOfCustomFnsApplied = expressionsWithDefaultTheme.length - expressions.length;
190
-
191
163
  if (Array.isArray(styleArg) && numOfCustomFnsApplied > 0) {
192
- const placeholders = new Array(numOfCustomFnsApplied).fill(''); // If the type is array, than we need to add placeholders in the template for the overrides, variants and the sx styles.
193
-
164
+ const placeholders = new Array(numOfCustomFnsApplied).fill('');
165
+ // If the type is array, than we need to add placeholders in the template for the overrides, variants and the sx styles.
194
166
  transformedStyleArg = [...styleArg, ...placeholders];
195
167
  transformedStyleArg.raw = [...styleArg.raw, ...placeholders];
196
- } else if (typeof styleArg === 'function' && // On the server Emotion doesn't use React.forwardRef for creating components, so the created
168
+ } else if (typeof styleArg === 'function' &&
169
+ // On the server Emotion doesn't use React.forwardRef for creating components, so the created
197
170
  // component stays as a function. This condition makes sure that we do not interpolate functions
198
171
  // which are basically components used as a selectors.
199
172
  styleArg.__emotion_real !== styleArg) {
200
173
  // If the type is function, we need to define the default theme.
201
174
  transformedStyleArg = _ref2 => {
202
175
  let {
203
- theme: themeInput
204
- } = _ref2,
205
- other = _objectWithoutPropertiesLoose(_ref2, _excluded3);
206
-
176
+ theme: themeInput
177
+ } = _ref2,
178
+ other = _objectWithoutPropertiesLoose(_ref2, _excluded3);
207
179
  return styleArg(_extends({
208
180
  theme: isEmpty(themeInput) ? defaultTheme : themeInput
209
181
  }, other));
210
182
  };
211
183
  }
212
-
213
184
  const Component = defaultStyledResolver(transformedStyleArg, ...expressionsWithDefaultTheme);
214
-
215
185
  if (process.env.NODE_ENV !== 'production') {
216
186
  let displayName;
217
-
218
187
  if (componentName) {
219
188
  displayName = `${componentName}${componentSlot || ''}`;
220
189
  }
221
-
222
190
  if (displayName === undefined) {
223
191
  displayName = `Styled(${getDisplayName(tag)})`;
224
192
  }
225
-
226
193
  Component.displayName = displayName;
227
194
  }
228
-
229
195
  return Component;
230
196
  };
231
-
232
197
  if (defaultStyledResolver.withConfig) {
233
198
  muiStyledResolver.withConfig = defaultStyledResolver.withConfig;
234
199
  }
235
-
236
200
  return muiStyledResolver;
237
201
  };
238
202
  }