@mui/system 5.13.1 → 5.13.2

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 (93) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/Container/Container.d.ts +13 -13
  3. package/Container/ContainerProps.d.ts +40 -40
  4. package/Container/containerClasses.d.ts +22 -22
  5. package/Container/createContainer.d.ts +18 -18
  6. package/Container/createContainer.js +35 -41
  7. package/GlobalStyles/GlobalStyles.d.ts +13 -13
  8. package/GlobalStyles/index.d.ts +2 -2
  9. package/Stack/Stack.d.ts +14 -14
  10. package/Stack/StackProps.d.ts +53 -53
  11. package/Stack/createStack.d.ts +21 -21
  12. package/Stack/createStack.js +26 -24
  13. package/Stack/index.d.ts +5 -5
  14. package/Stack/stackClasses.d.ts +8 -8
  15. package/ThemeProvider/ThemeProvider.js +5 -9
  16. package/Unstable_Grid/Grid.d.ts +12 -12
  17. package/Unstable_Grid/GridProps.d.ts +185 -185
  18. package/Unstable_Grid/createGrid.d.ts +11 -11
  19. package/Unstable_Grid/createGrid.js +23 -21
  20. package/Unstable_Grid/gridClasses.d.ts +20 -20
  21. package/Unstable_Grid/gridGenerator.d.ts +38 -38
  22. package/Unstable_Grid/gridGenerator.js +18 -20
  23. package/Unstable_Grid/index.d.ts +5 -5
  24. package/breakpoints.js +6 -7
  25. package/createBox.js +12 -9
  26. package/createStyled.js +32 -40
  27. package/createTheme/createBreakpoints.js +26 -24
  28. package/createTheme/createSpacing.d.ts +10 -10
  29. package/createTheme/createTheme.js +14 -18
  30. package/cssVars/createCssVarsProvider.js +20 -21
  31. package/cssVars/createCssVarsTheme.d.ts +15 -15
  32. package/cssVars/createCssVarsTheme.js +10 -10
  33. package/cssVars/createGetCssVar.d.ts +5 -5
  34. package/cssVars/cssVarsParser.d.ts +64 -64
  35. package/cssVars/getInitColorSchemeScript.d.ts +42 -42
  36. package/cssVars/index.d.ts +5 -5
  37. package/cssVars/prepareCssVars.d.ts +16 -16
  38. package/cssVars/prepareCssVars.js +12 -13
  39. package/cssVars/useCurrentColorScheme.d.ts +53 -53
  40. package/cssVars/useCurrentColorScheme.js +11 -17
  41. package/esm/Container/createContainer.js +35 -41
  42. package/esm/Stack/createStack.js +26 -24
  43. package/esm/ThemeProvider/ThemeProvider.js +5 -9
  44. package/esm/Unstable_Grid/createGrid.js +23 -21
  45. package/esm/Unstable_Grid/gridGenerator.js +17 -20
  46. package/esm/breakpoints.js +6 -7
  47. package/esm/createBox.js +12 -9
  48. package/esm/createStyled.js +31 -38
  49. package/esm/createTheme/createBreakpoints.js +25 -24
  50. package/esm/createTheme/createTheme.js +14 -18
  51. package/esm/cssVars/createCssVarsProvider.js +20 -21
  52. package/esm/cssVars/createCssVarsTheme.js +10 -10
  53. package/esm/cssVars/prepareCssVars.js +12 -13
  54. package/esm/cssVars/useCurrentColorScheme.js +10 -17
  55. package/esm/propsToClassKey.js +5 -3
  56. package/esm/styleFunctionSx/extendSxProp.js +10 -14
  57. package/index.js +1 -1
  58. package/legacy/Container/createContainer.js +6 -7
  59. package/legacy/Stack/createStack.js +5 -6
  60. package/legacy/ThemeProvider/ThemeProvider.js +3 -4
  61. package/legacy/Unstable_Grid/createGrid.js +4 -6
  62. package/legacy/Unstable_Grid/gridGenerator.js +4 -6
  63. package/legacy/breakpoints.js +3 -5
  64. package/legacy/createBox.js +2 -4
  65. package/legacy/createStyled.js +11 -13
  66. package/legacy/createTheme/createBreakpoints.js +3 -4
  67. package/legacy/createTheme/createTheme.js +4 -6
  68. package/legacy/cssVars/createCssVarsProvider.js +5 -6
  69. package/legacy/cssVars/createCssVarsTheme.js +2 -4
  70. package/legacy/cssVars/prepareCssVars.js +3 -5
  71. package/legacy/cssVars/useCurrentColorScheme.js +7 -9
  72. package/legacy/index.js +1 -1
  73. package/legacy/styleFunctionSx/extendSxProp.js +4 -6
  74. package/modern/Container/createContainer.js +35 -41
  75. package/modern/Stack/createStack.js +26 -24
  76. package/modern/ThemeProvider/ThemeProvider.js +5 -9
  77. package/modern/Unstable_Grid/createGrid.js +23 -21
  78. package/modern/Unstable_Grid/gridGenerator.js +17 -20
  79. package/modern/breakpoints.js +6 -7
  80. package/modern/createBox.js +12 -9
  81. package/modern/createStyled.js +31 -38
  82. package/modern/createTheme/createBreakpoints.js +25 -24
  83. package/modern/createTheme/createTheme.js +14 -18
  84. package/modern/cssVars/createCssVarsProvider.js +20 -21
  85. package/modern/cssVars/createCssVarsTheme.js +10 -10
  86. package/modern/cssVars/prepareCssVars.js +12 -13
  87. package/modern/cssVars/useCurrentColorScheme.js +10 -17
  88. package/modern/index.js +1 -1
  89. package/modern/propsToClassKey.js +5 -3
  90. package/modern/styleFunctionSx/extendSxProp.js +10 -14
  91. package/package.json +2 -2
  92. package/propsToClassKey.js +6 -3
  93. package/styleFunctionSx/extendSxProp.js +10 -14
