@mui/system 5.11.9 → 5.11.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/Box/Box.spec.d.ts +1 -1
  2. package/CHANGELOG.md +279 -1
  3. package/Container/Container.d.ts +13 -13
  4. package/Container/ContainerProps.d.ts +40 -40
  5. package/Container/containerClasses.d.ts +22 -22
  6. package/Container/createContainer.d.ts +18 -18
  7. package/Stack/Stack.d.ts +13 -13
  8. package/Stack/Stack.js +5 -0
  9. package/Stack/StackProps.d.ts +42 -42
  10. package/Stack/createStack.d.ts +21 -21
  11. package/Stack/index.d.ts +5 -5
  12. package/Stack/stackClasses.d.ts +8 -8
  13. package/Unstable_Grid/Grid.d.ts +12 -12
  14. package/Unstable_Grid/GridProps.d.ts +173 -173
  15. package/Unstable_Grid/createGrid.d.ts +11 -11
  16. package/Unstable_Grid/gridClasses.d.ts +20 -20
  17. package/Unstable_Grid/gridGenerator.d.ts +33 -33
  18. package/Unstable_Grid/index.d.ts +5 -5
  19. package/createBox.spec.d.ts +1 -1
  20. package/createTheme/createSpacing.d.ts +10 -10
  21. package/cssVars/createCssVarsProvider.d.ts +0 -8
  22. package/cssVars/createCssVarsProvider.js +8 -16
  23. package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
  24. package/cssVars/createCssVarsTheme.d.ts +10 -0
  25. package/cssVars/createCssVarsTheme.js +24 -0
  26. package/cssVars/createGetCssVar.d.ts +5 -5
  27. package/cssVars/createGetCssVar.js +1 -1
  28. package/cssVars/cssVarsParser.d.ts +64 -63
  29. package/cssVars/cssVarsParser.js +4 -1
  30. package/cssVars/getInitColorSchemeScript.d.ts +42 -42
  31. package/cssVars/index.d.ts +5 -3
  32. package/cssVars/index.js +15 -1
  33. package/cssVars/prepareCssVars.d.ts +11 -0
  34. package/cssVars/prepareCssVars.js +70 -0
  35. package/cssVars/useCurrentColorScheme.d.ts +53 -53
  36. package/esm/Stack/Stack.js +5 -0
  37. package/esm/cssVars/createCssVarsProvider.js +8 -16
  38. package/esm/cssVars/createCssVarsTheme.js +16 -0
  39. package/esm/cssVars/createGetCssVar.js +1 -1
  40. package/esm/cssVars/cssVarsParser.js +4 -1
  41. package/esm/cssVars/index.js +3 -1
  42. package/esm/cssVars/prepareCssVars.js +62 -0
  43. package/esm/index.js +3 -0
  44. package/index.d.ts +3 -0
  45. package/index.js +25 -1
  46. package/index.spec.d.ts +1 -1
  47. package/legacy/Stack/Stack.js +5 -0
  48. package/legacy/cssVars/createCssVarsProvider.js +15 -21
  49. package/legacy/cssVars/createCssVarsTheme.js +13 -0
  50. package/legacy/cssVars/createGetCssVar.js +1 -1
  51. package/legacy/cssVars/cssVarsParser.js +4 -1
  52. package/legacy/cssVars/index.js +3 -1
  53. package/legacy/cssVars/prepareCssVars.js +59 -0
  54. package/legacy/index.js +4 -1
  55. package/modern/Stack/Stack.js +5 -0
  56. package/modern/cssVars/createCssVarsProvider.js +8 -16
  57. package/modern/cssVars/createCssVarsTheme.js +16 -0
  58. package/modern/cssVars/createGetCssVar.js +1 -1
  59. package/modern/cssVars/cssVarsParser.js +4 -1
  60. package/modern/cssVars/index.js +3 -1
  61. package/modern/cssVars/prepareCssVars.js +62 -0
  62. package/modern/index.js +4 -1
  63. package/package.json +5 -5
  64. package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
@@ -13,12 +13,11 @@ var React = _interopRequireWildcard(require("react"));
13
13
  var _propTypes = _interopRequireDefault(require("prop-types"));
