@mui/system 5.8.6 → 5.8.7

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 (37) hide show
  1. package/Box/Box.spec.d.ts +1 -1
  2. package/CHANGELOG.md +51 -0
  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/createBox.spec.d.ts +1 -1
  8. package/createTheme/createSpacing.d.ts +10 -10
  9. package/cssVars/createCssVarsProvider.d.ts +13 -18
  10. package/cssVars/createCssVarsProvider.js +11 -16
  11. package/cssVars/createCssVarsProvider.spec.d.ts +1 -1
  12. package/cssVars/createGetCssVar.d.ts +5 -5
  13. package/cssVars/createGetCssVar.js +2 -2
  14. package/cssVars/cssVarsParser.d.ts +65 -70
  15. package/cssVars/cssVarsParser.js +4 -19
  16. package/cssVars/getInitColorSchemeScript.d.ts +45 -45
  17. package/cssVars/index.d.ts +3 -2
  18. package/cssVars/index.js +9 -1
  19. package/cssVars/useCurrentColorScheme.d.ts +53 -53
  20. package/esm/cssVars/createCssVarsProvider.js +11 -15
  21. package/esm/cssVars/createGetCssVar.js +2 -2
  22. package/esm/cssVars/cssVarsParser.js +4 -19
  23. package/esm/cssVars/index.js +2 -1
  24. package/index.js +1 -1
  25. package/index.spec.d.ts +1 -1
  26. package/legacy/cssVars/createCssVarsProvider.js +11 -16
  27. package/legacy/cssVars/createGetCssVar.js +3 -3
  28. package/legacy/cssVars/cssVarsParser.js +4 -20
  29. package/legacy/cssVars/index.js +2 -1
  30. package/legacy/index.js +1 -1
  31. package/modern/cssVars/createCssVarsProvider.js +11 -15
  32. package/modern/cssVars/createGetCssVar.js +2 -2
  33. package/modern/cssVars/cssVarsParser.js +4 -19
  34. package/modern/cssVars/index.js +2 -1
  35. package/modern/index.js +1 -1
  36. package/package.json +3 -3
  37. package/styleFunctionSx/styleFunctionSx.spec.d.ts +1 -1
@@ -102,13 +102,9 @@ const getCssValue = (keys, value) => {
102
102
  * @param {Object} theme
103
103
  * @param {{
104
104
  * prefix?: string,
105
- * basePrefix?: string,
106
105
  * shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean
107
106
  * }} options.
108
- * `basePrefix`: defined by design system.
109
- * `prefix`: defined by application
110
- *
111
- * the CSS variable value will be adjusted based on the provided `basePrefix` & `prefix` which can be found in `parsedTheme`.
107
+ * `prefix`: The prefix of the generated CSS variables. This function does not change the value.
112
108
  *
113
109
  * @returns {{ css: Object, vars: Object, parsedTheme: typeof theme }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme), and `parsedTheme` is the cloned version of theme.
114
110
  *
@@ -119,16 +115,15 @@ const getCssValue = (keys, value) => {
119
115
  * palette: { primary: { 500: 'var(--color)' } }
120
116
  * }, { prefix: 'foo' })
121
117
  *
122
- * console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--foo-color)' }
123
- * console.log(vars) // { fontSize: '--foo-fontSize', lineHeight: '--foo-lineHeight', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
124
- * console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--foo-color)' } } }
118
+ * console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--color)' }
119
+ * console.log(vars) // { fontSize: 'var(--foo-fontSize)', lineHeight: 'var(--foo-lineHeight)', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
120
+ * console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--color)' } } }
125
121
  */
126
122
 
127
123
 