@@ -5,20 +5,23 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
8
10
  var _utils = require("@mui/utils");
9
11
  var _createBreakpoints = _interopRequireDefault(require("./createBreakpoints"));
10
12
  var _shape = _interopRequireDefault(require("./shape"));
11
13
  var _createSpacing = _interopRequireDefault(require("./createSpacing"));
12
14
  var _styleFunctionSx = _interopRequireDefault(require("../styleFunctionSx/styleFunctionSx"));
13
15
  var _defaultSxConfig = _interopRequireDefault(require("../styleFunctionSx/defaultSxConfig"));
16
+ const _excluded = ["breakpoints", "palette", "spacing", "shape"];
14
17
  function createTheme(options = {}, ...args) {
15
18
  const {
16
- breakpoints: breakpointsInput = {},
17
- palette: paletteInput = {},
18
- spacing: spacingInput,
19
- shape: shapeInput = {},
20
- ...other
21
- } = options;
19
+ breakpoints: breakpointsInput = {},
20
+ palette: paletteInput = {},
21
+ spacing: spacingInput,
22
+ shape: shapeInput = {}
23
+ } = options,
24
+ other = (0, _objectWithoutPropertiesLoose2.default)(options, _excluded);
22
25
  const breakpoints = (0, _createBreakpoints.default)(breakpointsInput);
23
26
  const spacing = (0, _createSpacing.default)(spacingInput);