14
14
  var _styledEngine = require("@mui/styled-engine");
15
15
  var _privateTheming = require("@mui/private-theming");
16
- var _cssVarsParser = _interopRequireDefault(require("./cssVarsParser"));
17
16
  var _ThemeProvider = _interopRequireDefault(require("../ThemeProvider"));
18
17
  var _getInitColorSchemeScript = _interopRequireWildcard(require("./getInitColorSchemeScript"));
19
18
  var _useCurrentColorScheme = _interopRequireDefault(require("./useCurrentColorScheme"));
20
19
  var _jsxRuntime = require("react/jsx-runtime");
21
- const _excluded = ["colorSchemes", "components", "cssVarPrefix"];
20
+ const _excluded = ["colorSchemes", "components", "generateCssVars", "cssVarPrefix"];
22
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); }
23
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; }
24
23
  const DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
@@ -32,7 +31,6 @@ function createCssVarsProvider(options) {
32
31
  defaultMode: designSystemMode = 'light',
33
32
  defaultColorScheme: designSystemColorScheme,
34
33
  disableTransitionOnChange: designSystemTransitionOnChange = false,
35
- shouldSkipGeneratingVar: designSystemShouldSkipGeneratingVar,
36
34
  resolveTheme,
37
35
  excludeVariablesFromRoot
38
36
  } = options;
@@ -60,7 +58,6 @@ function createCssVarsProvider(options) {
60
58
  documentNode = typeof document === 'undefined' ? undefined : document,
61
59
  colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
62
60
  colorSchemeSelector = ':root',
63
- shouldSkipGeneratingVar = designSystemShouldSkipGeneratingVar,
64
61
  disableNestedContext = false,
65
62
  disableStyleSheetGeneration = false
66
63
  }) {
@@ -71,6 +68,10 @@ function createCssVarsProvider(options) {
71
68
  const {
72
69
  colorSchemes = {},
73
70
  components = {},
71
+ generateCssVars = () => ({
72
+ vars: {},
73
+ css: {}
74
+ }),
74
75
  cssVarPrefix
75
76
  } = themeProp,
76
77
  restThemeProp = (0, _objectWithoutPropertiesLoose2.default)(themeProp, _excluded);
@@ -128,10 +129,7 @@ function createCssVarsProvider(options) {
128
129
  const {
129
130
  css: rootCss,
130
131
  vars: rootVars
131
- } = (0, _cssVarsParser.default)(restThemeProp, {
132
- prefix: cssVarPrefix,
133
- shouldSkipGeneratingVar
134
- });
132
+ } = generateCssVars();
135
133
 
136
134
  // 3. Start composing the theme object
137
135
  const theme = (0, _extends2.default)({}, restThemeProp, {
@@ -151,10 +149,7 @@ function createCssVarsProvider(options) {
151
149
  const {
152
150
  css,
153
151
  vars
154
- } = (0, _cssVarsParser.default)(scheme, {
155
- prefix: cssVarPrefix,
156
- shouldSkipGeneratingVar
157
- });
152
+ } = generateCssVars(key);
158
153
  theme.vars = (0, _utils.deepmerge)(theme.vars, vars);
159
154
  if (key === calculatedColorScheme) {
160
155
  // 4.1 Merge the selected color scheme to the theme
@@ -193,6 +188,7 @@ function createCssVarsProvider(options) {
193
188
  otherColorSchemesStyleSheet[`${colorSchemeSelector === ':root' ? '' : colorSchemeSelector}[${attribute}="${key}"]`] = css;
194
189
  }
195
190
  });
191
+ theme.vars = (0, _utils.deepmerge)(theme.vars, rootVars);
196
192
 
197
193
  // 5. Declaring effects
198
194
  // 5.1 Updates the selector value to use the current color scheme which tells CSS to use the proper stylesheet.
@@ -317,10 +313,6 @@ function createCssVarsProvider(options) {
317
313
  * The key in the local storage used to store current color scheme.
318
314
  */
319
315
  modeStorageKey: _propTypes.default.string,
320
- /**
321
- * A function to determine if the key, value should be attached as CSS Variable
322
- */
323
- shouldSkipGeneratingVar: _propTypes.default.func,
324
316
  /**
325
317
  * The window that attaches the 'storage' event listener
326
318
  * @default window
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -0,0 +1,10 @@
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>(theme: T): T & {
7
+ vars: ThemeVars;
8
+ generateCssVars: (colorScheme?: string | undefined) => any;
9
+ };
10
+ export default createCssVarsTheme;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
10
+ var _prepareCssVars = _interopRequireDefault(require("./prepareCssVars"));
11
+ const _excluded = ["cssVarPrefix", "shouldSkipGeneratingVar"];
12
+ function createCssVarsTheme(theme) {
13
+ const {
14
+ cssVarPrefix,
15
+ shouldSkipGeneratingVar
16
+ } = theme,
17
+ otherTheme = (0, _objectWithoutPropertiesLoose2.default)(theme, _excluded);
18
+ return (0, _extends2.default)({}, theme, (0, _prepareCssVars.default)(otherTheme, {
19
+ prefix: cssVarPrefix,
20
+ shouldSkipGeneratingVar
21
+ }));
22
+ }
23
+ var _default = createCssVarsTheme;
24
+ exports.default = _default;
@@ -1,5 +1,5 @@
1
- /**
2
- * The benefit of this function is to help developers get CSS var from theme without specifying the whole variable
3
- * and they does not need to remember the prefix (defined once).
4
- */
5
- export default function createGetCssVar<T extends string = string>(prefix?: string): <AdditionalVars extends string = never>(field: T | AdditionalVars, ...fallbacks: (T | AdditionalVars)[]) => string;
1
+ /**
2
+ * The benefit of this function is to help developers get CSS var from theme without specifying the whole variable
3
+ * and they does not need to remember the prefix (defined once).
4
+ */
5
+ export default function createGetCssVar<T extends string = string>(prefix?: string): <AdditionalVars extends string = never>(field: T | AdditionalVars, ...fallbacks: (T | AdditionalVars)[]) => string;
@@ -14,7 +14,7 @@ function createGetCssVar(prefix = '') {
14
14
  return '';
15
15
  }
16
16
  const value = vars[0];
17
- if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))/)) {
17
+ if (typeof value === 'string' && !value.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))|^(-?(\d*\.)?\d+)$|(\d+ \d+ \d+)/)) {
18
18
  return `, var(--${prefix ? `${prefix}-` : ''}${value}${appendVar(...vars.slice(1))})`;
19
19
  }
