@openedx/paragon 23.0.0-alpha.3 → 23.0.0-alpha.4
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.
- package/bin/paragon-scripts.js +10 -0
- package/dist/Annotation/index.scss +16 -0
- package/dist/Card/CardDeck.js +0 -2
- package/dist/Card/CardDeck.js.map +1 -1
- package/dist/Card/index.scss +6 -6
- package/dist/Carousel/index.scss +24 -1
- package/dist/Chip/ChipIcon.d.ts +1 -1
- package/dist/CloseButton/index.scss +8 -0
- package/dist/ColorPicker/index.scss +1 -1
- package/dist/DataTable/index.scss +12 -0
- package/dist/Dropdown/dropdown-bootstrap.scss +6 -0
- package/dist/Dropzone/index.scss +34 -0
- package/dist/Form/_FormText.scss +1 -1
- package/dist/Form/_bootstrap-custom-forms.scss +40 -0
- package/dist/Form/_index.scss +9 -0
- package/dist/Form/_mixins.scss +22 -0
- package/dist/IconButton/index.d.ts +1 -1
- package/dist/IconButton/index.scss +146 -0
- package/dist/Menu/index.scss +8 -0
- package/dist/Modal/ModalDialog.js +8 -4
- package/dist/Modal/ModalDialog.js.map +1 -1
- package/dist/Modal/_ModalDialog.scss +22 -2
- package/dist/Nav/index.scss +8 -0
- package/dist/Overlay/index.d.ts +2 -2
- package/dist/PageBanner/index.scss +2 -2
- package/dist/Pagination/pagination-bootstrap.scss +9 -0
- package/dist/Popover/index.scss +1 -1
- package/dist/ProductTour/Checkpoint.scss +1 -1
- package/dist/ProgressBar/bootstrap-progress.scss +20 -5
- package/dist/ProgressBar/index.scss +3 -3
- package/dist/Stepper/index.scss +1 -1
- package/dist/Sticky/index.scss +12 -0
- package/dist/Toast/index.scss +13 -1
- package/dist/Tooltip/index.scss +16 -0
- package/dist/core.css +911 -470
- package/dist/core.css.map +1 -1
- package/dist/core.min.css +1 -1
- package/dist/light.css +2035 -1315
- package/dist/light.css.map +1 -1
- package/dist/light.min.css +1 -1
- package/lib/build-tokens.js +67 -31
- package/package.json +7 -4
- package/src/Annotation/index.scss +16 -0
- package/src/Card/CardDeck.jsx +0 -3
- package/src/Card/README.md +0 -31
- package/src/Card/index.scss +6 -6
- package/src/Carousel/index.scss +24 -1
- package/src/CloseButton/index.scss +8 -0
- package/src/ColorPicker/index.scss +1 -1
- package/src/DataTable/index.scss +12 -0
- package/src/Dropdown/dropdown-bootstrap.scss +6 -0
- package/src/Dropzone/index.scss +34 -0
- package/src/Form/_FormText.scss +1 -1
- package/src/Form/_bootstrap-custom-forms.scss +40 -0
- package/src/Form/_index.scss +9 -0
- package/src/Form/_mixins.scss +22 -0
- package/src/IconButton/index.scss +146 -0
- package/src/Menu/index.scss +8 -0
- package/src/Modal/ModalDialog.jsx +7 -3
- package/src/Modal/_ModalDialog.scss +22 -2
- package/src/Modal/modal-dialog.mdx +95 -6
- package/src/Modal/tests/ModalDialog.test.jsx +2 -0
- package/src/Nav/index.scss +8 -0
- package/src/PageBanner/index.scss +2 -2
- package/src/Pagination/pagination-bootstrap.scss +9 -0
- package/src/Popover/index.scss +1 -1
- package/src/ProductTour/Checkpoint.scss +1 -1
- package/src/ProgressBar/bootstrap-progress.scss +20 -5
- package/src/ProgressBar/index.scss +3 -3
- package/src/Stepper/index.scss +1 -1
- package/src/Sticky/index.scss +12 -0
- package/src/Toast/index.scss +13 -1
- package/src/Tooltip/index.scss +16 -0
- package/styles/css/core/abstraction-variables.css +44 -0
- package/styles/css/core/custom-media-breakpoints.css +3 -4
- package/styles/css/core/index.css +2 -1
- package/styles/css/core/variables.css +494 -430
- package/styles/css/themes/light/abstraction-variables.css +304 -0
- package/styles/css/themes/light/index.css +1 -0
- package/styles/css/themes/light/utility-classes.css +2 -3
- package/styles/css/themes/light/variables.css +1753 -1334
- package/styles/scss/core/_typography.scss +16 -4
- package/styles/scss/core/_utilities.scss +7 -3
- package/styles/scss/core/_variables.scss +43 -30
- package/styles/scss/core/core.scss +1 -0
- package/tokens/src/core/alias/size.json +6 -5
- package/tokens/src/core/components/ActionRow.json +3 -2
- package/tokens/src/core/components/Alert.json +12 -10
- package/tokens/src/core/components/Annotation.json +9 -7
- package/tokens/src/core/components/Avatar.json +9 -9
- package/tokens/src/core/components/AvatarButton.json +4 -3
- package/tokens/src/core/components/Badge.json +12 -9
- package/tokens/src/core/components/Breadcrumb.json +7 -5
- package/tokens/src/core/components/Bubble.json +4 -3
- package/tokens/src/core/components/Button/core.json +35 -59
- package/tokens/src/core/components/Card.json +33 -44
- package/tokens/src/core/components/Carousel.json +39 -13
- package/tokens/src/core/components/Chip.json +13 -21
- package/tokens/src/core/components/ChipCarousel.json +4 -5
- package/tokens/src/core/components/CloseButton.json +2 -6
- package/tokens/src/core/components/Code.json +9 -8
- package/tokens/src/core/components/Collapsible.json +10 -13
- package/tokens/src/core/components/ColorPicker.json +3 -2
- package/tokens/src/core/components/Container.json +6 -5
- package/tokens/src/core/components/DataTable.json +17 -9
- package/tokens/src/core/components/Dropdown.json +24 -29
- package/tokens/src/core/components/Dropzone.json +5 -7
- package/tokens/src/core/components/Form/other.json +5 -4
- package/tokens/src/core/components/Form/size.json +72 -119
- package/tokens/src/core/components/Form/spacing.json +39 -83
- package/tokens/src/core/components/Form/transition.json +43 -7
- package/tokens/src/core/components/Form/typography.json +24 -88
- package/tokens/src/core/components/Icon.json +6 -5
- package/tokens/src/core/components/IconButton.json +4 -7
- package/tokens/src/core/components/Image.json +7 -6
- package/tokens/src/core/components/Menu.json +14 -12
- package/tokens/src/core/components/Modal.json +26 -21
- package/tokens/src/core/components/Nav.json +14 -16
- package/tokens/src/core/components/Navbar.json +15 -30
- package/tokens/src/core/components/Pagination.json +23 -24
- package/tokens/src/core/components/Popover.json +18 -14
- package/tokens/src/core/components/ProductTour.json +8 -14
- package/tokens/src/core/components/ProgressBar.json +29 -14
- package/tokens/src/core/components/SearchField.json +7 -9
- package/tokens/src/core/components/SelectableBox.json +4 -3
- package/tokens/src/core/components/Sheet.json +3 -2
- package/tokens/src/core/components/Spinner.json +9 -7
- package/tokens/src/core/components/Stack.json +2 -1
- package/tokens/src/core/components/Stepper.json +12 -14
- package/tokens/src/core/components/Sticky.json +2 -1
- package/tokens/src/core/components/Tab.json +8 -7
- package/tokens/src/core/components/Tabs.json +5 -5
- package/tokens/src/core/components/Toast.json +11 -8
- package/tokens/src/core/components/Tooltip.json +13 -11
- package/tokens/src/core/components/general/caret.json +5 -3
- package/tokens/src/core/components/general/headings.json +5 -4
- package/tokens/src/core/components/general/hr.json +3 -2
- package/tokens/src/core/components/general/input.json +19 -19
- package/tokens/src/core/components/general/link.json +13 -12
- package/tokens/src/core/components/general/list.json +9 -6
- package/tokens/src/core/components/general/text.json +6 -12
- package/tokens/src/core/global/breakpoints.json +25 -6
- package/tokens/src/core/global/elevation.json +55 -13
- package/tokens/src/core/global/other.json +5 -1
- package/tokens/src/core/global/spacing.json +70 -17
- package/tokens/src/core/global/transition.json +41 -4
- package/tokens/src/core/global/typography.json +248 -53
- package/tokens/src/core/utilities/color.json +35 -4
- package/tokens/src/themes/light/alias/color.json +276 -75
- package/tokens/src/themes/light/components/Alert.json +15 -26
- package/tokens/src/themes/light/components/Annotation.json +27 -13
- package/tokens/src/themes/light/components/Avatar.json +2 -1
- package/tokens/src/themes/light/components/Badge.json +57 -122
- package/tokens/src/themes/light/components/Breadcrumb.json +6 -5
- package/tokens/src/themes/light/components/Bubble.json +9 -8
- package/tokens/src/themes/light/components/Button/brand.json +171 -119
- package/tokens/src/themes/light/components/Button/core.json +8 -9
- package/tokens/src/themes/light/components/Button/danger.json +171 -112
- package/tokens/src/themes/light/components/Button/dark.json +188 -106
- package/tokens/src/themes/light/components/Button/info.json +186 -112
- package/tokens/src/themes/light/components/Button/light.json +186 -110
- package/tokens/src/themes/light/components/Button/primary.json +178 -116
- package/tokens/src/themes/light/components/Button/secondary.json +166 -132
- package/tokens/src/themes/light/components/Button/success.json +176 -117
- package/tokens/src/themes/light/components/Button/tertiary.json +34 -60
- package/tokens/src/themes/light/components/Button/warning.json +164 -128
- package/tokens/src/themes/light/components/Card.json +10 -21
- package/tokens/src/themes/light/components/Carousel.json +12 -11
- package/tokens/src/themes/light/components/Chip.json +14 -26
- package/tokens/src/themes/light/components/CloseButton.json +12 -2
- package/tokens/src/themes/light/components/Code.json +7 -9
- package/tokens/src/themes/light/components/DataTable.json +7 -11
- package/tokens/src/themes/light/components/Dropdown.json +17 -20
- package/tokens/src/themes/light/components/Dropzone.json +49 -11
- package/tokens/src/themes/light/components/Form/color.json +101 -155
- package/tokens/src/themes/light/components/Form/elevation.json +38 -42
- package/tokens/src/themes/light/components/Form/other.json +44 -41
- package/tokens/src/themes/light/components/IconButton.json +408 -256
- package/tokens/src/themes/light/components/Image.json +7 -4
- package/tokens/src/themes/light/components/Menu.json +12 -10
- package/tokens/src/themes/light/components/Modal.json +22 -12
- package/tokens/src/themes/light/components/Nav.json +82 -94
- package/tokens/src/themes/light/components/Navbar.json +32 -76
- package/tokens/src/themes/light/components/OverflowScroll.json +3 -1
- package/tokens/src/themes/light/components/PageBanner.json +11 -10
- package/tokens/src/themes/light/components/Pagination.json +19 -23
- package/tokens/src/themes/light/components/Popover.json +22 -27
- package/tokens/src/themes/light/components/ProductTour.json +9 -20
- package/tokens/src/themes/light/components/ProgressBar.json +12 -10
- package/tokens/src/themes/light/components/Scrollable.json +3 -3
- package/tokens/src/themes/light/components/SearchField.json +9 -9
- package/tokens/src/themes/light/components/Sheet.json +6 -7
- package/tokens/src/themes/light/components/Stepper.json +12 -17
- package/tokens/src/themes/light/components/Sticky.json +31 -6
- package/tokens/src/themes/light/components/Tab.json +47 -24
- package/tokens/src/themes/light/components/Toast.json +26 -14
- package/tokens/src/themes/light/components/Tooltip.json +25 -10
- package/tokens/src/themes/light/components/general/body.json +3 -2
- package/tokens/src/themes/light/components/general/headings.json +2 -1
- package/tokens/src/themes/light/components/general/hr.json +3 -6
- package/tokens/src/themes/light/components/general/input.json +11 -4
- package/tokens/src/themes/light/components/general/link.json +34 -43
- package/tokens/src/themes/light/components/general/list.json +15 -19
- package/tokens/src/themes/light/components/general/text.json +5 -6
- package/tokens/src/themes/light/global/color.json +1592 -867
- package/tokens/src/themes/light/global/elevation.json +481 -93
- package/tokens/style-dictionary.js +342 -144
- package/tokens/utils.js +176 -6
- package/tokens/src/core/global/display.json +0 -22
|
@@ -2,30 +2,92 @@
|
|
|
2
2
|
* This module creates and exports custom StyleDictionary instance for Paragon.
|
|
3
3
|
*/
|
|
4
4
|
const toml = require('js-toml');
|
|
5
|
-
const
|
|
5
|
+
const chalk = require('chalk');
|
|
6
6
|
const chroma = require('chroma-js');
|
|
7
7
|
const { colorYiq, darken, lighten } = require('./sass-helpers');
|
|
8
8
|
const cssUtilities = require('./css-utilities');
|
|
9
|
-
const { composeBreakpointName } = require('./utils');
|
|
9
|
+
const { composeBreakpointName, processAndUpdateTokens } = require('./utils');
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
/* eslint-disable import/no-unresolved */
|
|
12
|
+
const getStyleDictionary = async () => (await import('style-dictionary')).default;
|
|
13
|
+
const getStyleDictionaryUtils = async () => import('style-dictionary/utils');
|
|
14
|
+
const getTokensStudioTransforms = async () => import('@tokens-studio/sd-transforms');
|
|
15
|
+
/* eslint-enable import/no-unresolved */
|
|
12
16
|
|
|
13
|
-
|
|
17
|
+
/**
|
|
18
|
+
* @typedef {import('style-dictionary/types').DesignToken} DesignToken
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @typedef ModifyColorYiq
|
|
23
|
+
* @property {'color-yiq'} type - The type of modification.
|
|
24
|
+
* @property {number} [amount] - The amount of modification to apply.
|
|
25
|
+
* @property {string} [otherColor] - The other color to mix with.
|
|
26
|
+
* @property {number} [light] - The light color to use for color-yiq.
|
|
27
|
+
* @property {number} [dark] - The dark color to use for color-yiq.
|
|
28
|
+
* @property {number} [threshold] - The threshold to use for color-yiq.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @typedef ModifyColorDarken
|
|
33
|
+
* @property {'darken'} type - The type of modification.
|
|
34
|
+
* @property {number} amount - The amount of modification to apply.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @typedef ModifyColorLighten
|
|
39
|
+
* @property {'lighten'} type - The type of modification.
|
|
40
|
+
* @property {number} amount - The amount of modification to apply.
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @typedef ModifyColorMix
|
|
45
|
+
* @property {'mix'} type - The type of modification.
|
|
46
|
+
* @property {number} amount - The amount of modification to apply.
|
|
47
|
+
* @property {string} otherColor - The other color to mix with.
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @typedef ModifyColorAlpha
|
|
52
|
+
* @property {'alpha'} type - The type of modification.
|
|
53
|
+
* @property {number} amount - The amount of modification to apply.
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @typedef DesignTokenModify
|
|
58
|
+
* @type {ModifyColorYiq | ModifyColorDarken | ModifyColorLighten | ModifyColorMix | ModifyColorAlpha}
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @typedef {DesignToken & {
|
|
63
|
+
* outputReferences?: boolean;
|
|
64
|
+
* modify?: DesignTokenModify[];
|
|
65
|
+
* }} ParagonDesignToken
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Transforms a color token based on various modifications.
|
|
70
|
+
*
|
|
71
|
+
* @param {ParagonDesignToken} token - The token object containing color information and modifications.
|
|
72
|
+
* @param {string} themeVariant - The themeVariant object containing additional information for color transformations.
|
|
73
|
+
* @returns {string} - The transformed color value in hexadecimal format, including alpha if applicable.
|
|
74
|
+
*/
|
|
75
|
+
const colorTransform = (token, themeVariant) => {
|
|
14
76
|
const {
|
|
15
77
|
name: tokenName,
|
|
16
|
-
value,
|
|
78
|
+
$value,
|
|
17
79
|
original,
|
|
18
|
-
modify
|
|
80
|
+
modify,
|
|
19
81
|
} = token;
|
|
20
|
-
const reservedColorValues = ['inherit', 'initial', 'revert', 'unset', 'currentColor'];
|
|
82
|
+
const reservedColorValues = ['inherit', 'initial', 'revert', 'unset', 'currentColor', 'none'];
|
|
21
83
|
|
|
22
|
-
if (reservedColorValues.includes(original
|
|
23
|
-
return original
|
|
84
|
+
if (reservedColorValues.includes(original.$value)) {
|
|
85
|
+
return original.$value;
|
|
24
86
|
}
|
|
25
87
|
|
|
26
|
-
let color = chroma(value);
|
|
88
|
+
let color = chroma($value);
|
|
27
89
|
|
|
28
|
-
if (modify
|
|
90
|
+
if (modify?.length > 0) {
|
|
29
91
|
modify.forEach((modifier) => {
|
|
30
92
|
const { type, amount, otherColor } = modifier;
|
|
31
93
|
switch (type) {
|
|
@@ -40,7 +102,7 @@ const colorTransform = (token, theme) => {
|
|
|
40
102
|
light,
|
|
41
103
|
dark,
|
|
42
104
|
threshold,
|
|
43
|
-
|
|
105
|
+
themeVariant,
|
|
44
106
|
});
|
|
45
107
|
break;
|
|
46
108
|
}
|
|
@@ -50,8 +112,16 @@ const colorTransform = (token, theme) => {
|
|
|
50
112
|
case 'lighten':
|
|
51
113
|
color = lighten(color, amount);
|
|
52
114
|
break;
|
|
53
|
-
default:
|
|
115
|
+
default: {
|
|
116
|
+
if (!color[type]) {
|
|
117
|
+
// eslint-disable-next-line no-console
|
|
118
|
+
console.warn(
|
|
119
|
+
chalk.keyword('orange').bold(`[Paragon] Warning: Invalid color modification type "${type}" for ${tokenName}.`),
|
|
120
|
+
);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
54
123
|
color = color[type](amount);
|
|
124
|
+
}
|
|
55
125
|
}
|
|
56
126
|
});
|
|
57
127
|
}
|
|
@@ -65,165 +135,293 @@ const colorTransform = (token, theme) => {
|
|
|
65
135
|
* 2. 'theme' to output only theme's variables (e.g, 'light' or 'dark'), if theme is not provided - only
|
|
66
136
|
* core tokens are built.
|
|
67
137
|
*/
|
|
68
|
-
const createCustomCSSVariables = ({
|
|
69
|
-
|
|
70
|
-
themeVariant,
|
|
71
|
-
}) => {
|
|
138
|
+
const createCustomCSSVariables = async ({ formatterArgs }) => {
|
|
139
|
+
const { fileHeader, formattedVariables } = await getStyleDictionaryUtils();
|
|
72
140
|
const { dictionary, options, file } = formatterArgs;
|
|
141
|
+
const { outputReferences, formatting } = options;
|
|
142
|
+
const variables = formattedVariables({
|
|
143
|
+
format: 'css',
|
|
144
|
+
dictionary,
|
|
145
|
+
outputReferences: (token) => {
|
|
146
|
+
// Formatter options configured to never output references
|
|
147
|
+
if (!outputReferences) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
// Token has modifications (e.g., mix, darken, lighten); the computed
|
|
151
|
+
// value should be output instead of the reference.
|
|
152
|
+
if (token.modify) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
// Formatter options configured to show output references, but handle when individual tokens might opt-out.
|
|
156
|
+
return token.outputReferences ?? true;
|
|
157
|
+
},
|
|
158
|
+
usesDtcg: true,
|
|
159
|
+
});
|
|
160
|
+
const header = await fileHeader({ file, formatting });
|
|
161
|
+
return `${header}:root {\n${variables}\n}\n`;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* @typedef {type import("style-dictionary/types").StyleDictionary} StyleDictionary
|
|
166
|
+
*/
|
|
73
167
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
168
|
+
/**
|
|
169
|
+
* Initializes and configures Style Dictionary with custom transforms, formatters, filters, and parsers.
|
|
170
|
+
*
|
|
171
|
+
* @returns {Promise<StyleDictionary>} - A promise that resolves to the configured Style Dictionary instance.
|
|
172
|
+
*/
|
|
173
|
+
const initializeStyleDictionary = async ({ themes }) => {
|
|
174
|
+
const StyleDictionary = await getStyleDictionary();
|
|
175
|
+
const sdUtils = await getStyleDictionaryUtils();
|
|
176
|
+
const {
|
|
177
|
+
register: registerTokensStudioTransforms,
|
|
178
|
+
getTransforms: tokensStudioTransforms,
|
|
179
|
+
} = await getTokensStudioTransforms();
|
|
77
180
|
|
|
78
|
-
|
|
79
|
-
|
|
181
|
+
StyleDictionary.registerPreprocessor({
|
|
182
|
+
name: 'pgn-annotate-token-extensions-with-references',
|
|
183
|
+
preprocessor: (dictionary) => {
|
|
184
|
+
// Define the extension properties to add to the tokens $extensions object
|
|
185
|
+
const extensionProperties = [
|
|
186
|
+
{
|
|
187
|
+
name: 'isReferencedBySourceToken',
|
|
188
|
+
filter: tkn => tkn.isSource,
|
|
189
|
+
referenceTokenFilter: tkn => !tkn.isSource,
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
name: 'isReferencedByThemeVariant',
|
|
193
|
+
filter: tkn => themes.some(theme => tkn.filePath.includes(theme)),
|
|
194
|
+
referenceTokenFilter: tkn => !themes.some(theme => tkn.filePath.includes(theme)),
|
|
195
|
+
},
|
|
196
|
+
];
|
|
80
197
|
|
|
81
|
-
|
|
198
|
+
// Pass the dictionary to the recursive function to process and update tokens in place
|
|
199
|
+
const dictionaryCopy = { ...dictionary };
|
|
200
|
+
processAndUpdateTokens(dictionary, extensionProperties, sdUtils, dictionaryCopy);
|
|
82
201
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
});
|
|
88
|
-
}
|
|
202
|
+
// Return the updated dictionary
|
|
203
|
+
return dictionary;
|
|
204
|
+
},
|
|
205
|
+
});
|
|
89
206
|
|
|
90
|
-
|
|
91
|
-
|
|
207
|
+
/**
|
|
208
|
+
* Registers transforms from @tokens-studio/sd-transforms.
|
|
209
|
+
*/
|
|
210
|
+
registerTokensStudioTransforms(StyleDictionary);
|
|
92
211
|
|
|
93
|
-
|
|
94
|
-
|
|
212
|
+
/**
|
|
213
|
+
* Transforms tokens by applying SASS color functions to tokens.
|
|
214
|
+
*/
|
|
215
|
+
StyleDictionary.registerTransform({
|
|
216
|
+
name: 'color/sass-color-functions',
|
|
217
|
+
transitive: true,
|
|
218
|
+
type: 'value',
|
|
219
|
+
filter: (token) => token.attributes?.category === 'color' || token.$value.toString().startsWith('#'),
|
|
220
|
+
transform: (token) => colorTransform(token),
|
|
221
|
+
});
|
|
95
222
|
|
|
96
|
-
/**
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
StyleDictionary.registerTransform({
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
223
|
+
/**
|
|
224
|
+
* Transforms that implements str-replace from SASS.
|
|
225
|
+
*/
|
|
226
|
+
StyleDictionary.registerTransform({
|
|
227
|
+
name: 'str-replace',
|
|
228
|
+
transitive: true,
|
|
229
|
+
type: 'value',
|
|
230
|
+
filter: (token) => token.modify && token.modify[0].type === 'str-replace',
|
|
231
|
+
transform: (token) => {
|
|
232
|
+
const { $value, modify } = token;
|
|
233
|
+
const { toReplace, replaceWith } = modify[0];
|
|
234
|
+
return $value.replaceAll(toReplace, replaceWith);
|
|
235
|
+
},
|
|
236
|
+
});
|
|
108
237
|
|
|
109
|
-
/**
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
});
|
|
238
|
+
/**
|
|
239
|
+
* Registers a custom transform group for Paragon CSS.
|
|
240
|
+
*/
|
|
241
|
+
const customTransforms = [
|
|
242
|
+
'color/sass-color-functions',
|
|
243
|
+
'str-replace',
|
|
244
|
+
];
|
|
245
|
+
StyleDictionary.registerTransformGroup({
|
|
246
|
+
name: 'paragon-css',
|
|
247
|
+
transforms: [
|
|
248
|
+
...tokensStudioTransforms({ platform: 'css' }),
|
|
249
|
+
...StyleDictionary.hooks.transformGroups.css,
|
|
250
|
+
...customTransforms,
|
|
251
|
+
],
|
|
252
|
+
});
|
|
125
253
|
|
|
126
|
-
/**
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
StyleDictionary.registerFormat({
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
});
|
|
254
|
+
/**
|
|
255
|
+
* The custom formatter to create CSS variables for core tokens.
|
|
256
|
+
*/
|
|
257
|
+
StyleDictionary.registerFormat({
|
|
258
|
+
name: 'css/custom-variables',
|
|
259
|
+
format: formatterArgs => createCustomCSSVariables({ formatterArgs }),
|
|
260
|
+
});
|
|
133
261
|
|
|
134
|
-
/**
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
StyleDictionary.registerFormat({
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
262
|
+
/**
|
|
263
|
+
* Formatter to generate CSS utility classes.
|
|
264
|
+
* Looks in ./src/utilities/ to get utility classes configuration, filters tokens by 'filters' object attributes
|
|
265
|
+
* (see https://amzn.github.io/style-dictionary/#/tokens?id=category-type-item for possible keys in the object,
|
|
266
|
+
* each key should have a list of valid values) and generates CSS classes with using functions defined in
|
|
267
|
+
* 'utilityFunctionsToApply' list, those functions must be located in css-utilities.js module and return string.
|
|
268
|
+
*/
|
|
269
|
+
StyleDictionary.registerFormat({
|
|
270
|
+
name: 'css/utility-classes',
|
|
271
|
+
format: async ({ dictionary, file, options = {} }) => {
|
|
272
|
+
const { formatting } = options;
|
|
273
|
+
const { fileHeader } = await getStyleDictionaryUtils();
|
|
274
|
+
const { utilities } = dictionary.tokens;
|
|
275
|
+
if (!utilities) {
|
|
276
|
+
return '';
|
|
277
|
+
}
|
|
145
278
|
|
|
146
|
-
|
|
147
|
-
return '';
|
|
148
|
-
}
|
|
279
|
+
let utilityClasses = '';
|
|
149
280
|
|
|
150
|
-
|
|
281
|
+
utilities.forEach(({ filters, utilityFunctionsToApply }) => {
|
|
282
|
+
let tokens = dictionary.allTokens;
|
|
151
283
|
|
|
152
|
-
|
|
153
|
-
|
|
284
|
+
Object.entries(filters).forEach(([attributeName, allowedValues]) => {
|
|
285
|
+
tokens = tokens.filter((token) => allowedValues.includes(token.attributes[attributeName]));
|
|
286
|
+
});
|
|
154
287
|
|
|
155
|
-
|
|
156
|
-
|
|
288
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
289
|
+
for (const token of tokens) {
|
|
290
|
+
// Get action token by reference
|
|
291
|
+
const ref = sdUtils.getReferences(token.original.actions.default, dictionary.tokens)[0];
|
|
292
|
+
token.actions = { default: `var(--${ref.name})` };
|
|
293
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
294
|
+
for (const funcName of utilityFunctionsToApply) {
|
|
295
|
+
utilityClasses += cssUtilities[funcName](token);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
157
298
|
});
|
|
299
|
+
const header = await fileHeader({ file, formatting });
|
|
300
|
+
return `${header}${utilityClasses}`;
|
|
301
|
+
},
|
|
302
|
+
});
|
|
158
303
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
304
|
+
/**
|
|
305
|
+
* Formatter to generate CSS custom media queries for responsive breakpoints.
|
|
306
|
+
* Gets input about existing tokens of the 'size' category,
|
|
307
|
+
* 'breakpoints' subcategory, and generates a CSS custom media queries.
|
|
308
|
+
*/
|
|
309
|
+
StyleDictionary.registerFormat({
|
|
310
|
+
name: 'css/custom-media-breakpoints',
|
|
311
|
+
format: async ({ dictionary, file, options = {} }) => {
|
|
312
|
+
const { fileHeader } = await getStyleDictionaryUtils();
|
|
313
|
+
const { formatting } = options;
|
|
314
|
+
const { breakpoint } = dictionary.tokens.size;
|
|
315
|
+
|
|
316
|
+
let customMediaVariables = '';
|
|
317
|
+
const breakpoints = Object.values(breakpoint || {});
|
|
318
|
+
|
|
319
|
+
for (let i = 0; i < breakpoints.length; i++) {
|
|
320
|
+
const [currentBreakpoint, nextBreakpoint] = [breakpoints[i], breakpoints[i + 1]];
|
|
321
|
+
customMediaVariables
|
|
322
|
+
+= `${composeBreakpointName(currentBreakpoint.name, 'min')} (min-width: ${currentBreakpoint.$value});\n`;
|
|
323
|
+
if (nextBreakpoint) {
|
|
324
|
+
customMediaVariables
|
|
325
|
+
+= `${composeBreakpointName(currentBreakpoint.name, 'max')} (max-width: ${nextBreakpoint.$value});\n`;
|
|
167
326
|
}
|
|
168
327
|
}
|
|
169
|
-
|
|
328
|
+
const header = await fileHeader({ file, formatting });
|
|
329
|
+
return `${header}${customMediaVariables}`;
|
|
330
|
+
},
|
|
331
|
+
});
|
|
170
332
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
333
|
+
/**
|
|
334
|
+
* @typedef {function} StyleDictionaryFilterFunction
|
|
335
|
+
* @param {import('style-dictionary/types').TransformedToken} token - The token object to filter.
|
|
336
|
+
* @param {object} [opts] - The options object passed to the filter.
|
|
337
|
+
*/
|
|
174
338
|
|
|
175
|
-
/**
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
339
|
+
/**
|
|
340
|
+
* @typedef {object} StyleDictionaryFilterOptions
|
|
341
|
+
* @property {boolean} hasThemeVariants - Indicates whether the filter should also be registered with theme variants.
|
|
342
|
+
*/
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Registers a custom filter with Style Dictionary.
|
|
346
|
+
* @param {string} name Name for the filter.
|
|
347
|
+
* @param {StyleDictionaryFilterFunction} filter Filter value or function.
|
|
348
|
+
* @param {StyleDictionaryFilterOptions} [filterOptions] Custom options for the filter.
|
|
349
|
+
*/
|
|
350
|
+
function registerStyleDictionaryFilter(name, filter, filterOptions = {}) {
|
|
351
|
+
StyleDictionary.registerFilter({ name, filter });
|
|
352
|
+
if (filterOptions.hasThemeVariants) {
|
|
353
|
+
themes.forEach((themeVariant) => {
|
|
354
|
+
StyleDictionary.registerFilter({
|
|
355
|
+
name: `${name}.${themeVariant}`,
|
|
356
|
+
filter: (token, opts) => {
|
|
357
|
+
const paragonExtensions = token.$extensions?.['org.openedx.paragon'];
|
|
358
|
+
const isReferencedByThemeVariant = !!paragonExtensions?.isReferencedByThemeVariant;
|
|
359
|
+
const baseFilterResult = typeof filter === 'function' ? filter(token, opts) || isReferencedByThemeVariant : filter;
|
|
360
|
+
if (!baseFilterResult) {
|
|
361
|
+
return false;
|
|
362
|
+
}
|
|
363
|
+
return token.filePath.includes(themeVariant) || isReferencedByThemeVariant;
|
|
364
|
+
},
|
|
365
|
+
});
|
|
366
|
+
});
|
|
194
367
|
}
|
|
368
|
+
}
|
|
195
369
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
370
|
+
const paragonFilters = [
|
|
371
|
+
/**
|
|
372
|
+
* Registers a filter `isSource` that filters output to only include source tokens.
|
|
373
|
+
*/
|
|
374
|
+
{
|
|
375
|
+
name: 'isSource',
|
|
376
|
+
filter: (token) => {
|
|
377
|
+
const paragonExtensions = token.$extensions?.['org.openedx.paragon'];
|
|
378
|
+
const isReferencedBySourceToken = !!paragonExtensions?.isReferencedBySourceToken;
|
|
379
|
+
return token.isSource || isReferencedBySourceToken;
|
|
380
|
+
},
|
|
381
|
+
opts: { hasThemeVariants: true },
|
|
382
|
+
},
|
|
383
|
+
/**
|
|
384
|
+
* Registers filter(s) `isThemeVariant.{variant}` that only include the requested theme variant tokens.
|
|
385
|
+
*/
|
|
386
|
+
...themes.map((themeVariant) => ({
|
|
387
|
+
name: `isThemeVariant.${themeVariant}`,
|
|
388
|
+
filter: (token) => {
|
|
389
|
+
const isThemeVariantToken = token.filePath.includes(themeVariant);
|
|
390
|
+
const paragonExtensions = token.$extensions?.['org.openedx.paragon'];
|
|
391
|
+
const isReferencedByThemeVariant = !!paragonExtensions?.isReferencedByThemeVariant;
|
|
392
|
+
return isThemeVariantToken || isReferencedByThemeVariant;
|
|
393
|
+
},
|
|
394
|
+
})),
|
|
395
|
+
];
|
|
396
|
+
paragonFilters.forEach(({ name, filter, opts }) => registerStyleDictionaryFilter(name, filter, opts));
|
|
199
397
|
|
|
200
|
-
/**
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
StyleDictionary.
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
],
|
|
209
|
-
});
|
|
398
|
+
/**
|
|
399
|
+
* Registers a custom TOML parser with Style Dictionary.
|
|
400
|
+
*/
|
|
401
|
+
StyleDictionary.registerParser({
|
|
402
|
+
name: 'toml-parser',
|
|
403
|
+
pattern: /\.toml$/,
|
|
404
|
+
parser: ({ contents }) => toml.load(contents),
|
|
405
|
+
});
|
|
210
406
|
|
|
211
|
-
/**
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
407
|
+
/**
|
|
408
|
+
* Registers a custom fileHeader.
|
|
409
|
+
*/
|
|
410
|
+
StyleDictionary.registerFileHeader({
|
|
411
|
+
name: 'customFileHeader',
|
|
412
|
+
fileHeader: (defaultMessage) => [
|
|
413
|
+
`${defaultMessage} while transforming design tokens.`,
|
|
414
|
+
'See <root>/tokens/README.md for more details.',
|
|
415
|
+
],
|
|
416
|
+
});
|
|
219
417
|
|
|
220
|
-
StyleDictionary
|
|
221
|
-
|
|
222
|
-
parse: ({ contents }) => toml.load(contents),
|
|
223
|
-
});
|
|
418
|
+
return StyleDictionary;
|
|
419
|
+
};
|
|
224
420
|
|
|
225
421
|
module.exports = {
|
|
226
|
-
|
|
422
|
+
initializeStyleDictionary,
|
|
423
|
+
getTokensStudioTransforms,
|
|
227
424
|
createCustomCSSVariables,
|
|
228
425
|
colorTransform,
|
|
426
|
+
getStyleDictionaryUtils,
|
|
229
427
|
};
|