128
124
  function cssVarsParser(theme, options) {
129
125
  const {
130
126
  prefix,
131
- basePrefix = '',
132
127
  shouldSkipGeneratingVar
133
128
  } = options || {};
134
129
  const css = {};
@@ -136,16 +131,6 @@ function cssVarsParser(theme, options) {
136
131
  const parsedTheme = {};
137
132
  walkObjectDeep(theme, (keys, value, arrayKeys) => {
138
133
  if (typeof value === 'string' || typeof value === 'number') {
139
- if (typeof value === 'string' && value.match(/var\(\s*--/)) {
140
- // for CSS variable, apply prefix or remove basePrefix from the variable
141
- if (!basePrefix && prefix) {
142
- value = value.replace(/var\(\s*--/g, `var(--${prefix}-`);
143
- } else {
144
- value = prefix ? value.replace(new RegExp(`var\\(\\s*--${basePrefix}`, 'g'), `var(--${prefix}`) // removing spaces
145
- : value.replace(new RegExp(`var\\(\\s*--${basePrefix}-`, 'g'), 'var(--');
146
- }
147
- }
148
-
149
134
  if (!shouldSkipGeneratingVar || shouldSkipGeneratingVar && !shouldSkipGeneratingVar(keys, value)) {
150
135
  // only create css & var if `shouldSkipGeneratingVar` return false
151
136
  const cssVar = `--${prefix ? `${prefix}-` : ''}${keys.join('-')}`;
@@ -1,45 +1,45 @@
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
- * Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
8
- * @default true
9
- */
10
- enableColorScheme?: boolean;
11
- /**
12
- * If `true`, the initial color scheme is set to the user's prefers-color-scheme mode
13
- * @default false
14
- */
15
- enableSystem?: boolean;
16
- /**
17
- * The default color scheme to be used on the light mode
18
- */
19
- defaultLightColorScheme?: string;
20
- /**
21
- * The default color scheme to be used on the dark mode
22
- */
23
- defaultDarkColorScheme?: string;
24
- /**
25
- * The node (provided as string) used to attach the color-scheme attribute
26
- * @default 'document.documentElement'
27
- */
28
- colorSchemeNode?: string;
29
- /**
30
- * localStorage key used to store `mode`
31
- * @default 'mode'
32
- */
33
- modeStorageKey?: string;
34
- /**
35
- * localStorage key used to store `colorScheme`
36
- * @default 'color-scheme'
37
- */
38
- colorSchemeStorageKey?: string;
39
- /**
40
- * DOM attribute for applying color scheme
41
- * @default 'data-color-scheme'
42
- */
43
- attribute?: string;
44
- }
45
- 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
+ * Indicate to the browser which color scheme is used (light or dark) for rendering built-in UI
8
+ * @default true
9
+ */
10
+ enableColorScheme?: boolean;
11
+ /**
12
+ * If `true`, the initial color scheme is set to the user's prefers-color-scheme mode
13
+ * @default false
14
+ */
15
+ enableSystem?: boolean;
16
+ /**
17
+ * The default color scheme to be used on the light mode
18
+ */
19
+ defaultLightColorScheme?: string;
20
+ /**
21
+ * The default color scheme to be used on the dark mode
22
+ */
23
+ defaultDarkColorScheme?: string;
24
+ /**
25
+ * The node (provided as string) used to attach the color-scheme attribute
26
+ * @default 'document.documentElement'
27
+ */
28
+ colorSchemeNode?: string;
29
+ /**
30
+ * localStorage key used to store `mode`
31
+ * @default 'mode'
32
+ */
33
+ modeStorageKey?: string;
34
+ /**
35
+ * localStorage key used to store `colorScheme`
36
+ * @default 'color-scheme'
37
+ */
38
+ colorSchemeStorageKey?: string;
39
+ /**
40
+ * DOM attribute for applying color scheme
41
+ * @default 'data-color-scheme'
42
+ */
43
+ attribute?: string;
44
+ }
45
+ export default function getInitColorSchemeScript(options?: GetInitColorSchemeScriptOptions): JSX.Element;
@@ -1,2 +1,3 @@
1
- export { default } from './createCssVarsProvider';
2
- export type { CreateCssVarsProviderResult } from './createCssVarsProvider';
1
+ export { default } from './createCssVarsProvider';
2
+ export type { CreateCssVarsProviderResult, CssVarsProviderConfig, ColorSchemeContextValue, } from './createCssVarsProvider';
3
+ export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
package/cssVars/index.js CHANGED
@@ -11,5 +11,13 @@ Object.defineProperty(exports, "default", {
11
11
  return _createCssVarsProvider.default;
12
12
  }
13
13
  });
14
+ Object.defineProperty(exports, "getInitColorSchemeScript", {
15
+ enumerable: true,
16
+ get: function () {
17
+ return _getInitColorSchemeScript.default;
18
+ }
19
+ });
20
+
21
+ var _createCssVarsProvider = _interopRequireDefault(require("./createCssVarsProvider"));
14
22
 
15
- var _createCssVarsProvider = _interopRequireDefault(require("./createCssVarsProvider"));
23
+ var _getInitColorSchemeScript = _interopRequireDefault(require("./getInitColorSchemeScript"));
@@ -1,53 +1,53 @@
1
- export declare type Mode = 'light' | 'dark' | 'system';
2
- export declare 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 declare 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 declare type Mode = 'light' | 'dark' | 'system';
2
+ export declare 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 declare 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,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
3
  import { formatMuiErrorMessage as _formatMuiErrorMessage } from "@mui/utils";
4
- const _excluded = ["colorSchemes", "components"];
4
+ const _excluded = ["colorSchemes", "components", "cssVarPrefix"];
5
5
  import * as React from 'react';
6
6
  import PropTypes from 'prop-types';
7
7
  import { deepmerge, unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
@@ -10,7 +10,6 @@ import cssVarsParser from './cssVarsParser';
10
10
  import ThemeProvider from '../ThemeProvider';
11
11
  import systemGetInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_COLOR_SCHEME_STORAGE_KEY, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
12
12
  import useCurrentColorScheme from './useCurrentColorScheme';
13
- import createGetCssVar from './createGetCssVar';
14
13
  import { jsx as _jsx } from "react/jsx-runtime";
15
14
  import { jsxs as _jsxs } from "react/jsx-runtime";
16
15
  export const DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
@@ -24,8 +23,7 @@ export default function createCssVarsProvider(options) {
24
23
  defaultColorScheme: designSystemColorScheme,
25
24
  disableTransitionOnChange: designSystemTransitionOnChange = false,
26
25
  enableColorScheme: designSystemEnableColorScheme = true,
27
- prefix: designSystemPrefix = '',
28
- shouldSkipGeneratingVar,
26
+ shouldSkipGeneratingVar: designSystemShouldSkipGeneratingVar,
29
27
  resolveTheme
30
28
  } = options;
31
29
 
@@ -48,7 +46,6 @@ export default function createCssVarsProvider(options) {
48
46
  function CssVarsProvider({
49
47
  children,
50
48
  theme: themeProp = defaultTheme,
51
- prefix = designSystemPrefix,
52
49
  modeStorageKey = defaultModeStorageKey,
53
50
  colorSchemeStorageKey = defaultColorSchemeStorageKey,
54
51
  attribute = defaultAttribute,
@@ -59,13 +56,15 @@ export default function createCssVarsProvider(options) {
59
56
  storageWindow = typeof window === 'undefined' ? undefined : window,
60
57
  documentNode = typeof document === 'undefined' ? undefined : document,
61
58
  colorSchemeNode = typeof document === 'undefined' ? undefined : document.documentElement,
62
- colorSchemeSelector = ':root'
59
+ colorSchemeSelector = ':root',
60
+ shouldSkipGeneratingVar = designSystemShouldSkipGeneratingVar
63
61
  }) {
64
62
  const hasMounted = React.useRef(false);
65
63
 
66
64
  const {
67
65
  colorSchemes = {},
68
- components = {}
66
+ components = {},
67
+ cssVarPrefix
69
68
  } = themeProp,
70
69
  restThemeProp = _objectWithoutPropertiesLoose(themeProp, _excluded);
71
70
 
@@ -110,16 +109,14 @@ export default function createCssVarsProvider(options) {
110
109
  vars: rootVars,
111
110
  parsedTheme
112
111
  } = cssVarsParser(theme, {
113
- prefix,
114
- basePrefix: designSystemPrefix,
112
+ prefix: cssVarPrefix,
115
113
  shouldSkipGeneratingVar
116
114
  });
117
115
  theme = _extends({}, parsedTheme, {
118
116
  components,
119
117
  colorSchemes,
120
- prefix,
118
+ cssVarPrefix,
121
119
  vars: rootVars,
122
- getCssVar: createGetCssVar(prefix),
123
120
  getColorSchemeSelector: targetColorScheme => `[${attribute}="${targetColorScheme}"] &`
124
121
  });
125
122
  const defaultColorSchemeStyleSheet = {};
@@ -130,8 +127,7 @@ export default function createCssVarsProvider(options) {
130
127
  vars,
131
128
  parsedTheme: parsedScheme
132
129
  } = cssVarsParser(scheme, {
133
- prefix,
134
- basePrefix: designSystemPrefix,
130
+ prefix: cssVarPrefix,
135
131
  shouldSkipGeneratingVar
136
132
  });
137
133
  theme.vars = deepmerge(theme.vars, vars);
@@ -295,9 +291,9 @@ export default function createCssVarsProvider(options) {
295
291
  modeStorageKey: PropTypes.string,
296
292
 
297
293
  /**
298
- * CSS variable prefix.
294
+ * A function to determine if the key, value should be attached as CSS Variable
299
295
  */
300
- prefix: PropTypes.string,
296
+ shouldSkipGeneratingVar: PropTypes.func,
301
297
 
302
298
  /**
303
299
  * The window that attaches the 'storage' event listener
@@ -18,8 +18,8 @@ export default function createGetCssVar(prefix = '') {
18
18
  } // AdditionalVars makes `getCssVar` less strict, so it can be use like this `getCssVar('non-mui-variable')` without type error.
19
19
 
20
20
 
21
- const getCssVar = (field, ...vars) => {
22
- return `var(--${prefix ? `${prefix}-` : ''}${field}${appendVar(...vars)})`;
21
+ const getCssVar = (field, ...fallbacks) => {
22
+ return `var(--${prefix ? `${prefix}-` : ''}${field}${appendVar(...fallbacks)})`;
23
23
  };
24
24
 
25
25
  return getCssVar;
@@ -88,13 +88,9 @@ const getCssValue = (keys, value) => {
88
88
  * @param {Object} theme
89
89
  * @param {{
90
90
  * prefix?: string,
91
- * basePrefix?: string,
92
91
  * shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean
93
92
  * }} options.
94
- * `basePrefix`: defined by design system.
95
- * `prefix`: defined by application
96
- *
97
- * the CSS variable value will be adjusted based on the provided `basePrefix` & `prefix` which can be found in `parsedTheme`.
93
+ * `prefix`: The prefix of the generated CSS variables. This function does not change the value.
98
94
  *
99
95
  * @returns {{ css: Object, vars: Object, parsedTheme: typeof theme }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme), and `parsedTheme` is the cloned version of theme.
100
96
  *
@@ -105,16 +101,15 @@ const getCssValue = (keys, value) => {
105
101
  * palette: { primary: { 500: 'var(--color)' } }
106
102
  * }, { prefix: 'foo' })
107
103
  *
108
- * console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--foo-color)' }
109
- * console.log(vars) // { fontSize: '--foo-fontSize', lineHeight: '--foo-lineHeight', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
110
- * console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--foo-color)' } } }
104
+ * console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--color)' }
105
+ * console.log(vars) // { fontSize: 'var(--foo-fontSize)', lineHeight: 'var(--foo-lineHeight)', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
106
+ * console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--color)' } } }
111
107
  */
112
108
 
113
109
 
114
110
  export default function cssVarsParser(theme, options) {
115
111
  const {
116
112
  prefix,
117
- basePrefix = '',
118
113
  shouldSkipGeneratingVar
119
114
  } = options || {};
120
115
  const css = {};
@@ -122,16 +117,6 @@ export default function cssVarsParser(theme, options) {
122
117
  const parsedTheme = {};
123
118
  walkObjectDeep(theme, (keys, value, arrayKeys) => {
124
119
  if (typeof value === 'string' || typeof value === 'number') {
125
- if (typeof value === 'string' && value.match(/var\(\s*--/)) {
126
- // for CSS variable, apply prefix or remove basePrefix from the variable
127
- if (!basePrefix && prefix) {
128
- value = value.replace(/var\(\s*--/g, `var(--${prefix}-`);
129
- } else {
130
- value = prefix ? value.replace(new RegExp(`var\\(\\s*--${basePrefix}`, 'g'), `var(--${prefix}`) // removing spaces
131
- : value.replace(new RegExp(`var\\(\\s*--${basePrefix}-`, 'g'), 'var(--');
132
- }
133
- }
134
-
135
120
  if (!shouldSkipGeneratingVar || shouldSkipGeneratingVar && !shouldSkipGeneratingVar(keys, value)) {
136
121
  // only create css & var if `shouldSkipGeneratingVar` return false
137
122
  const cssVar = `--${prefix ? `${prefix}-` : ''}${keys.join('-')}`;
@@ -1 +1,2 @@
1
- export { default } from './createCssVarsProvider';
1
+ export { default } from './createCssVarsProvider';
2
+ export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.8.6
1
+ /** @license MUI v5.8.7
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
package/index.spec.d.ts CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -12,7 +12,6 @@ import cssVarsParser from './cssVarsParser';
12
12
  import ThemeProvider from '../ThemeProvider';
13
13
  import systemGetInitColorSchemeScript, { DEFAULT_ATTRIBUTE, DEFAULT_COLOR_SCHEME_STORAGE_KEY, DEFAULT_MODE_STORAGE_KEY } from './getInitColorSchemeScript';
14
14
  import useCurrentColorScheme from './useCurrentColorScheme';
15
- import createGetCssVar from './createGetCssVar';
16
15
  import { jsx as _jsx } from "react/jsx-runtime";
17
16
  import { jsxs as _jsxs } from "react/jsx-runtime";
18
17
  export var DISABLE_CSS_TRANSITION = '*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}';
@@ -32,9 +31,7 @@ export default function createCssVarsProvider(options) {
32
31
  designSystemTransitionOnChange = _options$disableTrans === void 0 ? false : _options$disableTrans,
33
32
  _options$enableColorS = options.enableColorScheme,
34
33
  designSystemEnableColorScheme = _options$enableColorS === void 0 ? true : _options$enableColorS,
35
- _options$prefix = options.prefix,
36
- designSystemPrefix = _options$prefix === void 0 ? '' : _options$prefix,
37
- shouldSkipGeneratingVar = options.shouldSkipGeneratingVar,
34
+ designSystemShouldSkipGeneratingVar = options.shouldSkipGeneratingVar,
38
35
  resolveTheme = options.resolveTheme;
39
36
 
40
37
  if (!defaultTheme.colorSchemes || typeof designSystemColorScheme === 'string' && !defaultTheme.colorSchemes[designSystemColorScheme] || _typeof(designSystemColorScheme) === 'object' && !defaultTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.light] || _typeof(designSystemColorScheme) === 'object' && !defaultTheme.colorSchemes[designSystemColorScheme == null ? void 0 : designSystemColorScheme.dark]) {
@@ -57,8 +54,6 @@ export default function createCssVarsProvider(options) {
57
54
  var children = _ref.children,
58
55
  _ref$theme = _ref.theme,
59
56
  themeProp = _ref$theme === void 0 ? defaultTheme : _ref$theme,
60
- _ref$prefix = _ref.prefix,
61
- prefix = _ref$prefix === void 0 ? designSystemPrefix : _ref$prefix,
62
57
  _ref$modeStorageKey = _ref.modeStorageKey,
63
58
  modeStorageKey = _ref$modeStorageKey === void 0 ? defaultModeStorageKey : _ref$modeStorageKey,
64
59
  _ref$colorSchemeStora = _ref.colorSchemeStorageKey,
@@ -80,14 +75,17 @@ export default function createCssVarsProvider(options) {
80
75
  _ref$colorSchemeNode = _ref.colorSchemeNode,
81
76
  colorSchemeNode = _ref$colorSchemeNode === void 0 ? typeof document === 'undefined' ? undefined : document.documentElement : _ref$colorSchemeNode,
82
77
  _ref$colorSchemeSelec = _ref.colorSchemeSelector,
83
- colorSchemeSelector = _ref$colorSchemeSelec === void 0 ? ':root' : _ref$colorSchemeSelec;
78
+ colorSchemeSelector = _ref$colorSchemeSelec === void 0 ? ':root' : _ref$colorSchemeSelec,
79
+ _ref$shouldSkipGenera = _ref.shouldSkipGeneratingVar,
80
+ shouldSkipGeneratingVar = _ref$shouldSkipGenera === void 0 ? designSystemShouldSkipGeneratingVar : _ref$shouldSkipGenera;
84
81
  var hasMounted = React.useRef(false);
85
82
 
86
83
  var _themeProp$colorSchem = themeProp.colorSchemes,
87
84
  colorSchemes = _themeProp$colorSchem === void 0 ? {} : _themeProp$colorSchem,
88
85
  _themeProp$components = themeProp.components,
89
86
  components = _themeProp$components === void 0 ? {} : _themeProp$components,
90
- restThemeProp = _objectWithoutProperties(themeProp, ["colorSchemes", "components"]);
87
+ cssVarPrefix = themeProp.cssVarPrefix,
88
+ restThemeProp = _objectWithoutProperties(themeProp, ["colorSchemes", "components", "cssVarPrefix"]);
91
89
 
92
90
  var allColorSchemes = Object.keys(colorSchemes);
93
91
  var defaultLightColorScheme = typeof defaultColorScheme === 'string' ? defaultColorScheme : defaultColorScheme.light;
@@ -127,8 +125,7 @@ export default function createCssVarsProvider(options) {
127
125
  var theme = restThemeProp;
128
126
 
129
127
  var _cssVarsParser = cssVarsParser(theme, {
130
- prefix: prefix,
131
- basePrefix: designSystemPrefix,
128
+ prefix: cssVarPrefix,
132
129
  shouldSkipGeneratingVar: shouldSkipGeneratingVar
133
130
  }),
134
131
  rootCss = _cssVarsParser.css,
@@ -138,9 +135,8 @@ export default function createCssVarsProvider(options) {
138
135
  theme = _extends({}, parsedTheme, {
139
136
  components: components,
140
137
  colorSchemes: colorSchemes,
141
- prefix: prefix,
138
+ cssVarPrefix: cssVarPrefix,
142
139
  vars: rootVars,
143
- getCssVar: createGetCssVar(prefix),
144
140
  getColorSchemeSelector: function getColorSchemeSelector(targetColorScheme) {
145
141
  return "[".concat(attribute, "=\"").concat(targetColorScheme, "\"] &");
146
142
  }
@@ -153,8 +149,7 @@ export default function createCssVarsProvider(options) {
153
149
  scheme = _ref3[1];
154
150
 
155
151
  var _cssVarsParser2 = cssVarsParser(scheme, {
156
- prefix: prefix,
157
- basePrefix: designSystemPrefix,
152
+ prefix: cssVarPrefix,
158
153
  shouldSkipGeneratingVar: shouldSkipGeneratingVar
159
154
  }),
160
155
  css = _cssVarsParser2.css,
@@ -322,9 +317,9 @@ export default function createCssVarsProvider(options) {
322
317
  modeStorageKey: PropTypes.string,
323
318
 
324
319
  /**
325
- * CSS variable prefix.
320
+ * A function to determine if the key, value should be attached as CSS Variable
326
321
  */
327
- prefix: PropTypes.string,
322
+ shouldSkipGeneratingVar: PropTypes.func,
328
323
 
329
324
  /**
330
325
  * The window that attaches the 'storage' event listener
@@ -27,11 +27,11 @@ export default function createGetCssVar() {
27
27
 
28
28
 
29
29
  var getCssVar = function getCssVar(field) {
30
- for (var _len2 = arguments.length, vars = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
31
- vars[_key2 - 1] = arguments[_key2];
30
+ for (var _len2 = arguments.length, fallbacks = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
31
+ fallbacks[_key2 - 1] = arguments[_key2];
32
32
  }
33
33
 
34
- return "var(--".concat(prefix ? "".concat(prefix, "-") : '').concat(field).concat(appendVar.apply(void 0, vars), ")");
34
+ return "var(--".concat(prefix ? "".concat(prefix, "-") : '').concat(field).concat(appendVar.apply(void 0, fallbacks), ")");
35
35
  };
36
36
 
37
37
  return getCssVar;
@@ -103,13 +103,9 @@ var getCssValue = function getCssValue(keys, value) {
103
103
  * @param {Object} theme
104
104
  * @param {{
105
105
  * prefix?: string,
106
- * basePrefix?: string,
107
106
  * shouldSkipGeneratingVar?: (objectPathKeys: Array<string>, value: string | number) => boolean
108
107
  * }} options.
109
- * `basePrefix`: defined by design system.
110
- * `prefix`: defined by application
111
- *
112
- * the CSS variable value will be adjusted based on the provided `basePrefix` & `prefix` which can be found in `parsedTheme`.
108
+ * `prefix`: The prefix of the generated CSS variables. This function does not change the value.
113
109
  *
114
110
  * @returns {{ css: Object, vars: Object, parsedTheme: typeof theme }} `css` is the stylesheet, `vars` is an object to get css variable (same structure as theme), and `parsedTheme` is the cloned version of theme.
115
111
  *
@@ -120,17 +116,15 @@ var getCssValue = function getCssValue(keys, value) {
120
116
  * palette: { primary: { 500: 'var(--color)' } }
121
117
  * }, { prefix: 'foo' })
122
118
  *
123
- * console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--foo-color)' }
124
- * console.log(vars) // { fontSize: '--foo-fontSize', lineHeight: '--foo-lineHeight', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
125
- * console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--foo-color)' } } }
119
+ * console.log(css) // { '--foo-fontSize': '12px', '--foo-lineHeight': 1.2, '--foo-palette-primary-500': 'var(--color)' }
120
+ * console.log(vars) // { fontSize: 'var(--foo-fontSize)', lineHeight: 'var(--foo-lineHeight)', palette: { primary: { 500: 'var(--foo-palette-primary-500)' } } }
121
+ * console.log(parsedTheme) // { fontSize: 12, lineHeight: 1.2, palette: { primary: { 500: 'var(--color)' } } }
126
122
  */
127
123
 
128
124
 
129
125
  export default function cssVarsParser(theme, options) {
130
126
  var _ref3 = options || {},
131
127
  prefix = _ref3.prefix,
132
- _ref3$basePrefix = _ref3.basePrefix,
133
- basePrefix = _ref3$basePrefix === void 0 ? '' : _ref3$basePrefix,
134
128
  shouldSkipGeneratingVar = _ref3.shouldSkipGeneratingVar;
135
129
 
136
130
  var css = {};
@@ -138,16 +132,6 @@ export default function cssVarsParser(theme, options) {
138
132
  var parsedTheme = {};
139
133
  walkObjectDeep(theme, function (keys, value, arrayKeys) {
140
134
  if (typeof value === 'string' || typeof value === 'number') {
141
- if (typeof value === 'string' && value.match(/var\(\s*--/)) {
142
- // for CSS variable, apply prefix or remove basePrefix from the variable
143
- if (!basePrefix && prefix) {
144
- value = value.replace(/var\(\s*--/g, "var(--".concat(prefix, "-"));
145
- } else {
146
- value = prefix ? value.replace(new RegExp("var\\(\\s*--".concat(basePrefix), 'g'), "var(--".concat(prefix)) // removing spaces
147
- : value.replace(new RegExp("var\\(\\s*--".concat(basePrefix, "-"), 'g'), 'var(--');
148
- }
149
- }
150
-
151
135
  if (!shouldSkipGeneratingVar || shouldSkipGeneratingVar && !shouldSkipGeneratingVar(keys, value)) {
152
136
  // only create css & var if `shouldSkipGeneratingVar` return false
153
137
  var cssVar = "--".concat(prefix ? "".concat(prefix, "-") : '').concat(keys.join('-'));
@@ -1 +1,2 @@
1
- export { default } from './createCssVarsProvider';
1
+ export { default } from './createCssVarsProvider';
2
+ export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
package/legacy/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.8.6
1
+ /** @license MUI v5.8.7
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.