20
20
  return `, ${value}`;
@@ -1,63 +1,64 @@
1
- type NestedRecord<V = any> = {
2
- [k: string | number]: NestedRecord<V> | V;
3
- };
4
- /**
5
- * This function create an object from keys, value and then assign to target
6
- *
7
- * @param {Object} obj : the target object to be assigned
8
- * @param {string[]} keys
9
- * @param {string | number} value
10
- *
11
- * @example
12
- * const source = {}
13
- * assignNestedKeys(source, ['palette', 'primary'], 'var(--palette-primary)')
14
- * console.log(source) // { palette: { primary: 'var(--palette-primary)' } }
15
- *
16
- * @example
17
- * const source = { palette: { primary: 'var(--palette-primary)' } }
18
- * assignNestedKeys(source, ['palette', 'secondary'], 'var(--palette-secondary)')
19
- * console.log(source) // { palette: { primary: 'var(--palette-primary)', secondary: 'var(--palette-secondary)' } }
20
- */
21
- export declare const assignNestedKeys: <T extends string | Record<string, any> | null | undefined = NestedRecord<any>, Value = any>(obj: T, keys: Array<string>, value: Value, arrayKeys?: Array<string>) => void;
22
- /**
23
- *
24
- * @param {Object} obj : source object
25
- * @param {Function} callback : a function that will be called when
26
- * - the deepest key in source object is reached
27
- * - the value of the deepest key is NOT `undefined` | `null`
28
- *
29
- * @example
30
- * walkObjectDeep({ palette: { primary: { main: '#000000' } } }, console.log)
31
- * // ['palette', 'primary', 'main'] '#000000'
32
- */
33
- export declare const walkObjectDeep: <Value, T = Record<string, any>>(obj: T, callback: (keys: Array<string>, value: Value, arrayKeys: Array<string>) => void, shouldSkipPaths?: ((keys: Array<string>) => boolean) | undefined) => void;
34
- /**
35
- * a function that parse theme and return { css, vars }
36
- *
37
- * @param {Object} theme
38
- * @param {{
39
- * prefix?: string,
40
- * shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean
41
- * }} options.
42
- * `prefix`: The prefix of the generated CSS variables. This function does not change the value.
43
- *
44
- * @returns {{ css: Object, vars: Object }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme).
45
- *
46
- * @example
47
- * const { css, vars } = parser({
48
- * fontSize: 12,
49
- * lineHeight: 1.2,
50
- * palette: { primary: { 500: 'var(--color)' } }
51
- * }, { prefix: 'foo' })
52
- *
53
- * console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--color)' }
54
- * console.log(vars) // { fontSize: 'var(--foo-fontSize)', lineHeight: 'var(--foo-lineHeight)', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
55
- */
56
- export default function cssVarsParser<T extends Record<string, any>>(theme: T, options?: {
57
- prefix?: string;
58
- shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
59
- }): {
60
- css: Record<string, string | number>;
61
- vars: NestedRecord<string>;
62
- };
63
- 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: T, options?: {
57
+ prefix?: string;
58
+ shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
59
+ }): {
60
+ css: Record<string, string | number>;
61
+ vars: NestedRecord<string>;
62
+ varsWithDefaults: {};
63
+ };
64
+ export {};
@@ -115,6 +115,7 @@ function cssVarsParser(theme, options) {
115
115
  } = options || {};
