@grantcodes/style-dictionary 1.3.0 → 1.3.1

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 (78) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/css/grantcodes/grantcodes.css +367 -0
  3. package/dist/css/grantcodes/tokens.css +367 -0
  4. package/dist/css/todomap/todomap.css +200 -0
  5. package/dist/css/todomap/tokens.css +200 -0
  6. package/dist/css/wireframe/tokens.css +426 -0
  7. package/dist/css/wireframe/wireframe.css +426 -0
  8. package/dist/js/grantcodes/style-dictionary.d.ts +361 -0
  9. package/dist/js/grantcodes/style-dictionary.js +386 -0
  10. package/dist/js/todomap/style-dictionary.d.ts +202 -0
  11. package/dist/js/todomap/style-dictionary.js +220 -0
  12. package/dist/js/wireframe/style-dictionary.d.ts +414 -0
  13. package/dist/js/wireframe/style-dictionary.js +427 -0
  14. package/dist/json/grantcodes/tokens.json +351 -0
  15. package/dist/json/todomap/tokens.json +200 -0
  16. package/dist/json/wireframe/tokens.json +404 -0
  17. package/package.json +66 -61
  18. package/.turbo/turbo-build.log +0 -45
  19. package/.turbo/turbo-lint.log +0 -10
  20. package/AGENTS.md +0 -67
  21. package/biome.json +0 -9
  22. package/build.js +0 -10
  23. package/config.js +0 -509
  24. package/demo.html +0 -171
  25. package/lib/color-generator.js +0 -13
  26. package/lib/get-style-dictionary-config.js +0 -223
  27. package/lib/get-themes.js +0 -10
  28. package/lib/index.js +0 -3
  29. package/tests/tokens.test.js +0 -87
  30. package/tokens/core/tier-1-definitions/colors.json +0 -174
  31. package/tokens/core/tier-1-definitions/z-index.json +0 -28
  32. package/tokens/grantcodes/tier-1-definitions/animation.json +0 -26
  33. package/tokens/grantcodes/tier-1-definitions/borders.json +0 -35
  34. package/tokens/grantcodes/tier-1-definitions/colors.json +0 -35
  35. package/tokens/grantcodes/tier-1-definitions/shadows.json +0 -38
  36. package/tokens/grantcodes/tier-1-definitions/spacing.json +0 -49
  37. package/tokens/grantcodes/tier-1-definitions/typography.json +0 -142
  38. package/tokens/grantcodes/tier-2-usage/00-colors-background.json +0 -71
  39. package/tokens/grantcodes/tier-2-usage/00-colors-border.json +0 -41
  40. package/tokens/grantcodes/tier-2-usage/00-colors-content.json +0 -44
  41. package/tokens/grantcodes/tier-2-usage/animation.json +0 -23
  42. package/tokens/grantcodes/tier-2-usage/borders.json +0 -26
  43. package/tokens/grantcodes/tier-2-usage/shadows.json +0 -38
  44. package/tokens/grantcodes/tier-2-usage/spacing.json +0 -25
  45. package/tokens/grantcodes/tier-2-usage/typography-usage.json +0 -276
  46. package/tokens/grantcodes/tier-3-components/button.json +0 -94
  47. package/tokens/grantcodes/tier-3-components/focus-ring.json +0 -25
  48. package/tokens/grantcodes/tier-3-components/form.json +0 -69
  49. package/tokens/grantcodes/tier-3-components/link.json +0 -38
  50. package/tokens/todomap/tier-1-definitions/colors.json +0 -91
  51. package/tokens/todomap/tier-1-definitions/spacing.json +0 -49
  52. package/tokens/todomap/tier-1-definitions/typography.json +0 -12
  53. package/tokens/todomap/tier-2-usage/00-colors-background.json +0 -35
  54. package/tokens/todomap/tier-2-usage/00-colors-content.json +0 -32
  55. package/tokens/todomap/tier-2-usage/spacing.json +0 -25
  56. package/tokens/todomap/tier-2-usage/typography-usage.json +0 -20
  57. package/tokens/todomap/tier-3-components/button.json +0 -140
  58. package/tokens/todomap/tier-3-components/focus-ring.json +0 -25
  59. package/tokens/todomap/tier-3-components/form.json +0 -69
  60. package/tokens/todomap/tier-3-components/link.json +0 -38
  61. package/tokens/wireframe/tier-1-definitions/animation.json +0 -17
  62. package/tokens/wireframe/tier-1-definitions/borders.json +0 -41
  63. package/tokens/wireframe/tier-1-definitions/colors.json +0 -35
  64. package/tokens/wireframe/tier-1-definitions/shadows.json +0 -38
  65. package/tokens/wireframe/tier-1-definitions/spacing.json +0 -49
  66. package/tokens/wireframe/tier-1-definitions/typography.json +0 -130
  67. package/tokens/wireframe/tier-2-usage/00-colors-background.json +0 -85
  68. package/tokens/wireframe/tier-2-usage/00-colors-border.json +0 -41
  69. package/tokens/wireframe/tier-2-usage/00-colors-content.json +0 -44
  70. package/tokens/wireframe/tier-2-usage/animation.json +0 -23
  71. package/tokens/wireframe/tier-2-usage/borders.json +0 -32
  72. package/tokens/wireframe/tier-2-usage/shadows.json +0 -38
  73. package/tokens/wireframe/tier-2-usage/spacing.json +0 -25
  74. package/tokens/wireframe/tier-2-usage/typography-usage.json +0 -444
  75. package/tokens/wireframe/tier-3-components/button.json +0 -94
  76. package/tokens/wireframe/tier-3-components/focus-ring.json +0 -25
  77. package/tokens/wireframe/tier-3-components/form.json +0 -69
  78. package/tokens/wireframe/tier-3-components/link.json +0 -38