24
27
  let muiTheme = (0, _utils.deepmerge)({
@@ -26,21 +29,14 @@ function createTheme(options = {}, ...args) {
26
29
  direction: 'ltr',
27
30
  components: {},
28
31
  // Inject component definitions.
29
- palette: {
30
- mode: 'light',
31
- ...paletteInput
32
- },
32
+ palette: (0, _extends2.default)({
33
+ mode: 'light'
34
+ }, paletteInput),
33
35
  spacing,
34
- shape: {
35
- ..._shape.default,
36
- ...shapeInput
37
- }
36
+ shape: (0, _extends2.default)({}, _shape.default, shapeInput)
38
37
  }, other);
39
38
  muiTheme = args.reduce((acc, argument) => (0, _utils.deepmerge)(acc, argument), muiTheme);
40
- muiTheme.unstable_sxConfig = {
41
- ..._defaultSxConfig.default,
42
- ...(other == null ? void 0 : other.unstable_sxConfig)
43
- };
39
+ muiTheme.unstable_sxConfig = (0, _extends2.default)({}, _defaultSxConfig.default, other == null ? void 0 : other.unstable_sxConfig);
44
40
  muiTheme.unstable_sx = function sx(props) {
45
41
  return (0, _styleFunctionSx.default)({
46
42
  sx: props,
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.DISABLE_CSS_TRANSITION = void 0;
8
8
  exports.default = createCssVarsProvider;
9
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
9
11
  var _utils = require("@mui/utils");
10
12
  var React = _interopRequireWildcard(require("react"));
11
13
  var _propTypes = _interopRequireDefault(require("prop-types"));
@@ -15,6 +17,7 @@ var _ThemeProvider = _interopRequireDefault(require("../ThemeProvider"));
15
17
  var _getInitColorSchemeScript = _interopRequireWildcard(require("./getInitColorSchemeScript"));
16
18
  var _useCurrentColorScheme = _interopRequireDefault(require("./useCurrentColorScheme"));
17
19
  var _jsxRuntime = require("react/jsx-runtime");
20
+ const _excluded = ["colorSchemes", "components", "generateCssVars", "cssVarPrefix"];
18
21
  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); }
19
22
  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; }
20
23
  const DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
@@ -64,16 +67,17 @@ function createCssVarsProvider(options) {
64
67
  const ctx = React.useContext(ColorSchemeContext);
65
68
  const nested = !!ctx && !disableNestedContext;
66
69
  const scopedTheme = themeProp[themeId];
67
- const {
68
- colorSchemes = {},
69
- components = {},
70
- generateCssVars = () => ({
71
- vars: {},
72
- css: {}
73
- }),
74
- cssVarPrefix,
75
- ...restThemeProp
76
- } = scopedTheme || themeProp;
70
+ const _ref = scopedTheme || themeProp,
71
+ {
72
+ colorSchemes = {},
73
+ components = {},
74
+ generateCssVars = () => ({
75
+ vars: {},
76
+ css: {}
77
+ }),
78
+ cssVarPrefix
79
+ } = _ref,
80
+ restThemeProp = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);
77
81
  const allColorSchemes = Object.keys(colorSchemes);
78
82
  const defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
79
83
  const defaultDarkColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.dark;
@@ -131,14 +135,13 @@ function createCssVarsProvider(options) {
131
135
  } = generateCssVars();
132
136
 
133
137
  // 3. Start composing the theme object
134
- const theme = {
135
- ...restThemeProp,
138
+ const theme = (0, _extends2.default)({}, restThemeProp, {
136
139
  components,
137
140
  colorSchemes,
138
141
  cssVarPrefix,
139
142
  vars: rootVars,
140
143
  getColorSchemeSelector: targetColorScheme => `[${attribute}="${targetColorScheme}"] &`
141
- };
144
+ });
142
145
 
143
146
  // 4. Create color CSS variables and store them in objects (to be generated in stylesheets in the final step)
144
147
  // The default color scheme stylesheet is constructed to have the least CSS specificity.
@@ -156,10 +159,7 @@ function createCssVarsProvider(options) {
156
159
  Object.keys(scheme).forEach(schemeKey => {
157
160
  if (scheme[schemeKey] && typeof scheme[schemeKey] === 'object') {
158
161
  // shallow merge the 1st level structure of the theme.
159
- theme[schemeKey] = {
160
- ...theme[schemeKey],
161
- ...scheme[schemeKey]
162
- };
162
+ theme[schemeKey] = (0, _extends2.default)({}, theme[schemeKey], scheme[schemeKey]);
163
163
  } else {
164
164
  theme[schemeKey] = scheme[schemeKey];
165
165
  }
@@ -329,15 +329,14 @@ function createCssVarsProvider(options) {
329
329
  } : void 0;
330
330
  const defaultLightColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.light;
331
331
  const defaultDarkColorScheme = typeof designSystemColorScheme === 'string' ? designSystemColorScheme : designSystemColorScheme.dark;
332
- const getInitColorSchemeScript = params => (0, _getInitColorSchemeScript.default)({
332
+ const getInitColorSchemeScript = params => (0, _getInitColorSchemeScript.default)((0, _extends2.default)({
333
333
  attribute: defaultAttribute,
334
334
  colorSchemeStorageKey: defaultColorSchemeStorageKey,
335
335
  defaultMode: designSystemMode,
336
336
  defaultLightColorScheme,
337
337
  defaultDarkColorScheme,
338
- modeStorageKey: defaultModeStorageKey,
339
- ...params
340
- });
338
+ modeStorageKey: defaultModeStorageKey
339
+ }, params));
341
340
  return {
342
341
  CssVarsProvider,
343
342
  useColorScheme,
@@ -1,15 +1,15 @@
1
- import { DefaultCssVarsTheme } from './prepareCssVars';
2
- interface Theme extends DefaultCssVarsTheme {
3
- cssVarPrefix?: string;
4
- shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
5
- }
6
- declare function createCssVarsTheme<T extends Theme, ThemeVars extends Record<string, any>>(theme: T): T & {
7
- vars: ThemeVars;
8
- generateCssVars: (colorScheme?: string | undefined) => {
9
- css: {
10
- [x: string]: string | number;
11
- };
12
- vars: ThemeVars;
13
- };
14
- };
15
- export default createCssVarsTheme;
1
+ import { DefaultCssVarsTheme } from './prepareCssVars';
2
+ interface Theme extends DefaultCssVarsTheme {
3
+ cssVarPrefix?: string;
4
+ shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
5
+ }
6
+ declare function createCssVarsTheme<T extends Theme, ThemeVars extends Record<string, any>>(theme: T): T & {
7
+ vars: ThemeVars;
8
+ generateCssVars: (colorScheme?: string | undefined) => {
9
+ css: {
10
+ [x: string]: string | number;
11
+ };
12
+ vars: ThemeVars;
13
+ };
14
+ };
15
+ export default createCssVarsTheme;
@@ -5,20 +5,20 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
8
10
  var _prepareCssVars = _interopRequireDefault(require("./prepareCssVars"));
11
+ const _excluded = ["cssVarPrefix", "shouldSkipGeneratingVar"];
9
12
  function createCssVarsTheme(theme) {
10
13
  const {
11
- cssVarPrefix,
12
- shouldSkipGeneratingVar,
13
- ...otherTheme
14
- } = theme;
15
- return {
16
- ...theme,
17
- ...(0, _prepareCssVars.default)(otherTheme, {
18
- prefix: cssVarPrefix,
14
+ cssVarPrefix,
19
15
  shouldSkipGeneratingVar
20
- })
21
- };
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
22
  }
23
23
  var _default = createCssVarsTheme;
24
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;
@@ -1,64 +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: Record<string, any>, options?: {
57
- prefix?: string;
58
- shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
59
- }): {
60
- css: Record<string, string | number>;
61
- vars: T;
62
- varsWithDefaults: {};
63
- };
64
- export {};
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: Record<string, any>, options?: {
57
+ prefix?: string;
58
+ shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
59
+ }): {
60
+ css: Record<string, string | number>;
61
+ vars: T;
62
+ varsWithDefaults: {};
63
+ };
64
+ export {};
@@ -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
+ import * as React from '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): React.JSX.Element;
@@ -1,5 +1,5 @@
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';
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';
@@ -1,16 +1,16 @@
1
- export interface DefaultCssVarsTheme {
2
- colorSchemes: Record<string, any>;
3
- }
4
- declare function prepareCssVars<T extends DefaultCssVarsTheme, ThemeVars extends Record<string, any>>(theme: T, parserConfig?: {
5
- prefix?: string;
6
- shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
7
- }): {
8
- vars: ThemeVars;
9
- generateCssVars: (colorScheme?: string) => {
10
- css: {
11
- [x: string]: string | number;
12
- };
13
- vars: ThemeVars;
14
- };
15
- };
16
- export default prepareCssVars;
1
+ export interface DefaultCssVarsTheme {
2
+ colorSchemes: Record<string, any>;
3
+ }
4
+ declare function prepareCssVars<T extends DefaultCssVarsTheme, ThemeVars extends Record<string, any>>(theme: T, parserConfig?: {
5
+ prefix?: string;
6
+ shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
7
+ }): {
8
+ vars: ThemeVars;
9
+ generateCssVars: (colorScheme?: string) => {
10
+ css: {
11
+ [x: string]: string | number;
12
+ };
13
+ vars: ThemeVars;
14
+ };
15
+ };
16
+ export default prepareCssVars;
@@ -5,15 +5,18 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
8
10
  var _utils = require("@mui/utils");
9
11
  var _cssVarsParser = _interopRequireDefault(require("./cssVarsParser"));
12
+ const _excluded = ["colorSchemes", "components"],
13
+ _excluded2 = ["light"];
10
14
  function prepareCssVars(theme, parserConfig) {
11
15
  // @ts-ignore - ignore components do not exist
12
16
  const {
13
- colorSchemes = {},
14
- components,
15
- ...otherTheme
16
- } = theme;
17
+ colorSchemes = {}
18
+ } = theme,
19
+ otherTheme = (0, _objectWithoutPropertiesLoose2.default)(theme, _excluded);
17
20
  const {
18
21
  vars: rootVars,
19
22
  css: rootCss,
@@ -22,9 +25,9 @@ function prepareCssVars(theme, parserConfig) {
22
25
  let themeVars = rootVarsWithDefaults;
23
26
  const colorSchemesMap = {};
24
27
  const {
25
- light,
26
- ...otherColorSchemes
27
- } = colorSchemes;
28
+ light
29
+ } = colorSchemes,
30
+ otherColorSchemes = (0, _objectWithoutPropertiesLoose2.default)(colorSchemes, _excluded2);
28
31
  Object.entries(otherColorSchemes || {}).forEach(([key, scheme]) => {
29
32
  const {
30
33
  vars,
@@ -53,16 +56,12 @@ function prepareCssVars(theme, parserConfig) {
53
56
  const generateCssVars = colorScheme => {
54
57
  if (!colorScheme) {
55
58
  return {
56
- css: {
57
- ...rootCss
58
- },
59
+ css: (0, _extends2.default)({}, rootCss),
59
60
  vars: rootVars
60
61
  };
61
62
  }
62
63
  return {
63
- css: {
64
- ...colorSchemesMap[colorScheme].css
65
- },
64
+ css: (0, _extends2.default)({}, colorSchemesMap[colorScheme].css),
66
65
  vars: colorSchemesMap[colorScheme].vars
67
66
  };
68
67
  };
@@ -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 {};