116
116
  const css = {};
117
117
  const vars = {};
118
+ const varsWithDefaults = {};
118
119
  walkObjectDeep(theme, (keys, value, arrayKeys) => {
119
120
  if (typeof value === 'string' || typeof value === 'number') {
120
121
  if (!shouldSkipGeneratingVar || !shouldSkipGeneratingVar(keys, value)) {
@@ -124,6 +125,7 @@ function cssVarsParser(theme, options) {
124
125
  [cssVar]: getCssValue(keys, value)
125
126
  });
126
127
  assignNestedKeys(vars, keys, `var(${cssVar})`, arrayKeys);
128
+ assignNestedKeys(varsWithDefaults, keys, `var(${cssVar}, ${value})`, arrayKeys);
127
129
  }
128
130
  }
129
131
  }, keys => keys[0] === 'vars' // skip 'vars/*' paths
@@ -131,6 +133,7 @@ function cssVarsParser(theme, options) {
131
133
 
132
134
  return {
133
135
  css,
134
- vars
136
+ vars,
137
+ varsWithDefaults
135
138
  };
136
139
  }
@@ -1,42 +1,42 @@
1
- /// <reference types="react" />
2
- export declare const DEFAULT_MODE_STORAGE_KEY = "mode";
3
- export declare const DEFAULT_COLOR_SCHEME_STORAGE_KEY = "color-scheme";
4
- export declare const DEFAULT_ATTRIBUTE = "data-color-scheme";
5
- export interface GetInitColorSchemeScriptOptions {
6
- /**
7
- * The mode to be used for the first visit
8
- * @default 'light'
9
- */
10
- defaultMode?: 'light' | 'dark' | 'system';
11
- /**
12
- * The default color scheme to be used on the light mode
13
- * @default 'light'
14
- */
15
- defaultLightColorScheme?: string;
16
- /**
17
- * The default color scheme to be used on the dark mode
18
- * * @default 'dark'
19
- */
20
- defaultDarkColorScheme?: string;
21
- /**
22
- * The node (provided as string) used to attach the color-scheme attribute
23
- * @default 'document.documentElement'
24
- */
25
- colorSchemeNode?: string;
26
- /**
27
- * localStorage key used to store `mode`
28
- * @default 'mode'
29
- */
30
- modeStorageKey?: string;
31
- /**
32
- * localStorage key used to store `colorScheme`
33
- * @default 'color-scheme'
34
- */
35
- colorSchemeStorageKey?: string;
36
- /**
37
- * DOM attribute for applying color scheme
38
- * @default 'data-color-scheme'
39
- */
40
- attribute?: string;
41
- }
42
- export default function getInitColorSchemeScript(options?: GetInitColorSchemeScriptOptions): JSX.Element;
1
+ /// <reference types="react" />
2
+ export declare const DEFAULT_MODE_STORAGE_KEY = "mode";
3
+ export declare const DEFAULT_COLOR_SCHEME_STORAGE_KEY = "color-scheme";
4
+ export declare const DEFAULT_ATTRIBUTE = "data-color-scheme";
5
+ export interface GetInitColorSchemeScriptOptions {
6
+ /**
7
+ * The mode to be used for the first visit
8
+ * @default 'light'
9
+ */
10
+ defaultMode?: 'light' | 'dark' | 'system';
11
+ /**
12
+ * The default color scheme to be used on the light mode
13
+ * @default 'light'
14
+ */
15
+ defaultLightColorScheme?: string;
16
+ /**
17
+ * The default color scheme to be used on the dark mode
18
+ * * @default 'dark'
19
+ */
20
+ defaultDarkColorScheme?: string;
21
+ /**
22
+ * The node (provided as string) used to attach the color-scheme attribute
23
+ * @default 'document.documentElement'
24
+ */
25
+ colorSchemeNode?: string;
26
+ /**
27
+ * localStorage key used to store `mode`
28
+ * @default 'mode'
29
+ */
30
+ modeStorageKey?: string;
31
+ /**
32
+ * localStorage key used to store `colorScheme`
33
+ * @default 'color-scheme'
34
+ */
35
+ colorSchemeStorageKey?: string;
36
+ /**
37
+ * DOM attribute for applying color scheme
38
+ * @default 'data-color-scheme'
39
+ */
40
+ attribute?: string;
41
+ }
42
+ export default function getInitColorSchemeScript(options?: GetInitColorSchemeScriptOptions): JSX.Element;
@@ -1,3 +1,5 @@
1
- export { default } from './createCssVarsProvider';
2
- export type { CreateCssVarsProviderResult, CssVarsProviderConfig, ColorSchemeContextValue, } from './createCssVarsProvider';
3
- export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
1
+ export { default } from './createCssVarsProvider';
2
+ export type { CreateCssVarsProviderResult, CssVarsProviderConfig, ColorSchemeContextValue, } from './createCssVarsProvider';
3
+ export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
4
+ export { default as prepareCssVars } from './prepareCssVars';
5
+ export { default as createCssVarsTheme } from './createCssVarsTheme';
package/cssVars/index.js CHANGED
@@ -4,6 +4,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
+ Object.defineProperty(exports, "createCssVarsTheme", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _createCssVarsTheme.default;
11
+ }
12
+ });
7
13
  Object.defineProperty(exports, "default", {
8
14
  enumerable: true,
9
15
  get: function () {
@@ -16,5 +22,13 @@ Object.defineProperty(exports, "getInitColorSchemeScript", {
16
22
  return _getInitColorSchemeScript.default;
17
23
  }
18
24
  });
25
+ Object.defineProperty(exports, "prepareCssVars", {
26
+ enumerable: true,
27
+ get: function () {
28
+ return _prepareCssVars.default;
29
+ }
30
+ });
19
31
  var _createCssVarsProvider = _interopRequireDefault(require("./createCssVarsProvider"));
20
- var _getInitColorSchemeScript = _interopRequireDefault(require("./getInitColorSchemeScript"));
32
+ var _getInitColorSchemeScript = _interopRequireDefault(require("./getInitColorSchemeScript"));
33
+ var _prepareCssVars = _interopRequireDefault(require("./prepareCssVars"));
34
+ var _createCssVarsTheme = _interopRequireDefault(require("./createCssVarsTheme"));
@@ -0,0 +1,11 @@
1
+ export interface DefaultCssVarsTheme {
2
+ colorSchemes: Record<string, any>;
3
+ }
4
+ declare function prepareCssVars<T extends DefaultCssVarsTheme, ThemeVars>(theme: T, parserConfig?: {
5
+ prefix?: string;
6
+ shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean;
7
+ }): {
8
+ vars: ThemeVars;
9
+ generateCssVars: (colorScheme?: string) => any;
10
+ };
11
+ export default prepareCssVars;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
9
+ var _utils = require("@mui/utils");
10
+ var _cssVarsParser = _interopRequireDefault(require("./cssVarsParser"));
11
+ const _excluded = ["colorSchemes", "components"],
12
+ _excluded2 = ["light"];
13
+ function prepareCssVars(theme, parserConfig) {
14
+ // @ts-ignore - ignore components do not exist
15
+ const {
16
+ colorSchemes = {}
17
+ } = theme,
18
+ otherTheme = (0, _objectWithoutPropertiesLoose2.default)(theme, _excluded);
19
+ const {
20
+ vars: rootVars,
21
+ css: rootCss,
22
+ varsWithDefaults: rootVarsWithDefaults
23
+ } = (0, _cssVarsParser.default)(otherTheme, parserConfig);
24
+ let themeVars = rootVarsWithDefaults;
25
+ const colorSchemesMap = {};
26
+ const {
27
+ light
28
+ } = colorSchemes,
29
+ otherColorSchemes = (0, _objectWithoutPropertiesLoose2.default)(colorSchemes, _excluded2);
30
+ Object.entries(otherColorSchemes || {}).forEach(([key, scheme]) => {
31
+ const {
32
+ vars,
33
+ css,
34
+ varsWithDefaults
35
+ } = (0, _cssVarsParser.default)(scheme, parserConfig);
36
+ themeVars = (0, _utils.deepmerge)(themeVars, varsWithDefaults);
37
+ colorSchemesMap[key] = {
38
+ css,
39
+ vars
40
+ };
41
+ });
42
+ if (light) {
43
+ // light color scheme vars should be merged last to set as default
44
+ const {
45
+ css,
46
+ vars,
47
+ varsWithDefaults
48
+ } = (0, _cssVarsParser.default)(light, parserConfig);
49
+ themeVars = (0, _utils.deepmerge)(themeVars, varsWithDefaults);
50
+ colorSchemesMap.light = {
51
+ css,
52
+ vars
53
+ };
54
+ }
55
+ const generateCssVars = colorScheme => {
56
+ if (!colorScheme) {
57
+ return {
58
+ css: rootCss,
59
+ vars: rootVars
60
+ };
61
+ }
62
+ return colorSchemesMap[colorScheme];
63
+ };
64
+ return {
65
+ vars: themeVars,
66
+ generateCssVars
67
+ };
68
+ }
69
+ var _default = prepareCssVars;
70
+ exports.default = _default;
@@ -1,53 +1,53 @@
1
- export type Mode = 'light' | 'dark' | 'system';
2
- export type SystemMode = Exclude<Mode, 'system'>;
3
- export interface State<SupportedColorScheme extends string> {
4
- /**
5
- * User selected mode.
6
- * Note: on the server, mode is always undefined
7
- */
8
- mode: Mode | undefined;
9
- /**
10
- * Only valid if `mode: 'system'`, either 'light' | 'dark'.
11
- */
12
- systemMode: SystemMode | undefined;
13
- /**
14
- * The color scheme for the light mode.
15
- */
16
- lightColorScheme: SupportedColorScheme;
17
- /**
18
- * The color scheme for the dark mode.
19
- */
20
- darkColorScheme: SupportedColorScheme;
21
- }
22
- export type Result<SupportedColorScheme extends string> = State<SupportedColorScheme> & {
23
- /**
24
- * The current application color scheme. It is always `undefined` on the server.
25
- */
26
- colorScheme: SupportedColorScheme | undefined;
27
- /**
28
- * `mode` is saved to internal state and localStorage
29
- * If `mode` is null, it will be reset to the defaultMode
30
- */
31
- setMode: (mode: Mode | null) => void;
32
- /**
33
- * `colorScheme` is saved to internal state and localStorage
34
- * If `colorScheme` is null, it will be reset to the defaultColorScheme (light | dark)
35
- */
36
- setColorScheme: (colorScheme: SupportedColorScheme | Partial<{
37
- light: SupportedColorScheme | null;
38
- dark: SupportedColorScheme | null;
39
- }> | null) => void;
40
- };
41
- export declare function getSystemMode(mode: undefined | string): SystemMode | undefined;
42
- export declare function getColorScheme<SupportedColorScheme extends string>(state: State<SupportedColorScheme>): SupportedColorScheme | undefined;
43
- interface UseCurrentColoSchemeOptions<SupportedColorScheme extends string> {
44
- defaultLightColorScheme: SupportedColorScheme;
45
- defaultDarkColorScheme: SupportedColorScheme;
46
- supportedColorSchemes: Array<SupportedColorScheme>;
47
- defaultMode?: Mode;
48
- modeStorageKey?: string;
49
- colorSchemeStorageKey?: string;
50
- storageWindow?: Window | null;
51
- }
52
- export default function useCurrentColorScheme<SupportedColorScheme extends string>(options: UseCurrentColoSchemeOptions<SupportedColorScheme>): Result<SupportedColorScheme>;
53
- export {};
1
+ export type Mode = 'light' | 'dark' | 'system';
2
+ export type SystemMode = Exclude<Mode, 'system'>;
3
+ export interface State<SupportedColorScheme extends string> {
4
+ /**
5
+ * User selected mode.
6
+ * Note: on the server, mode is always undefined
7
+ */
8
+ mode: Mode | undefined;
9
+ /**
10
+ * Only valid if `mode: 'system'`, either 'light' | 'dark'.
11
+ */
12
+ systemMode: SystemMode | undefined;
13
+ /**
14
+ * The color scheme for the light mode.
15
+ */
16
+ lightColorScheme: SupportedColorScheme;
17
+ /**
18
+ * The color scheme for the dark mode.
19
+ */
20
+ darkColorScheme: SupportedColorScheme;
21
+ }
22
+ export type Result<SupportedColorScheme extends string> = State<SupportedColorScheme> & {
23
+ /**
24
+ * The current application color scheme. It is always `undefined` on the server.
25
+ */
26
+ colorScheme: SupportedColorScheme | undefined;
27
+ /**
28
+ * `mode` is saved to internal state and localStorage
29
+ * If `mode` is null, it will be reset to the defaultMode
30
+ */
31
+ setMode: (mode: Mode | null) => void;
32
+ /**
33
+ * `colorScheme` is saved to internal state and localStorage
34
+ * If `colorScheme` is null, it will be reset to the defaultColorScheme (light | dark)
35
+ */
36
+ setColorScheme: (colorScheme: SupportedColorScheme | Partial<{
37
+ light: SupportedColorScheme | null;
38
+ dark: SupportedColorScheme | null;
39
+ }> | null) => void;
40
+ };
41
+ export declare function getSystemMode(mode: undefined | string): SystemMode | undefined;
42
+ export declare function getColorScheme<SupportedColorScheme extends string>(state: State<SupportedColorScheme>): SupportedColorScheme | undefined;
43
+ interface UseCurrentColoSchemeOptions<SupportedColorScheme extends string> {
44
+ defaultLightColorScheme: SupportedColorScheme;
45
+ defaultDarkColorScheme: SupportedColorScheme;
46
+ supportedColorSchemes: Array<SupportedColorScheme>;
47
+ defaultMode?: Mode;
48
+ modeStorageKey?: string;
49
+ colorSchemeStorageKey?: string;
50
+ storageWindow?: Window | null;
51
+ }
52
+ export default function useCurrentColorScheme<SupportedColorScheme extends string>(options: UseCurrentColoSchemeOptions<SupportedColorScheme>): Result<SupportedColorScheme>;
53
+ export {};
@@ -21,6 +21,11 @@ process.env.NODE_ENV !== "production" ? Stack.propTypes /* remove-proptypes */ =
21
21
  * The content of the component.
22
22
  */
23
23
  children: PropTypes.node,
24
+ /**
25
+ * The component used for the root node.
26
+ * Either a string to use a HTML element or a component.
27
+ */
28
+ component: PropTypes.elementType,
24
29
  /**
25
30
  * Defines the `flex-direction` style property.
26
31
  * It is applied for all screen sizes.