package/AGENTS.md DELETED
@@ -1,67 +0,0 @@
1
- # @grantcodes/style-dictionary
2
-
3
- Design tokens and theming system for the UI packages. Built with Style Dictionary.
4
-
5
- ## Themes
6
-
7
- Three themes are available:
8
-
9
- - **grantcodes** - Default theme with Greycliff font
10
- - **todomap** - Theme with Quicksand font
11
- - **wireframe** - Minimal theme with system fonts
12
-
13
- ## Token Structure
14
-
15
- Tokens are organized in tiers:
16
-
17
- ```
18
- tokens/
19
- ā”œā”€ā”€ core/ # Shared tokens (z-index)
20
- ā”œā”€ā”€ grantcodes/ # Grantcodes theme
21
- │ ā”œā”€ā”€ tier-1-definitions/ # Base tokens (colors, typography, etc.)
22
- │ ā”œā”€ā”€ tier-2-usage/ # Usage tokens (component-level)
23
- │ └── tier-3-components/ # Component-specific tokens
24
- ā”œā”€ā”€ todomap/ # Todomap theme
25
- └── wireframe/ # Wireframe theme
26
- ```
27
-
28
- ### Tier System
29
-
30
- - **Tier 1** - Primitive/base tokens (colors, spacing, typography)
31
- - **Tier 2** - Usage tokens (semantic, component-level)
32
- - **Tier 3** - Component-specific tokens
33
-
34
- ## Exports
35
-
36
- ```javascript
37
- // Theme tokens (CSS variables)
38
- import '@grantcodes/style-dictionary/grantcodes/css';
39
- import '@grantcodes/style-dictionary/todomap/css';
40
- import '@grantcodes/style-dictionary/wireframe/css';
41
-
42
- // Theme with component tokens
43
- import '@grantcodes/style-dictionary/grantcodes/css/theme';
44
-
45
- // JavaScript tokens
46
- import { GColorNeutral100 } from '@grantcodes/style-dictionary/grantcodes/js';
47
-
48
- // Fonts
49
- import '@grantcodes/style-dictionary/assets/fonts/greycliff';
50
- import '@grantcodes/style-dictionary/assets/fonts/quicksand';
51
- ```
52
-
53
- ## Adding New Tokens
54
-
55
- 1. Choose the appropriate theme folder
56
- 2. Add token to the correct tier (1, 2, or 3)
57
- 3. Rebuild with `pnpm build`
58
-
59
- ## Building
60
-
61
- ```bash
62
- # Build all themes
63
- pnpm build
64
-
65
- # Build single theme
66
- pnpm build -- --theme=grantcodes
67
- ```
package/biome.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "root": false,
3
- "$schema": "https://biomejs.dev/schemas/2.3.13/schema.json",
4
- "extends": ["../biome.json"],
5
- "files": {
6
- "ignoreUnknown": false,
7
- "includes": ["tokens/**", "lib/**", "build.js", "config.js"]
8
- }
9
- }
package/build.js DELETED
@@ -1,10 +0,0 @@
1
- /**
2
- * Build script to create style dictionary outputs for each theme
3
- * This now uses the config.js file which contains all the build logic
4
- */
5
-
6
- // The build logic is now in config.js and runs automatically when executed
7
- // This file can be kept for backwards compatibility or removed
8
- // Run: node config.js or node build.js (which runs config.js)
9
-
10
- import "./config.js";
package/config.js DELETED
@@ -1,509 +0,0 @@
1
- import StyleDictionary from "style-dictionary";
2
- import minimist from "minimist";
3
-
4
- /**
5
- * List of themes to build
6
- * 1) Add your new theme here in order to have it show up in the dropdown
7
- */
8
- const AVAILABLE_THEMES = ["wireframe", "grantcodes", "todomap"];
9
-
10
- /**
11
- * Look for args passed on the command line
12
- * 1) Used to build a single theme if needed
13
- * 2) Pass in the theme name as an argument
14
- * 3) If no argument is passed, build all themes
15
- */
16
- const args = minimist(process.argv.slice(2));
17
- const theme = args.theme;
18
-
19
- /**
20
- * Helper function to check if token is from tier-2 or tier-3
21
- * 1) Used to determine if the token should be included in the theme tokens to apply `theme` prefix
22
- */
23
- const isHigherTierToken = (filePath) => {
24
- const isHigherTier =
25
- filePath.includes("tier-2-usage") || filePath.includes("tier-3-components");
26
- return isHigherTier;
27
- };
28
-
29
- /**
30
- * Transform shadow tokens
31
- * 1) Used to transform the individual shadow tokens into a single box-shadow-sm, box-shadow-md, etc. with x, y, blur, spread, and color concatenated
32
- */
33
- const transformTypographyTokens = (dictionary, themeTokens) => {
34
- const typographyGroups = dictionary.allTokens.filter(
35
- (p) =>
36
- isHigherTierToken(p.filePath) &&
37
- p.path[0] === 'typography'
38
- ).reduce((groups, token) => {
39
- const style = token.path[1]; // extract typography.{style}
40
- if (!groups[style]) groups[style] = {};
41
- groups[style][token.path[2]] = token.value;
42
- return groups;
43
- }, {});
44
-
45
- Object.keys(typographyGroups).forEach((style) => {
46
- const group = typographyGroups[style];
47
- if (group['font-family'] && group['font-weight'] && group['font-size'] && group['line-height']) {
48
- const shorthand = `${group['font-weight']} ${group['font-size']}/${group['line-height']} ${group['font-family']}`;
49
- themeTokens.push(` --g-theme-typography-${style}: ${shorthand};`);
50
- }
51
- });
52
- };
53
-
54
- const transformShadowTokens = (dictionary, size, themeTokens) => {
55
- const shadowProps = dictionary.allTokens.filter(
56
- (p) =>
57
- isHigherTierToken(p.filePath) &&
58
- p.path[0] === "box-shadow" &&
59
- p.path[1] === size,
60
- );
61
-
62
- const x = shadowProps.find((p) => p.path[2] === "x")?.value || "0px";
63
- const y = shadowProps.find((p) => p.path[2] === "y")?.value || "0px";
64
- const blur = shadowProps.find((p) => p.path[2] === "blur")?.value || "0px";
65
- const spread =
66
- shadowProps.find((p) => p.path[2] === "spread")?.value || "0px";
67
- const color =
68
- shadowProps.find((p) => p.path[2] === "color")?.value || "transparent";
69
-
70
- /* 1 */
71
- themeTokens.push(
72
- ` --g-theme-box-shadow-${size}: ${x} ${y} ${blur} ${spread} ${color};`,
73
- );
74
- };
75
-
76
- /**
77
- * Transform line height tokens
78
- * 1) Used to transform the line height tokens to a unitless value for CSS by dividing the line height by the font size
79
- */
80
- const transformLineHeight = (
81
- dictionary,
82
- prop,
83
- outputArray,
84
- formatTokenName,
85
- ) => {
86
- const cleanPath = prop.path
87
- .map((segment) =>
88
- segment.startsWith("@") ? segment.substring(1) : segment,
89
- )
90
- .filter((segment) => segment !== "")
91
- .join("-");
92
-
93
- // For tier-1 tokens (typography.line-height.16), find matching font-size (typography.font-size.16)
94
- // For tier-2/3 tokens (typography.headline-lg.line-height), find matching font-size (typography.headline-lg.font-size)
95
- const isTier1 =
96
- prop.path.length === 3 &&
97
- prop.path[0] === "typography" &&
98
- prop.path[1] === "line-height";
99
- let fontSizePath;
100
- if (isTier1) {
101
- // Tier-1: typography.line-height.16 -> typography.font-size.16
102
- fontSizePath = ["typography", "font-size", prop.path[2]];
103
- } else {
104
- // Tier-2/3: typography.headline-lg.line-height -> typography.headline-lg.font-size
105
- fontSizePath = [...prop.path.slice(0, -1), "font-size"];
106
- }
107
-
108
- const fontSizeProp = dictionary.allTokens.find(
109
- (p) => p.path.join(".") === fontSizePath.join("."),
110
- );
111
-
112
- // Parse line-height value to pixels
113
- let lineHeightPx;
114
- if (prop.value.endsWith("px")) {
115
- lineHeightPx = parseFloat(prop.value.replace("px", ""));
116
- } else if (prop.value.endsWith("rem")) {
117
- lineHeightPx = parseFloat(prop.value.replace("rem", "")) * 16;
118
- } else {
119
- lineHeightPx = parseFloat(prop.value);
120
- }
121
-
122
- if (fontSizeProp) {
123
- // Found matching font-size - use it for calculation
124
- let fontSizePx;
125
- if (fontSizeProp.value.endsWith("px")) {
126
- fontSizePx = parseFloat(fontSizeProp.value.replace("px", ""));
127
- } else if (fontSizeProp.value.endsWith("rem")) {
128
- fontSizePx = parseFloat(fontSizeProp.value.replace("rem", "")) * 16;
129
- } else {
130
- fontSizePx = parseFloat(fontSizeProp.value);
131
- }
132
-
133
- if (fontSizePx > 0) {
134
- const unitlessValue = (lineHeightPx / fontSizePx).toFixed(2);
135
- outputArray.push(
136
- ` ${formatTokenName(cleanPath, prop)}: ${unitlessValue};`,
137
- );
138
- return;
139
- }
140
- } else if (isTier1 && lineHeightPx > 0) {
141
- // For tier-1 tokens without matching font-size, use 16px as base font-size
142
- const BASE_FONT_SIZE = 16;
143
- const unitlessValue = (lineHeightPx / BASE_FONT_SIZE).toFixed(2);
144
- outputArray.push(
145
- ` ${formatTokenName(cleanPath, prop)}: ${unitlessValue};`,
146
- );
147
- return;
148
- }
149
-
150
- // Fallback: output as-is if we can't calculate
151
- outputArray.push(` ${formatTokenName(cleanPath, prop)}: ${prop.value};`);
152
- };
153
-
154
- /**
155
- * Format variables
156
- * 1) Used to format the inner contents of the :root or .[theme-name] ruleset
157
- */
158
- const formatVariables = (dictionary) => {
159
- const processedShadows = new Set();
160
- const tier1Tokens = [];
161
- const themeTokens = [];
162
-
163
- /**
164
- * Format token global prefix and tier 2/3 identifier
165
- * 1) If the token is from tier-2 or tier-3, prefix it with `g-theme-`
166
- * 2) Otherwise, prefix it with `g-`
167
- */
168
- const formatTokenName = (cleanPath, prop) => {
169
- if (isHigherTierToken(prop.filePath)) {
170
- return `--g-theme-${cleanPath}`;
171
- }
172
- return `--g-${cleanPath}`;
173
- };
174
-
175
- /**
176
- * Get all box-shadow values from tier 2/3
177
- * 1) Used to determine which box-shadow values to transform into a single box-shadow-sm, box-shadow-md, etc.
178
- */
179
- const shadowSizes = dictionary.tokens.shadow
180
- ? Object.keys(dictionary.tokens.shadow)
181
- .map((key) => key.split("-")[0])
182
- .filter((value, index, self) => self.indexOf(value) === index) // Get unique sizes
183
- : [];
184
-
185
- /**
186
- * Iterate over all tokens and format them
187
- *
188
- */
189
-
190
- transformTypographyTokens(dictionary, themeTokens);
191
-
192
- dictionary.allTokens.forEach((prop) => {
193
- /**
194
- * 1) Always include z-index and size tokens from core
195
- */
196
- if (prop.path[0] === "z-index") {
197
- const cleanPath = prop.path
198
- .map((segment) =>
199
- segment.startsWith("@") ? segment.substring(1) : segment,
200
- )
201
- .filter((segment) => segment !== "")
202
- .join("-");
203
- tier1Tokens.push(` ${formatTokenName(cleanPath, prop)}: ${prop.value};`);
204
- return;
205
- }
206
-
207
- /**
208
- * Handle box-shadow token transformations
209
- * If the token is from tier-2 or tier-3 and is a box-shadow, transform it into a single box-shadow-sm, box-shadow-md, etc.
210
- */
211
- if (
212
- isHigherTierToken(prop.filePath) &&
213
- prop.path[0] === "box-shadow" &&
214
- shadowSizes.includes(prop.path[1])
215
- ) {
216
- const size = prop.path[1];
217
- if (processedShadows.has(size)) return;
218
- processedShadows.add(size);
219
- transformShadowTokens(dictionary, size, themeTokens);
220
- } else if (
221
- prop.path[0] === "typography" &&
222
- prop.path.includes("line-height")
223
- ) {
224
- /**
225
- * Handle line heights in typography (both tier-1 and tier-2/3)
226
- * 1) Transform line-height tokens to unitless values by dividing by font-size
227
- */
228
- const outputArray = isHigherTierToken(prop.filePath)
229
- ? themeTokens
230
- : tier1Tokens;
231
- transformLineHeight(dictionary, prop, outputArray, formatTokenName);
232
- } else if (!prop.path.includes("box-shadow") || prop.path.length > 3) {
233
- /**
234
- * Handle all other properties
235
- * 1) If the token is not a box-shadow or typography token, format it as a normal token
236
- */
237
- const cleanPath = prop.path
238
- .map((segment) =>
239
- segment.startsWith("@") ? segment.substring(1) : segment,
240
- )
241
- .filter((segment) => segment !== "")
242
- .join("-");
243
-
244
- const token = ` ${formatTokenName(cleanPath, prop)}: ${prop.value};`;
245
- if (isHigherTierToken(prop.filePath)) {
246
- themeTokens.push(token);
247
- } else {
248
- tier1Tokens.push(token);
249
- }
250
- }
251
- });
252
-
253
- return [...new Set([...tier1Tokens, ...themeTokens])].join("\n");
254
- };
255
-
256
- /**
257
- * Transform shadow tokens for JSON format
258
- * Combines individual shadow properties into a single value
259
- */
260
- const transformShadowTokensJSON = (dictionary, size) => {
261
- const shadowProps = dictionary.allTokens.filter(
262
- (p) =>
263
- isHigherTierToken(p.filePath) &&
264
- p.path[0] === "box-shadow" &&
265
- p.path[1] === size,
266
- );
267
-
268
- const x = shadowProps.find((p) => p.path[2] === "x")?.value || "0px";
269
- const y = shadowProps.find((p) => p.path[2] === "y")?.value || "0px";
270
- const blur = shadowProps.find((p) => p.path[2] === "blur")?.value || "0px";
271
- const spread =
272
- shadowProps.find((p) => p.path[2] === "spread")?.value || "0px";
273
- const color =
274
- shadowProps.find((p) => p.path[2] === "color")?.value || "transparent";
275
-
276
- return `${x} ${y} ${blur} ${spread} ${color}`;
277
- };
278
-
279
- /**
280
- * Generate a Theme-Specific Config
281
- * This accepts a theme parameter, which is used to control which set of
282
- * tokens to compile, and to define theme-specific compiled output.
283
- * @param {string} theme
284
- */
285
- const getStyleDictionaryConfig = (theme) => {
286
- // Register the JSON formatter
287
- StyleDictionary.registerFormat({
288
- name: "json/flat/custom",
289
- format: function (dictionary) {
290
- const transformedTokens = {};
291
-
292
- /**
293
- * Get all box-shadow values from tier 2/3
294
- * 1) Used to determine which box-shadow values to transform into a single box-shadow-sm, box-shadow-md, etc.
295
- */
296
- const shadowSizes = dictionary.tokens.shadow
297
- ? Object.keys(dictionary.tokens.shadow)
298
- .map((key) => key.split("-")[0])
299
- .filter((value, index, self) => self.indexOf(value) === index) // Get unique sizes
300
- : [];
301
-
302
- // Process regular tokens
303
- dictionary.allTokens.forEach((token) => {
304
- // Remove the isHigherTierToken check to include all tokens
305
- if (token.path[0] === "box-shadow" && token.path.length > 2) return;
306
- const prefix = isHigherTierToken(token.filePath) ? "g-theme-" : "g-";
307
- transformedTokens[`${prefix}${token.path.join("-")}`] = token.value;
308
- });
309
-
310
- // Process shadow tokens
311
- shadowSizes.forEach((size) => {
312
- transformedTokens[`g-theme-box-shadow-${size}`] =
313
- transformShadowTokensJSON(dictionary, size);
314
- });
315
-
316
- return JSON.stringify(transformedTokens, null, 2);
317
- },
318
- });
319
-
320
- /**
321
- * Register the CSS formatter
322
- * 1) Used to format the inner contents of the .[theme-name] ruleset for Storybook only or if you want to define tokens using a theme name
323
- */
324
- StyleDictionary.registerFormat({
325
- name: "css/variables-themed",
326
- format: function (dictionary) {
327
- return `.${theme} {\n${formatVariables(dictionary)}\n}\n`;
328
- },
329
- });
330
-
331
- /**
332
- * Define the base pixel value for rem conversion
333
- */
334
- const BASE_FONT_SIZE = 16; // Typically 16px = 1rem
335
-
336
- /**
337
- * Register the size/px-to-rem transform
338
- * 1) Used to convert px values to rem values
339
- * 2) Match only properties with px values
340
- * 3) Only transform if it's a valid px value
341
- */
342
- StyleDictionary.registerTransform({
343
- name: "size/px-to-rem",
344
- type: "value",
345
- matcher: function (prop) {
346
- /* 2 */
347
- return (
348
- prop &&
349
- prop.value &&
350
- typeof prop.value === "string" &&
351
- prop.value.endsWith("px")
352
- );
353
- },
354
- transform: function (prop) {
355
- if (!prop || !prop.value) return prop.value;
356
- /* 3 */
357
- const pxValue = prop.value.trim();
358
- if (!pxValue.endsWith("px")) return prop.value;
359
-
360
- const pixels = parseFloat(pxValue);
361
- if (isNaN(pixels)) return prop.value;
362
-
363
- const remValue = Number((pixels / BASE_FONT_SIZE).toFixed(4)).toString();
364
- return `${remValue}rem`;
365
- },
366
- });
367
-
368
- /**
369
- * Register the CSS formatter
370
- * 1) Used to format the inner contents of the :root ruleset for Storybook only or if you want to define tokens with theme prefix
371
- */
372
- StyleDictionary.registerFormat({
373
- name: "css/custom-variables",
374
- format: function (dictionary) {
375
- return `:root {\n${formatVariables(dictionary)}\n}`;
376
- },
377
- });
378
-
379
- /**
380
- * Register the name/theme-prefix transform
381
- * 1) Used to prefix the token name with the theme name
382
- * 2) If the token is from tier-2 or tier-3, prefix it with `GTheme` for JS
383
- * 3) Otherwise, prefix it with `G` for JS
384
- */
385
- StyleDictionary.registerTransform({
386
- name: "name/theme-prefix",
387
- type: "name",
388
- transform: function (token) {
389
- const cleanPath = token.path
390
- .map((segment) =>
391
- segment.startsWith("@") ? segment.substring(1) : segment,
392
- )
393
- .filter((segment) => segment !== "")
394
- .join("-");
395
-
396
- /* 2 */
397
- if (isHigherTierToken(token.filePath)) {
398
- return `GTheme${cleanPath
399
- .split("-")
400
- .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
401
- .join("")}`;
402
- }
403
-
404
- /* 3 */
405
- return `G${cleanPath
406
- .split("-")
407
- .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
408
- .join("")}`;
409
- },
410
- });
411
-
412
- /**
413
- * Register the custom/css transform group
414
- */
415
- StyleDictionary.registerTransformGroup({
416
- name: "custom/css",
417
- transforms: ["attribute/cti", "name/kebab", "size/px-to-rem"],
418
- });
419
-
420
- /**
421
- * Register the custom/js transform group
422
- */
423
- StyleDictionary.registerTransformGroup({
424
- name: "custom/js",
425
- transforms: ["attribute/cti", "name/theme-prefix", "size/px-to-rem"],
426
- });
427
-
428
- /**
429
- * Define the config
430
- * 1) Used to define the platforms, prefixes, etc. to build the tokens with/for
431
- */
432
- const config = {
433
- source: [`./tokens/core/**/*.json`, `./tokens/${theme}/**/*.json`],
434
- log: {
435
- // Set the log level to show errors, warnings, and info messages
436
- verbosity: "verbose",
437
- },
438
- platforms: {
439
- ts: {
440
- transformGroup: "custom/js",
441
- prefix: "G",
442
- buildPath: `./dist/js/${theme}/`,
443
- filter: {
444
- attributes: {
445
- category: "theme",
446
- },
447
- },
448
- files: [
449
- {
450
- destination: "style-dictionary.js",
451
- format: "javascript/es6",
452
- },
453
- {
454
- destination: "style-dictionary.d.ts",
455
- format: "typescript/es6-declarations",
456
- },
457
- ],
458
- },
459
- css: {
460
- transformGroup: "custom/css",
461
- prefix: "g",
462
- buildPath: `./dist/css/${theme}/`,
463
- files: [
464
- {
465
- destination: "tokens.css",
466
- format: "css/custom-variables",
467
- },
468
- {
469
- destination: `${theme}.css`,
470
- format: "css/variables-themed",
471
- },
472
- ],
473
- },
474
- json: {
475
- transformGroup: "custom/css",
476
- prefix: "g",
477
- buildPath: `./dist/json/${theme}/`,
478
- files: [
479
- {
480
- destination: "tokens.json",
481
- format: "json/flat/custom",
482
- },
483
- ],
484
- },
485
- },
486
- };
487
-
488
- return config;
489
- };
490
-
491
- /**
492
- * Build the tokens
493
- * 1) If no theme is specified, build all themes
494
- * 2) Otherwise, build the specified theme
495
- */
496
- if (!theme) {
497
- console.log("🚧 No theme specified, building all themes...");
498
- AVAILABLE_THEMES.forEach((themeName) => {
499
- console.log(`\nšŸ—ļø Building ${themeName.toUpperCase()} theme`);
500
- const themeConfig = getStyleDictionaryConfig(themeName);
501
- const StyleDictionaryExtended = new StyleDictionary(themeConfig);
502
- StyleDictionaryExtended.buildAllPlatforms();
503
- });
504
- } else {
505
- console.log(`🚧 Building ${theme.toUpperCase()} theme`);
506
- const config = getStyleDictionaryConfig(theme);
507
- const StyleDictionaryExtended = new StyleDictionary(config);
508
- StyleDictionaryExtended.buildAllPlatforms();
509
- }