@instructure/emotion 11.7.3 → 11.7.4-pr-snapshot-1781695314229

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 (68) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/LICENSE.md +1 -0
  3. package/{lib/styleUtils/mirrorShorthandEdges.js → babel.config.cjs} +13 -14
  4. package/es/InstUISettingsProvider/index.js +1 -1
  5. package/es/index.js +9 -9
  6. package/es/styleUtils/applyColorModifiers.js +83 -0
  7. package/es/styleUtils/calcSpacingFromShorthand.js +0 -1
  8. package/es/styleUtils/index.js +8 -7
  9. package/es/styleUtils/mirrorShorthandCorners.js +1 -1
  10. package/es/styleUtils/mirrorShorthandEdges.js +1 -1
  11. package/es/useStyle.js +7 -2
  12. package/es/useStyleNew.js +5 -3
  13. package/es/withStyle.js +10 -3
  14. package/es/withStyleNew.js +18 -40
  15. package/package.json +12 -14
  16. package/src/InstUISettingsProvider/README.md +4 -1
  17. package/src/InstUISettingsProvider/index.tsx +1 -1
  18. package/src/getComponentThemeOverride.ts +1 -1
  19. package/src/getTheme.ts +1 -1
  20. package/src/index.ts +9 -9
  21. package/src/styleUtils/applyColorModifiers.ts +108 -0
  22. package/src/styleUtils/index.ts +7 -7
  23. package/src/styleUtils/mirrorShorthandCorners.ts +1 -1
  24. package/src/styleUtils/mirrorShorthandEdges.ts +1 -1
  25. package/src/useStyle.ts +2 -2
  26. package/src/useStyleNew.ts +7 -4
  27. package/src/withStyle.tsx +7 -3
  28. package/src/withStyleNew.tsx +22 -46
  29. package/tsconfig.build.tsbuildinfo +1 -1
  30. package/types/getComponentThemeOverride.d.ts +1 -1
  31. package/types/getComponentThemeOverride.d.ts.map +1 -1
  32. package/types/getTheme.d.ts +1 -1
  33. package/types/getTheme.d.ts.map +1 -1
  34. package/types/index.d.ts +9 -9
  35. package/types/index.d.ts.map +1 -1
  36. package/types/styleUtils/applyColorModifiers.d.ts +18 -0
  37. package/types/styleUtils/applyColorModifiers.d.ts.map +1 -0
  38. package/types/styleUtils/index.d.ts +7 -7
  39. package/types/styleUtils/index.d.ts.map +1 -1
  40. package/types/styleUtils/mirrorShorthandCorners.d.ts +1 -1
  41. package/types/styleUtils/mirrorShorthandCorners.d.ts.map +1 -1
  42. package/types/styleUtils/mirrorShorthandEdges.d.ts +1 -1
  43. package/types/styleUtils/mirrorShorthandEdges.d.ts.map +1 -1
  44. package/types/useStyleNew.d.ts.map +1 -1
  45. package/types/withStyle.d.ts +5 -1
  46. package/types/withStyle.d.ts.map +1 -1
  47. package/types/withStyleNew.d.ts +11 -37
  48. package/types/withStyleNew.d.ts.map +1 -1
  49. package/lib/EmotionTypes.js +0 -5
  50. package/lib/InstUISettingsProvider/index.js +0 -79
  51. package/lib/getComponentThemeOverride.js +0 -74
  52. package/lib/getTheme.js +0 -94
  53. package/lib/index.js +0 -133
  54. package/lib/package.json +0 -1
  55. package/lib/styleUtils/ThemeablePropValues.js +0 -104
  56. package/lib/styleUtils/calcFocusOutlineStyles.js +0 -77
  57. package/lib/styleUtils/calcSpacingFromShorthand.js +0 -119
  58. package/lib/styleUtils/getShorthandPropValue.js +0 -84
  59. package/lib/styleUtils/index.js +0 -54
  60. package/lib/styleUtils/makeThemeVars.js +0 -51
  61. package/lib/styleUtils/mirrorShorthand.js +0 -97
  62. package/lib/styleUtils/mirrorShorthandCorners.js +0 -37
  63. package/lib/useComputedTheme.js +0 -63
  64. package/lib/useStyle.js +0 -60
  65. package/lib/useStyleNew.js +0 -85
  66. package/lib/useTheme.js +0 -53
  67. package/lib/withStyle.js +0 -121
  68. package/lib/withStyleNew.js +0 -195
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [11.7.4-pr-snapshot-1781695314229](https://github.com/instructure/instructure-ui/compare/v11.7.3...v11.7.4-pr-snapshot-1781695314229) (2026-06-17)
7
+
8
+
9
+ ### Features
10
+
11
+ * **ui-scripts:** refactor theme type generation and fix token fetching script ([ab0536f](https://github.com/instructure/instructure-ui/commit/ab0536f81ffe9ae60f8b8cdc5038f4f323314416))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [11.7.3](https://github.com/instructure/instructure-ui/compare/v11.7.2...v11.7.3) (2026-05-07)
7
18
 
8
19
 
package/LICENSE.md CHANGED
@@ -2,6 +2,7 @@
2
2
  title: The MIT License (MIT)
3
3
  category: Getting Started
4
4
  order: 9
5
+ isWIP: true
5
6
  ---
6
7
 
7
8
  # The MIT License (MIT)
@@ -1,16 +1,3 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- Object.defineProperty(exports, "mirrorShorthandEdges", {
8
- enumerable: true,
9
- get: function () {
10
- return _mirrorShorthand.mirrorShorthandEdges;
11
- }
12
- });
13
- var _mirrorShorthand = require("./mirrorShorthand");
14
1
  /*
15
2
  * The MIT License (MIT)
16
3
  *
@@ -34,4 +21,16 @@ var _mirrorShorthand = require("./mirrorShorthand");
34
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35
22
  * SOFTWARE.
36
23
  */
37
- var _default = exports.default = _mirrorShorthand.mirrorShorthandEdges;
24
+
25
+ module.exports = {
26
+ presets: [
27
+ [
28
+ require('@instructure/ui-babel-preset'),
29
+ {
30
+ esModules: Boolean(process.env.ES_MODULES),
31
+ removeConsole: process.env.NODE_ENV === 'production',
32
+ transformImports: Boolean(process.env.TRANSFORM_IMPORTS)
33
+ }
34
+ ]
35
+ ]
36
+ }
@@ -26,7 +26,7 @@ import { useContext } from 'react';
26
26
  import { ThemeProvider } from '@emotion/react';
27
27
  import { TextDirectionContext } from '@instructure/ui-i18n';
28
28
  import { DeterministicIdContextProvider } from '@instructure/ui-react-utils';
29
- import { getTheme } from "../getTheme.js";
29
+ import { getTheme } from '../getTheme.js';
30
30
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
31
31
  /**
32
32
  * ---
package/es/index.js CHANGED
@@ -24,12 +24,12 @@
24
24
  /// <reference types="@emotion/react/types/css-prop" />
25
25
 
26
26
  export * from '@emotion/react';
27
- export { useComputedTheme } from "./useComputedTheme.js";
28
- export { InstUISettingsProvider } from "./InstUISettingsProvider/index.js";
29
- export { withStyle } from "./withStyle.js";
30
- export { getComponentThemeOverride } from "./getComponentThemeOverride.js";
31
- export { withStyleNew } from "./withStyleNew.js";
32
- export { ThemeablePropValues, makeThemeVars, getShorthandPropValue, mirrorShorthandCorners, mirrorShorthandEdges, calcSpacingFromShorthand, calcFocusOutlineStyles } from "./styleUtils/index.js";
33
- export { useStyle } from "./useStyle.js";
34
- export { useStyleNew } from "./useStyleNew.js";
35
- export { useTheme } from "./useTheme.js";
27
+ export { useComputedTheme } from './useComputedTheme.js';
28
+ export { InstUISettingsProvider } from './InstUISettingsProvider/index.js';
29
+ export { withStyle } from './withStyle.js';
30
+ export { getComponentThemeOverride } from './getComponentThemeOverride.js';
31
+ export { withStyleNew } from './withStyleNew.js';
32
+ export { ThemeablePropValues, makeThemeVars, getShorthandPropValue, mirrorShorthandCorners, mirrorShorthandEdges, calcSpacingFromShorthand, calcFocusOutlineStyles } from './styleUtils/index.js';
33
+ export { useStyle } from './useStyle.js';
34
+ export { useStyleNew } from './useStyleNew.js';
35
+ export { useTheme } from './useTheme.js';
@@ -0,0 +1,83 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ import { colorToHsla } from '@instructure/ui-color-utils';
25
+ // Matches Tokens Studio's HSL modifier math: move L by `amount` (0–1) of the
26
+ // remaining distance toward the endpoint, so the step shrinks as it approaches
27
+ // black/white and never overshoots.
28
+ const modifyLightness = (l, amount, type) => type === 'darken' ? Math.max(0, l - l * amount) : Math.min(1, l + (1 - l) * amount);
29
+ const formatHsla = (h, s, l, a) => {
30
+ const hh = Math.round(h);
31
+ const ss = +(s * 100).toFixed(2);
32
+ const ll = +(l * 100).toFixed(2);
33
+ return a < 1 ? `hsla(${hh}, ${ss}%, ${ll}%, ${a})` : `hsl(${hh}, ${ss}%, ${ll}%)`;
34
+ };
35
+ const isModifyColor = val => typeof val === 'object' && val !== null && typeof val.value === 'string' && typeof val.modify === 'object' && val.modify !== null;
36
+ const resolveModifyColor = ({
37
+ value,
38
+ modify
39
+ }) => {
40
+ if (modify.type === 'darken' || modify.type === 'lighten') {
41
+ const {
42
+ h,
43
+ s,
44
+ l,
45
+ a
46
+ } = colorToHsla(value);
47
+ const newL = modifyLightness(l, modify.value, modify.type);
48
+ return formatHsla(h, s, newL, a);
49
+ }
50
+ return value;
51
+ };
52
+
53
+ /**
54
+ * Resolves a component theme object by applying color modifiers to any entries
55
+ * shaped as `{ value, modify: { type, value } }`. Entries with `modify.type` of
56
+ * `'darken'` or `'lighten'` are transformed in HSL space using the same math
57
+ * Tokens Studio applies (`space: "hsl"`): `amount` is a 0–1 fraction of the
58
+ * remaining distance to black/white. Plain values and unrecognized modifier
59
+ * types are passed through unchanged. Nested plain objects are walked
60
+ * recursively so modifiers anywhere in the tree get resolved.
61
+ *
62
+ * @param componentTheme - Theme map whose values can be CSS strings, `ModifyColor`
63
+ * objects, or nested theme objects containing the same.
64
+ * @returns A new theme object mirroring the input shape, with every `ModifyColor`
65
+ * collapsed to its final resolved color string.
66
+ */
67
+ const applyColorModifiers = componentTheme => {
68
+ if (componentTheme == null) return {};
69
+ const result = {};
70
+ for (const key of Object.keys(componentTheme)) {
71
+ const entry = componentTheme[key];
72
+ if (isModifyColor(entry)) {
73
+ result[key] = resolveModifyColor(entry);
74
+ } else if (typeof entry === 'object' && entry !== null && !Array.isArray(entry)) {
75
+ result[key] = applyColorModifiers(entry);
76
+ } else {
77
+ result[key] = entry;
78
+ }
79
+ }
80
+ return result;
81
+ };
82
+ export default applyColorModifiers;
83
+ export { applyColorModifiers };
@@ -1,4 +1,3 @@
1
- import "core-js/modules/es.array.includes.js";
2
1
  /*
3
2
  * The MIT License (MIT)
4
3
  *
@@ -21,10 +21,11 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
- export { ThemeablePropValues } from "./ThemeablePropValues.js";
25
- export { makeThemeVars } from "./makeThemeVars.js";
26
- export { getShorthandPropValue } from "./getShorthandPropValue.js";
27
- export { mirrorShorthandCorners } from "./mirrorShorthandCorners.js";
28
- export { mirrorShorthandEdges } from "./mirrorShorthandEdges.js";
29
- export { calcSpacingFromShorthand } from "./calcSpacingFromShorthand.js";
30
- export { calcFocusOutlineStyles } from "./calcFocusOutlineStyles.js";
24
+
25
+ export { ThemeablePropValues } from './ThemeablePropValues.js';
26
+ export { makeThemeVars } from './makeThemeVars.js';
27
+ export { getShorthandPropValue } from './getShorthandPropValue.js';
28
+ export { mirrorShorthandCorners } from './mirrorShorthandCorners.js';
29
+ export { mirrorShorthandEdges } from './mirrorShorthandEdges.js';
30
+ export { calcSpacingFromShorthand } from './calcSpacingFromShorthand.js';
31
+ export { calcFocusOutlineStyles } from './calcFocusOutlineStyles.js';
@@ -21,6 +21,6 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
- import { mirrorShorthandCorners } from "./mirrorShorthand.js";
24
+ import { mirrorShorthandCorners } from './mirrorShorthand.js';
25
25
  export default mirrorShorthandCorners;
26
26
  export { mirrorShorthandCorners };
@@ -21,6 +21,6 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
- import { mirrorShorthandEdges } from "./mirrorShorthand.js";
24
+ import { mirrorShorthandEdges } from './mirrorShorthand.js';
25
25
  export default mirrorShorthandEdges;
26
26
  export { mirrorShorthandEdges };
package/es/useStyle.js CHANGED
@@ -21,10 +21,15 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
- import { useTheme } from "./useTheme.js";
25
- import { getComponentThemeOverride } from "./getComponentThemeOverride.js"; // returns the second parameter of a function
24
+
25
+ import { useTheme } from './useTheme.js';
26
+ import { getComponentThemeOverride } from './getComponentThemeOverride.js';
27
+
28
+ // returns the second parameter of a function
29
+
26
30
  // TODO this is only used by the old themes, remove when everything uses the new
27
31
  // theming system
32
+
28
33
  /*
29
34
  * This is only used by the **old themes**, remove when everything uses the new
30
35
  * theming system (InstUI v12)
package/es/useStyleNew.js CHANGED
@@ -21,8 +21,10 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
- import { useTheme } from "./useTheme.js";
24
+
25
+ import { useTheme } from './useTheme.js';
25
26
  import { mergeDeep } from '@instructure/ui-utils';
27
+ import { applyColorModifiers } from './styleUtils/applyColorModifiers.js';
26
28
 
27
29
  // returns the second parameter of a function
28
30
 
@@ -64,11 +66,11 @@ const useStyleNew = useStyleParams => {
64
66
  const primitives = mergeDeep(theme.newTheme.primitives, primitiveOverrides);
65
67
  const semantics = mergeDeep(theme.newTheme.semantics?.(primitives), semanticsOverrides);
66
68
  const sharedTokens = mergeDeep(theme.newTheme.sharedTokens?.(semantics), sharedTokensOverrides);
67
- const baseComponentTheme = generateComponentTheme ? generateComponentTheme({
69
+ const baseComponentTheme = applyColorModifiers(generateComponentTheme ? generateComponentTheme({
68
70
  primitives,
69
71
  semantics,
70
72
  sharedTokens
71
- }) : theme.newTheme.components[componentWithTokensId]?.(semantics);
73
+ }) : theme.newTheme.components[componentWithTokensId]?.(semantics));
72
74
  const componentThemeFromSettingsProvider = mergeDeep(baseComponentTheme, componentOverridesFromSettingsProvider);
73
75
  const componentTheme = mergeDeep(componentThemeFromSettingsProvider, typeof themeOverride === 'function' ? themeOverride(componentThemeFromSettingsProvider, themeInContext) : themeOverride);
74
76
 
package/es/withStyle.js CHANGED
@@ -27,9 +27,12 @@ import hoistNonReactStatics from 'hoist-non-react-statics';
27
27
  import { deepEqual as isEqual } from '@instructure/ui-utils';
28
28
  import { warn } from '@instructure/console';
29
29
  import { decorator } from '@instructure/ui-decorator';
30
- import { getComponentThemeOverride } from "./getComponentThemeOverride.js";
31
- import { useTheme } from "./useTheme.js"; // Extract is needed because it would allow number otherwise
30
+ import { getComponentThemeOverride } from './getComponentThemeOverride.js';
31
+ import { useTheme } from './useTheme.js';
32
+
33
+ // Extract is needed because it would allow number otherwise
32
34
  // https://stackoverflow.com/a/51808262/319473
35
+
33
36
  // Unique name of an InstUI component
34
37
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
35
38
  const defaultValues = {
@@ -41,7 +44,11 @@ const defaultValues = {
41
44
  * ---
42
45
  * category: utilities/themes
43
46
  * ---
44
- * used for old (v11 and eariler) theming system
47
+ * Legacy decorator for the pre-v11.7 theming system. New components should use
48
+ * `withStyleNew` instead. Override patterns for components decorated with
49
+ * `withStyle` are documented on the
50
+ * [Legacy theme overrides](/#legacy-theme-overrides) docs page.
51
+ *
45
52
  * TODO delete when the theme migration is complete
46
53
  */
47
54
  const withStyle = decorator((ComposedComponent, generateStyle, generateComponentTheme) => {
@@ -27,8 +27,12 @@ import hoistNonReactStatics from 'hoist-non-react-statics';
27
27
  import { deepEqual as isEqual, mergeDeep } from '@instructure/ui-utils';
28
28
  import { warn } from '@instructure/console';
29
29
  import { decorator } from '@instructure/ui-decorator';
30
- import { useTheme } from "./useTheme.js"; // Extract is needed because it would allow number otherwise
30
+ import { useTheme } from './useTheme.js';
31
+ import { applyColorModifiers } from './styleUtils/applyColorModifiers.js';
32
+
33
+ // Extract is needed because it would allow number otherwise
31
34
  // https://stackoverflow.com/a/51808262/319473
35
+
32
36
  // Unique name of an InstUI component
33
37
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
34
38
  const defaultValues = {
@@ -41,11 +45,9 @@ const defaultValues = {
41
45
  * category: utilities/themes
42
46
  * ---
43
47
  *
44
- * A decorator or higher order component that makes a component themeable.
45
- *
46
- * It adds a `makeStyles` function and the generated `styles` object to the decorated Component's props. If it has an own theme, it also adds the `themeOverride` prop to the component.
47
- *
48
- * As a HOC:
48
+ * Decorator (or HOC) that makes a component themeable using InstUI's new
49
+ * theming system. Injects a `makeStyles` function and the
50
+ * generated `styles` object as props.
49
51
  *
50
52
  * ```js-code
51
53
  * import { withStyleNew } from '@instructure/emotion'
@@ -54,42 +56,18 @@ const defaultValues = {
54
56
  * export default withStyleNew(generateStyle)(ExampleComponent)
55
57
  * ```
56
58
  *
57
- * Themeable components inject their themed styles into the document
58
- * when they are mounted.
59
- *
60
- * ### Applying themes
61
- *
62
- * A themeable component’s theme can be configured via wrapping it in an
63
- * [InstUISettingsProvider](InstUISettingsProvider) component, and/or set
64
- * explicitly via its `themeOverride` prop.
59
+ * Optionally pass a `useTokensFrom` key as the second argument to consume
60
+ * another component's tokens (e.g. `withStyleNew(generateStyle, 'BaseButton')`).
65
61
  *
66
- * InstUISettingsProvider provides a theme object (e.g. the [canvas theme](/#canvas)).
67
- * These variables are mapped to the component's own variables in `theme.js` (see [theming](theming-basics) for more info).
68
- *
69
- * With the `themeOverride` prop you can directly set/override the component theme variables declared in theme.js. It accepts an object or a function. The function has the component's theme and the currently active main theme as its parameter.
70
- *
71
- * See more about the overrides on the [Using theme overrides](/#using-theme-overrides) docs page.
72
- *
73
- * ```jsx-code
74
- * {// global theme override}
75
- * <InstUISettingsProvider theme={{
76
- * colors: { backgroundMedium: '#888' }
77
- * }}>
78
- * {// component theme override}
79
- * <ExampleComponent themeOverride={{ hoverColor: '#eee' }} />
80
- *
81
- * {// component theme override with function}
82
- * <ExampleComponent themeOverride={(componentTheme, currentTheme) => ({
83
- * hoverBackground: componentTheme.background,
84
- * activeBackground: currentTheme.colors.backgroundBrand
85
- * })} />
86
- * </InstUISettingsProvider>
87
- * ```
62
+ * Override patterns (provider-scoped, per-component, primitives / semantics /
63
+ * sharedTokens layers, priority rules) are documented on the
64
+ * [New theme overrides](/#new-theme-overrides) docs page.
88
65
  *
89
66
  * @module withStyleNew
90
67
  *
91
- * @param {function} generateStyle - The function that returns the component's style object
92
- * @returns {ReactElement} The decorated WithStyle Component
68
+ * @param {function} generateStyle - Returns the component's style object
69
+ * @param {string} [useTokensFrom] - Key of another component whose tokens this one should consume
70
+ * @returns {ReactElement} The decorated component
93
71
  */
94
72
  const withStyleNew = decorator((ComposedComponent, generateStyle, useTokensFrom, frozenTheme, generateComponentTheme) => {
95
73
  const displayName = ComposedComponent.displayName || ComposedComponent.name;
@@ -131,11 +109,11 @@ const withStyleNew = decorator((ComposedComponent, generateStyle, useTokensFrom,
131
109
  const semantics = mergeDeep(theme.newTheme.semantics?.(primitives), semanticsOverrides);
132
110
  const sharedTokens = mergeDeep(theme.newTheme.sharedTokens?.(semantics), sharedTokensOverrides);
133
111
  // Note: Some components do not have a theme, e.g., FormFieldMessages
134
- const baseComponentTheme = generateComponentTheme ? generateComponentTheme({
112
+ const baseComponentTheme = applyColorModifiers(generateComponentTheme ? generateComponentTheme({
135
113
  primitives,
136
114
  semantics,
137
115
  sharedTokens
138
- }) : theme.newTheme.components[componentId]?.(semantics);
116
+ }) : theme.newTheme.components[componentId]?.(semantics));
139
117
  const componentThemeFromSettingsProvider = mergeDeep(baseComponentTheme, componentOverridesFromSettingsProvider);
140
118
  const componentTheme = mergeDeep(componentThemeFromSettingsProvider,
141
119
  // @ts-ignore TODO-theme-types: fix typing
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@instructure/emotion",
3
- "version": "11.7.3",
3
+ "version": "11.7.4-pr-snapshot-1781695314229",
4
+ "type": "module",
4
5
  "description": "A UI component library made by Instructure Inc.",
5
6
  "author": "Instructure, Inc. Engineering and Product Design",
6
7
  "module": "./es/index.js",
7
- "main": "./lib/index.js",
8
8
  "types": "./types/index.d.ts",
9
9
  "repository": {
10
10
  "type": "git",
@@ -17,14 +17,14 @@
17
17
  "@babel/runtime": "^7.29.2",
18
18
  "@emotion/react": "^11",
19
19
  "hoist-non-react-statics": "^3.3.2",
20
- "@instructure/console": "11.7.3",
21
- "@instructure/ui-color-utils": "11.7.3",
22
- "@instructure/ui-decorator": "11.7.3",
23
- "@instructure/ui-react-utils": "11.7.3",
24
- "@instructure/shared-types": "11.7.3",
25
- "@instructure/ui-i18n": "11.7.3",
26
- "@instructure/ui-themes": "11.7.3",
27
- "@instructure/ui-utils": "11.7.3"
20
+ "@instructure/console": "11.7.4-pr-snapshot-1781695314229",
21
+ "@instructure/shared-types": "11.7.4-pr-snapshot-1781695314229",
22
+ "@instructure/ui-decorator": "11.7.4-pr-snapshot-1781695314229",
23
+ "@instructure/ui-i18n": "11.7.4-pr-snapshot-1781695314229",
24
+ "@instructure/ui-react-utils": "11.7.4-pr-snapshot-1781695314229",
25
+ "@instructure/ui-themes": "11.7.4-pr-snapshot-1781695314229",
26
+ "@instructure/ui-utils": "11.7.4-pr-snapshot-1781695314229",
27
+ "@instructure/ui-color-utils": "11.7.4-pr-snapshot-1781695314229"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@testing-library/jest-dom": "^6.6.3",
@@ -32,7 +32,7 @@
32
32
  "@testing-library/user-event": "^14.6.1",
33
33
  "react-dom": "18.3.1",
34
34
  "vitest": "^3.2.2",
35
- "@instructure/ui-babel-preset": "11.7.3"
35
+ "@instructure/ui-babel-preset": "11.7.4-pr-snapshot-1781695314229"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "react": ">=18 <=19"
@@ -46,10 +46,8 @@
46
46
  "src": "./src/index.ts",
47
47
  "types": "./types/index.d.ts",
48
48
  "import": "./es/index.js",
49
- "require": "./lib/index.js",
50
49
  "default": "./es/index.js"
51
50
  },
52
- "./lib/*": "./lib/*",
53
51
  "./es/*": "./es/*",
54
52
  "./types/*": "./types/*",
55
53
  "./package.json": "./package.json",
@@ -59,7 +57,7 @@
59
57
  "lint": "ui-scripts lint",
60
58
  "lint:fix": "ui-scripts lint --fix",
61
59
  "clean": "ui-scripts clean",
62
- "build": "ui-scripts build --modules es,cjs",
60
+ "build": "ui-scripts build",
63
61
  "build:watch": "pnpm run ts:check -- --watch & ui-scripts build --watch",
64
62
  "build:types": "tsc -p tsconfig.build.json ",
65
63
  "ts:check": "tsc -p tsconfig.build.json"
@@ -62,7 +62,10 @@ ReactDOM.render(
62
62
 
63
63
  #### Theme overrides
64
64
 
65
- There are multiple ways to override themes in InstUI. You can read about how these work on the dedicated docs page: [Using theme overrides](/#using-theme-overrides).
65
+ There are multiple ways to override themes in InstUI. You can read about how these work on the dedicated docs pages:
66
+
67
+ - [Legacy theme overrides](/#legacy-theme-overrides).
68
+ - [New theme overrides](/#new-theme-overrides).
66
69
 
67
70
  ### Text direction management
68
71
 
@@ -28,7 +28,7 @@ import { ThemeProvider } from '@emotion/react'
28
28
  import { TextDirectionContext } from '@instructure/ui-i18n'
29
29
  import { DeterministicIdContextProvider } from '@instructure/ui-react-utils'
30
30
 
31
- import { getTheme } from '../getTheme'
31
+ import { getTheme } from '../getTheme.js'
32
32
 
33
33
  import type { ThemeOrLegacyOverride } from '../EmotionTypes'
34
34
  import type { DeterministicIdProviderValue } from '@instructure/ui-react-utils'
@@ -28,7 +28,7 @@ import type {
28
28
  ComponentOverride
29
29
  } from './EmotionTypes'
30
30
  import type { ComponentTheme } from '@instructure/shared-types'
31
- import { ThemeOverrideProp } from './withStyleNew'
31
+ import { ThemeOverrideProp } from './withStyleNew.js'
32
32
  import type { NewComponentTypes } from '@instructure/ui-themes'
33
33
 
34
34
  type ComponentName = keyof ComponentOverride | undefined
package/src/getTheme.ts CHANGED
@@ -31,7 +31,7 @@ import type {
31
31
  ThemeOrLegacyOverride,
32
32
  SpecificThemeOverride
33
33
  } from './EmotionTypes'
34
- import { InstUIProviderProps } from './InstUISettingsProvider'
34
+ import { InstUIProviderProps } from './InstUISettingsProvider/index.js'
35
35
  declare const process: Record<string, any> | undefined
36
36
 
37
37
  /**
package/src/index.ts CHANGED
@@ -25,11 +25,11 @@
25
25
 
26
26
  export * from '@emotion/react'
27
27
 
28
- export { useComputedTheme } from './useComputedTheme'
29
- export { InstUISettingsProvider } from './InstUISettingsProvider'
30
- export { withStyle } from './withStyle'
31
- export { getComponentThemeOverride } from './getComponentThemeOverride'
32
- export { withStyleNew } from './withStyleNew'
28
+ export { useComputedTheme } from './useComputedTheme.js'
29
+ export { InstUISettingsProvider } from './InstUISettingsProvider/index.js'
30
+ export { withStyle } from './withStyle.js'
31
+ export { getComponentThemeOverride } from './getComponentThemeOverride.js'
32
+ export { withStyleNew } from './withStyleNew.js'
33
33
  export {
34
34
  ThemeablePropValues,
35
35
  makeThemeVars,
@@ -38,11 +38,11 @@ export {
38
38
  mirrorShorthandEdges,
39
39
  calcSpacingFromShorthand,
40
40
  calcFocusOutlineStyles
41
- } from './styleUtils'
41
+ } from './styleUtils/index.js'
42
42
 
43
- export { useStyle } from './useStyle'
44
- export { useStyleNew } from './useStyleNew'
45
- export { useTheme } from './useTheme'
43
+ export { useStyle } from './useStyle.js'
44
+ export { useStyleNew } from './useStyleNew.js'
45
+ export { useTheme } from './useTheme.js'
46
46
 
47
47
  export type { InstUIProviderProps } from './InstUISettingsProvider'
48
48
  export type { ComponentStyle, StyleObject, Overrides } from './EmotionTypes'
@@ -0,0 +1,108 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ import { colorToHsla } from '@instructure/ui-color-utils'
25
+
26
+ type ModifyColor = {
27
+ value: string
28
+ modify: {
29
+ type: 'lighten' | 'darken'
30
+ value: number
31
+ }
32
+ }
33
+
34
+ // Matches Tokens Studio's HSL modifier math: move L by `amount` (0–1) of the
35
+ // remaining distance toward the endpoint, so the step shrinks as it approaches
36
+ // black/white and never overshoots.
37
+ const modifyLightness = (
38
+ l: number,
39
+ amount: number,
40
+ type: 'darken' | 'lighten'
41
+ ): number =>
42
+ type === 'darken'
43
+ ? Math.max(0, l - l * amount)
44
+ : Math.min(1, l + (1 - l) * amount)
45
+
46
+ const formatHsla = (h: number, s: number, l: number, a: number): string => {
47
+ const hh = Math.round(h)
48
+ const ss = +(s * 100).toFixed(2)
49
+ const ll = +(l * 100).toFixed(2)
50
+ return a < 1
51
+ ? `hsla(${hh}, ${ss}%, ${ll}%, ${a})`
52
+ : `hsl(${hh}, ${ss}%, ${ll}%)`
53
+ }
54
+
55
+ const isModifyColor = (val: unknown): val is ModifyColor =>
56
+ typeof val === 'object' &&
57
+ val !== null &&
58
+ typeof (val as ModifyColor).value === 'string' &&
59
+ typeof (val as ModifyColor).modify === 'object' &&
60
+ (val as ModifyColor).modify !== null
61
+
62
+ const resolveModifyColor = ({ value, modify }: ModifyColor): string => {
63
+ if (modify.type === 'darken' || modify.type === 'lighten') {
64
+ const { h, s, l, a } = colorToHsla(value)
65
+ const newL = modifyLightness(l, modify.value, modify.type)
66
+ return formatHsla(h, s, newL, a)
67
+ }
68
+ return value
69
+ }
70
+
71
+ /**
72
+ * Resolves a component theme object by applying color modifiers to any entries
73
+ * shaped as `{ value, modify: { type, value } }`. Entries with `modify.type` of
74
+ * `'darken'` or `'lighten'` are transformed in HSL space using the same math
75
+ * Tokens Studio applies (`space: "hsl"`): `amount` is a 0–1 fraction of the
76
+ * remaining distance to black/white. Plain values and unrecognized modifier
77
+ * types are passed through unchanged. Nested plain objects are walked
78
+ * recursively so modifiers anywhere in the tree get resolved.
79
+ *
80
+ * @param componentTheme - Theme map whose values can be CSS strings, `ModifyColor`
81
+ * objects, or nested theme objects containing the same.
82
+ * @returns A new theme object mirroring the input shape, with every `ModifyColor`
83
+ * collapsed to its final resolved color string.
84
+ */
85
+ const applyColorModifiers = (
86
+ componentTheme: Record<string, unknown> | undefined | null
87
+ ): Record<string, unknown> => {
88
+ if (componentTheme == null) return {}
89
+ const result: Record<string, unknown> = {}
90
+ for (const key of Object.keys(componentTheme)) {
91
+ const entry = componentTheme[key]
92
+ if (isModifyColor(entry)) {
93
+ result[key] = resolveModifyColor(entry)
94
+ } else if (
95
+ typeof entry === 'object' &&
96
+ entry !== null &&
97
+ !Array.isArray(entry)
98
+ ) {
99
+ result[key] = applyColorModifiers(entry as Record<string, unknown>)
100
+ } else {
101
+ result[key] = entry
102
+ }
103
+ }
104
+ return result
105
+ }
106
+
107
+ export default applyColorModifiers
108
+ export { applyColorModifiers }