@esri/calcite-design-tokens 1.1.1-next.2 → 2.0.0

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 (153) hide show
  1. package/README.md +7 -9
  2. package/dist/css/breakpoint.css +29 -0
  3. package/dist/css/classes.css +327 -0
  4. package/dist/css/core.css +311 -0
  5. package/dist/css/dark.css +47 -0
  6. package/dist/css/global.css +96 -0
  7. package/dist/css/index.css +184 -0
  8. package/dist/css/light.css +47 -0
  9. package/dist/docs/core.json +8134 -0
  10. package/dist/docs/global.json +6617 -0
  11. package/dist/es6/core.d.ts +309 -0
  12. package/dist/es6/core.js +309 -0
  13. package/dist/es6/global.d.ts +202 -0
  14. package/dist/es6/global.js +202 -0
  15. package/dist/js/core.d.ts +421 -0
  16. package/dist/js/core.js +8208 -0
  17. package/dist/js/global.d.ts +330 -0
  18. package/dist/js/global.js +6689 -0
  19. package/dist/scss/breakpoints.scss +37 -0
  20. package/dist/scss/core.scss +309 -0
  21. package/dist/scss/dark.scss +45 -0
  22. package/dist/scss/global.scss +94 -0
  23. package/dist/scss/index.scss +96 -0
  24. package/dist/scss/light.scss +45 -0
  25. package/dist/scss/mixins.scss +342 -0
  26. package/package.json +7 -21
  27. package/.eslintrc.cjs +0 -85
  28. package/.turbo/turbo-build.log +0 -7034
  29. package/.turbo/turbo-test.log +0 -15
  30. package/CHANGELOG.md +0 -33
  31. package/CONTRIBUTING.md +0 -41
  32. package/dist/css/brand-light.css +0 -9
  33. package/dist/css/calcite-dark.css +0 -504
  34. package/dist/css/calcite-headless.css +0 -2615
  35. package/dist/css/calcite-light.css +0 -507
  36. package/dist/es6/brand-light.d.ts +0 -7
  37. package/dist/es6/brand-light.js +0 -7
  38. package/dist/es6/calcite-dark.d.ts +0 -502
  39. package/dist/es6/calcite-dark.js +0 -502
  40. package/dist/es6/calcite-headless.d.ts +0 -2613
  41. package/dist/es6/calcite-headless.js +0 -2613
  42. package/dist/es6/calcite-light.d.ts +0 -505
  43. package/dist/es6/calcite-light.js +0 -505
  44. package/dist/js/brand-light.d.ts +0 -72
  45. package/dist/js/brand-light.js +0 -95
  46. package/dist/js/calcite-dark.d.ts +0 -563
  47. package/dist/js/calcite-dark.js +0 -10024
  48. package/dist/js/calcite-headless.d.ts +0 -1730
  49. package/dist/js/calcite-headless.js +0 -50082
  50. package/dist/js/calcite-light.d.ts +0 -544
  51. package/dist/js/calcite-light.js +0 -10090
  52. package/dist/scss/calcite-dark.scss +0 -535
  53. package/dist/scss/calcite-headless.scss +0 -3012
  54. package/dist/scss/calcite-light.scss +0 -538
  55. package/jest.config.json +0 -16
  56. package/src/$metadata.json +0 -76
  57. package/src/$themes.json +0 -2363
  58. package/src/brand/dark.json +0 -1
  59. package/src/brand/global.json +0 -1
  60. package/src/brand/light.json +0 -20
  61. package/src/calcite/dark.json +0 -2488
  62. package/src/calcite/light.json +0 -2508
  63. package/src/component/accordion-item.json +0 -172
  64. package/src/component/accordion.json +0 -192
  65. package/src/component/action-bar-grid.json +0 -66
  66. package/src/component/action-bar.json +0 -66
  67. package/src/component/action-pad-grid.json +0 -80
  68. package/src/component/action-pad.json +0 -80
  69. package/src/component/action.json +0 -156
  70. package/src/component/alert.json +0 -258
  71. package/src/component/avatar.json +0 -140
  72. package/src/component/block-section.json +0 -124
  73. package/src/component/block.json +0 -198
  74. package/src/component/button.json +0 -650
  75. package/src/component/card.json +0 -116
  76. package/src/component/checkbox.json +0 -110
  77. package/src/component/chip.json +0 -382
  78. package/src/component/color-picker.json +0 -148
  79. package/src/component/combobox.json +0 -152
  80. package/src/component/date-picker.json +0 -354
  81. package/src/component/dropdown-item.json +0 -384
  82. package/src/component/dropdown.json +0 -58
  83. package/src/component/fab.json +0 -490
  84. package/src/component/filter.json +0 -174
  85. package/src/component/icon.json +0 -18
  86. package/src/component/input-date-picker.json +0 -224
  87. package/src/component/input-datetime-local.json +0 -230
  88. package/src/component/input-email.json +0 -244
  89. package/src/component/input-file.json +0 -244
  90. package/src/component/input-message.json +0 -72
  91. package/src/component/input-month.json +0 -244
  92. package/src/component/input-number.json +0 -244
  93. package/src/component/input-password.json +0 -244
  94. package/src/component/input-search.json +0 -244
  95. package/src/component/input-telephone.json +0 -244
  96. package/src/component/input-text.json +0 -244
  97. package/src/component/input-time.json +0 -1
  98. package/src/component/input-week.json +0 -244
  99. package/src/component/label.json +0 -26
  100. package/src/component/link.json +0 -44
  101. package/src/component/loader.json +0 -130
  102. package/src/component/modal.json +0 -278
  103. package/src/component/notice.json +0 -280
  104. package/src/component/pagination.json +0 -152
  105. package/src/component/panel-header.json +0 -88
  106. package/src/component/popover.json +0 -170
  107. package/src/component/radio.json +0 -124
  108. package/src/component/rating.json +0 -243
  109. package/src/component/scrim.json +0 -18
  110. package/src/component/segmented-control.json +0 -154
  111. package/src/component/slider-histogram-range.json +0 -284
  112. package/src/component/slider-histogram.json +0 -280
  113. package/src/component/slider-range.json +0 -226
  114. package/src/component/slider.json +0 -226
  115. package/src/component/split-button.json +0 -830
  116. package/src/component/stepper-item.json +0 -372
  117. package/src/component/stepper.json +0 -152
  118. package/src/component/switch.json +0 -178
  119. package/src/component/tab-title.json +0 -228
  120. package/src/component/tabs.json +0 -242
  121. package/src/component/textarea.json +0 -200
  122. package/src/component/time-picker.json +0 -138
  123. package/src/component/tip-manager.json +0 -118
  124. package/src/component/tip.json +0 -114
  125. package/src/component/tooltip.json +0 -66
  126. package/src/component/tree-item.json +0 -176
  127. package/src/core.json +0 -1833
  128. package/src/semantic.json +0 -1709
  129. package/support/run.ts +0 -16
  130. package/support/tests/__snapshots__/index.spec.ts.snap +0 -88066
  131. package/support/tests/index.spec.ts +0 -102
  132. package/support/token-transformer/format/javascript.ts +0 -22
  133. package/support/token-transformer/format/scss.ts +0 -81
  134. package/support/token-transformer/getThemes.ts +0 -41
  135. package/support/token-transformer/parse/expandComposites.test.ts +0 -144
  136. package/support/token-transformer/parse/expandComposites.ts +0 -72
  137. package/support/token-transformer/sd-run.ts +0 -191
  138. package/support/token-transformer/transform/nameCamelCase.test.ts +0 -36
  139. package/support/token-transformer/transform/nameCamelCase.ts +0 -15
  140. package/support/token-transformer/transform/nameKebabCase.test.ts +0 -36
  141. package/support/token-transformer/transform/nameKebabCase.ts +0 -26
  142. package/support/token-transformer/utils/compositeTokens.test.ts +0 -133
  143. package/support/token-transformer/utils/compositeTokens.ts +0 -103
  144. package/support/token-transformer/utils/convertTokenToStyleDictionaryFormat.ts +0 -20
  145. package/support/token-transformer/utils/matchList.ts +0 -11
  146. package/support/token-transformer/utils/parseName.ts +0 -18
  147. package/support/token-transformer/utils/parseTokenPath.ts +0 -19
  148. package/support/token-transformer/utils/regex.ts +0 -9
  149. package/support/token-transformer/utils/sortAllTokens.ts +0 -12
  150. package/support/token-transformer/utils/transformOptions.ts +0 -31
  151. package/tsconfig-base.json +0 -17
  152. package/tsconfig-eslint.json +0 -4
  153. package/tsconfig.json +0 -4
@@ -1,102 +0,0 @@
1
- import { readFileSync } from "fs";
2
- import { resolve } from "path";
3
-
4
- describe("generated tokens", () => {
5
- describe("CSS", () => {
6
- it("global should match", () => {
7
- let global = readFileSync(resolve(__dirname, "../../dist/css/calcite-headless.css"), "utf-8");
8
- global = global.slice(global.indexOf("*/") + 1);
9
- expect(global).toMatchSnapshot();
10
- });
11
- it("light should match", () => {
12
- let light = readFileSync(resolve(__dirname, "../../dist/css/calcite-light.css"), "utf-8");
13
- light = light.slice(light.indexOf("*/") + 1);
14
- expect(light).toMatchSnapshot();
15
- });
16
- it("dark should match", () => {
17
- let dark = readFileSync(resolve(__dirname, "../../dist/css/calcite-light.css"), "utf-8");
18
- dark = dark.slice(dark.indexOf("*/") + 1);
19
- expect(dark).toMatchSnapshot();
20
- });
21
- });
22
-
23
- describe("SCSS", () => {
24
- it("global should match", () => {
25
- let global = readFileSync(resolve(__dirname, "../../dist/scss/calcite-headless.scss"), "utf-8");
26
- global = global.slice(global.indexOf("*/") + 1);
27
- expect(global).toMatchSnapshot();
28
- });
29
- it("light should match", () => {
30
- let light = readFileSync(resolve(__dirname, "../../dist/scss/calcite-light.scss"), "utf-8");
31
- light = light.slice(light.indexOf("*/") + 1);
32
- expect(light).toMatchSnapshot();
33
- });
34
- it("dark should match", () => {
35
- let dark = readFileSync(resolve(__dirname, "../../dist/scss/calcite-light.scss"), "utf-8");
36
- dark = dark.slice(dark.indexOf("*/") + 1);
37
- expect(dark).toMatchSnapshot();
38
- });
39
- });
40
-
41
- describe("JS", () => {
42
- it("global should match", () => {
43
- let global = readFileSync(resolve(__dirname, "../../dist/js/calcite-headless.js"), "utf-8");
44
- global = global.slice(global.indexOf("*/") + 1);
45
- expect(global).toMatchSnapshot();
46
- });
47
- it("light should match", () => {
48
- let light = readFileSync(resolve(__dirname, "../../dist/js/calcite-light.js"), "utf-8");
49
- light = light.slice(light.indexOf("*/") + 1);
50
- expect(light).toMatchSnapshot();
51
- });
52
- it("dark should match", () => {
53
- let dark = readFileSync(resolve(__dirname, "../../dist/js/calcite-light.js"), "utf-8");
54
- dark = dark.slice(dark.indexOf("*/") + 1);
55
- expect(dark).toMatchSnapshot();
56
- });
57
- it("types should match", () => {
58
- let global = readFileSync(resolve(__dirname, "../../dist/js/calcite-headless.d.ts"), "utf-8");
59
- let light = readFileSync(resolve(__dirname, "../../dist/js/calcite-light.d.ts"), "utf-8");
60
- let dark = readFileSync(resolve(__dirname, "../../dist/js/calcite-dark.d.ts"), "utf-8");
61
-
62
- global = global.slice(global.indexOf("*/") + 1);
63
- light = light.slice(light.indexOf("*/") + 1);
64
- dark = dark.slice(dark.indexOf("*/") + 1);
65
-
66
- expect(global).toMatchSnapshot();
67
- expect(light).toMatchSnapshot();
68
- expect(dark).toMatchSnapshot();
69
- });
70
- });
71
-
72
- describe("ES6", () => {
73
- it("global should match", () => {
74
- let global = readFileSync(resolve(__dirname, "../../dist/es6/calcite-headless.js"), "utf-8");
75
- global = global.slice(global.indexOf("*/") + 1);
76
- expect(global).toMatchSnapshot();
77
- });
78
- it("light should match", () => {
79
- let light = readFileSync(resolve(__dirname, "../../dist/es6/calcite-light.js"), "utf-8");
80
- light = light.slice(light.indexOf("*/") + 1);
81
- expect(light).toMatchSnapshot();
82
- });
83
- it("dark should match", () => {
84
- let dark = readFileSync(resolve(__dirname, "../../dist/es6/calcite-light.js"), "utf-8");
85
- dark = dark.slice(dark.indexOf("*/") + 1);
86
- expect(dark).toMatchSnapshot();
87
- });
88
- it("types should match", () => {
89
- let light = readFileSync(resolve(__dirname, "../../dist/es6/calcite-light.d.ts"), "utf-8");
90
- let dark = readFileSync(resolve(__dirname, "../../dist/es6/calcite-dark.d.ts"), "utf-8");
91
- let global = readFileSync(resolve(__dirname, "../../dist/es6/calcite-headless.d.ts"), "utf-8");
92
-
93
- global = global.slice(global.indexOf("*/") + 1);
94
- light = light.slice(light.indexOf("*/") + 1);
95
- dark = dark.slice(dark.indexOf("*/") + 1);
96
-
97
- expect(global).toMatchSnapshot();
98
- expect(light).toMatchSnapshot();
99
- expect(dark).toMatchSnapshot();
100
- });
101
- });
102
- });
@@ -1,22 +0,0 @@
1
- import StyleDictionary, { Dictionary, File } from "style-dictionary";
2
- import { default as JsonToTS } from "json-to-ts";
3
-
4
- type FormatOptions = { dictionary: Dictionary; file: File };
5
-
6
- export function formatJs({ dictionary, file }: FormatOptions): string {
7
- return (
8
- StyleDictionary.formatHelpers.fileHeader({ file }) +
9
- "export default" +
10
- JSON.stringify(dictionary.tokens, null, 2) +
11
- ";\n"
12
- );
13
- }
14
-
15
- export function formatTs({ dictionary, file }: FormatOptions): string {
16
- return (
17
- StyleDictionary.formatHelpers.fileHeader({ file }) +
18
- "declare const root: RootObject\n" +
19
- "export default root\n" +
20
- JsonToTS(dictionary.properties).join("\n")
21
- );
22
- }
@@ -1,81 +0,0 @@
1
- import { pascalCase, sentenceCase } from "change-case";
2
- import StyleDictionary, { Dictionary, File, Platform, Options } from "style-dictionary";
3
- import { sortAllTokens } from "../utils/sortAllTokens.js";
4
-
5
- const regexThemeGroup = /calcite|brand/gi;
6
- const regexFileNameWithoutExtension = /\w+(?=\.\w+$)/gi;
7
-
8
- /**
9
- * Exports SCSS style formats
10
- *
11
- * @param {object} fileInfo the file object
12
- * @param {Dictionary} fileInfo.dictionary the Style Dictionary object
13
- * @param {File} fileInfo.file information about the file to be generated
14
- * @param {Platform} [fileInfo.platform] the platform to generate the asset for
15
- * @param {Options} fileInfo.options the Style Dictionary format options passed from the config
16
- * @returns {string} a string that is passed to fs.writeFileSync
17
- */
18
- export function formatSCSS(fileInfo: {
19
- dictionary: Dictionary;
20
- file: File;
21
- platform?: Platform;
22
- options: Options & { themeable?: boolean };
23
- }): string {
24
- const { dictionary, file, options } = fileInfo;
25
- const { outputReferences } = options;
26
- const themeName = pascalCase(
27
- sentenceCase(file.destination.match(regexFileNameWithoutExtension)[0])
28
- .split(" ")
29
- .filter((n) => !regexThemeGroup.test(n))
30
- .join(" ")
31
- ).toLowerCase();
32
- const sassProps = StyleDictionary.formatHelpers.createPropertyFormatter({
33
- outputReferences,
34
- dictionary,
35
- format: "sass",
36
- });
37
- const cssProps = StyleDictionary.formatHelpers.createPropertyFormatter({
38
- outputReferences,
39
- dictionary,
40
- format: "css",
41
- });
42
- const sortedTokens = sortAllTokens(dictionary, outputReferences);
43
- const coreTokens = [...sortedTokens].reduce(
44
- (acc, token) => {
45
- token.value = token.value.includes(" ") ? `"${token.value}"` : token.value === "Demi" ? 600 : token.value;
46
- acc[1].push(cssProps(token));
47
-
48
- if (token.filePath.includes("core")) {
49
- const sassToken = { ...token };
50
- const path = sassToken.path.filter((p) => !/(core|default|font$)/.test(p));
51
- sassToken.name = sassToken.type === "color" ? path.slice(-1).join("-") : path.join("-");
52
- sassToken.original.value = sassToken.original.value[0] === "{" ? sassToken.value : sassToken.original.value;
53
- acc[0].push(sassProps(sassToken));
54
- }
55
-
56
- if (/dark|light/.test(token.filePath) && !token.path.includes("component")) {
57
- const sassToken = { ...token };
58
- const path = sassToken.path.reduce((acc, p) => {
59
- if (p === "default") {
60
- return acc;
61
- }
62
- acc.push(p === "color" ? "ui" : p);
63
- return acc;
64
- }, []);
65
- path.push(token.filePath.includes("dark") ? "dark" : "light");
66
- sassToken.name = path.join("-");
67
- acc[0].push(sassProps(sassToken));
68
- }
69
-
70
- return acc;
71
- },
72
- [[], []]
73
- );
74
-
75
- return `${StyleDictionary.formatHelpers.fileHeader({ file })}
76
- ${coreTokens[0].join("\n")}
77
-
78
- @mixin calcite-theme-${themeName}() {
79
- ${coreTokens[1].join("\n")}
80
- }`;
81
- }
@@ -1,41 +0,0 @@
1
- import { Options } from "style-dictionary";
2
-
3
- export interface ThemeFileInterface {
4
- id: string;
5
- name: string;
6
- selectedTokenSets: Record<string, "enabled" | "disabled" | "source">;
7
- $figmaStyleReferences?: Record<string, string>;
8
- }
9
-
10
- export type Theme = {
11
- name: string;
12
- enabled: string[];
13
- disabled: string[];
14
- source: string[];
15
- id?: string;
16
- options?: Options;
17
- };
18
-
19
- /**
20
- *
21
- * @param {ThemeFileInterface} themes an array of Figma Token Studio theme definition objects
22
- * @returns {Array} an array of Style Dictionary theme definition objects
23
- */
24
- export async function getThemes(themes: ThemeFileInterface[]): Promise<Theme[]> {
25
- return themes.map((themeConfig) => {
26
- const themeTypes = { enabled: [], disabled: [], source: [] };
27
- const { name, id, selectedTokenSets } = themeConfig;
28
- const { enabled, disabled, source } = Object.entries(selectedTokenSets).reduce((acc, [key, value]) => {
29
- acc[value].push(key);
30
- return acc;
31
- }, themeTypes);
32
-
33
- return {
34
- name,
35
- id,
36
- enabled,
37
- disabled,
38
- source,
39
- };
40
- });
41
- }
@@ -1,144 +0,0 @@
1
- const mockCorrectTypeCompoundToken = {
2
- core: {
3
- 1: {
4
- type: "sizing",
5
- value: "10",
6
- },
7
- },
8
- compound: {
9
- value: {
10
- fontFamily: "$core.font.font-family.primary",
11
- fontWeight: "$core.font.font-weight.light",
12
- lineHeight: "$core.font.line-height.fixed.0",
13
- fontSize: "$core.font.font-size.0",
14
- letterSpacing: "$core.font.letter-spacing.normal",
15
- paragraphSpacing: "$core.font.paragraph-spacing.normal",
16
- textDecoration: "$core.font.text-decoration.none",
17
- textCase: "$core.font.text-case.none",
18
- },
19
- type: "typography",
20
- },
21
- };
22
- const mockTransformedCompoundTokens = {
23
- core: {
24
- 1: {
25
- type: "sizing",
26
- value: "10",
27
- },
28
- },
29
- compound: {
30
- "font-family": {
31
- value: "$core.font.font-family.primary",
32
- type: "font-family",
33
- },
34
- "font-weight": {
35
- value: "$core.font.font-weight.light",
36
- type: "font-weights",
37
- },
38
- "line-height": {
39
- value: "$core.font.line-height.fixed.0",
40
- type: "line-heights",
41
- },
42
- "font-size": {
43
- value: "$core.font.font-size.0",
44
- type: "font-size",
45
- },
46
- "letter-spacing": {
47
- value: "$core.font.letter-spacing.normal",
48
- type: "letter-spacing",
49
- },
50
- "paragraph-spacing": {
51
- value: "$core.font.paragraph-spacing.normal",
52
- type: "paragraph-spacing",
53
- },
54
- "text-decoration": {
55
- value: "$core.font.text-decoration.none",
56
- type: "font-style",
57
- },
58
- "text-case": {
59
- value: "$core.font.text-case.none",
60
- type: "text-case",
61
- },
62
- },
63
- };
64
-
65
- const handleTokenStudioVariables = jest.fn((token) => (token.includes("$") ? `{${token.replace(/\$/g, "")}}` : token));
66
- const convertTokenToStyleDictionaryFormat = jest.fn(() => handleTokenStudioVariables);
67
- const shouldExpand = jest.fn().mockReturnValue(true);
68
- const expandToken = jest.fn().mockReturnValue(mockTransformedCompoundTokens);
69
-
70
- jest.mock("../utils/compositeTokens.js", () => {
71
- const originalModule = jest.requireActual("../utils/compositeTokens.js");
72
- return {
73
- __esModule: false,
74
- ...originalModule,
75
- shouldExpand,
76
- expandToken,
77
- };
78
- });
79
-
80
- jest.mock("../utils/convertTokenToStyleDictionaryFormat.js", () => {
81
- const originalModule = jest.requireActual("../utils/convertTokenToStyleDictionaryFormat.js");
82
- return {
83
- __esModule: false,
84
- ...originalModule,
85
- convertTokenToStyleDictionaryFormat,
86
- };
87
- });
88
-
89
- import * as expandComposites from "./expandComposites";
90
-
91
- describe("expand token dictionary", () => {
92
- beforeEach(() => {
93
- jest.clearAllMocks();
94
- });
95
-
96
- it("should not add placeholder elements", () => {
97
- const placeolderToken = {
98
- "[placeholder-component]": {
99
- type: "other",
100
- value: "#333",
101
- },
102
- };
103
- const placeholderValue = {
104
- compoonent: {
105
- type: "other",
106
- value: "[placholder-value]",
107
- },
108
- };
109
-
110
- // @ts-expect-error - it's fine.
111
- const testExpandPlaceholderKey = expandComposites.expandComposites(placeolderToken, "./fakePath");
112
- // @ts-expect-error - it's fine.
113
- const testExpandPlaceholderValue = expandComposites.expandComposites(placeholderValue, "./fakePath");
114
-
115
- expect(testExpandPlaceholderKey).toMatchObject({});
116
- expect(testExpandPlaceholderValue).toMatchObject({});
117
- });
118
-
119
- it('should loop through a dictionary and run "shouldExpand" and "expandToken" on each composite token', () => {
120
- // @ts-expect-error - it's fine.
121
- const testExpandComposite = expandComposites.expandComposites(mockCorrectTypeCompoundToken, "./fakePath");
122
- expect(handleTokenStudioVariables).toHaveBeenCalledTimes(1);
123
- expect(shouldExpand).toHaveBeenCalledTimes(1);
124
- expect(expandToken).toHaveBeenCalledTimes(1);
125
- expect(testExpandComposite).toMatchObject(mockTransformedCompoundTokens);
126
- });
127
-
128
- it("should not run expand token on unrecognized types", () => {
129
- const mockDictionary = {
130
- core: {
131
- type: "customType",
132
- value: {
133
- fontFamily: "Avanir",
134
- fontSize: "12px",
135
- },
136
- },
137
- };
138
- // @ts-expect-error - it's fine this is a test
139
- const testExpandComposite = expandComposites.expandComposites(mockDictionary, "./fakePath");
140
- expect(shouldExpand).not.toHaveBeenCalled();
141
- expect(expandToken).not.toHaveBeenCalled();
142
- expect(testExpandComposite).toMatchObject(mockDictionary);
143
- });
144
- });
@@ -1,72 +0,0 @@
1
- import { DeepKeyTokenMap } from "@tokens-studio/types";
2
- import { DesignToken } from "style-dictionary/types/DesignToken.js";
3
- import {
4
- TransformOptions,
5
- ExpandablesAsStrings,
6
- Expandables,
7
- expandablesAsStringsArr,
8
- } from "../utils/transformOptions.js";
9
- import { matchPlaceholderElement, tokenStudioCustomVariableIndicator } from "../utils/regex.js";
10
- import { shouldExpand, expandToken } from "../utils/compositeTokens.js";
11
- import { convertTokenToStyleDictionaryFormat } from "../utils/convertTokenToStyleDictionaryFormat.js";
12
-
13
- /**
14
- * Figma Token Studio creates an odd type of composite token where the "value" may contain an object of "key: value" pairs rather than a sting.
15
- * Here we will lift these composite tokens up to match the Style Dictionary format.
16
- *
17
- * @param {DeepKeyTokenMap} dictionary the raw JSON object in the token files. We will assume this is a token object generated by Figma Token Studio and may require composite tokens to be expanded.
18
- * @param {string} filePath the absolute file path to the JSON token file.
19
- * @param {TransformOptions} transformOpts the options passed in from the Style Dictionary config and runner
20
- * @returns {DeepKeyTokenMap} a token object where any Figma Token Studio composite tokens now match the Style Dictionary token format
21
- */
22
- export function expandComposites(
23
- dictionary: DeepKeyTokenMap,
24
- filePath: string,
25
- transformOpts: TransformOptions = {}
26
- ): DeepKeyTokenMap {
27
- const opts = {
28
- ...transformOpts,
29
- expand: {
30
- composition: true,
31
- typography: false,
32
- border: false,
33
- shadow: false,
34
- ...transformOpts.expand,
35
- },
36
- };
37
- const returnSlice: DeepKeyTokenMap = {};
38
- const handleTokenStudioVariables = convertTokenToStyleDictionaryFormat(tokenStudioCustomVariableIndicator);
39
- const newDictionary = Object.entries(dictionary).reduce((acc, [key, token]) => {
40
- const { type } = token;
41
-
42
- if (
43
- matchPlaceholderElement.test(`${key}`) ||
44
- (typeof token.value === "string" && matchPlaceholderElement.test(`${token.value}`))
45
- ) {
46
- return acc;
47
- }
48
-
49
- if (token.value && type) {
50
- const includesType = expandablesAsStringsArr.includes(`${type}`);
51
-
52
- if (includesType) {
53
- const expandType = (type as ExpandablesAsStrings) === "boxShadow" ? "shadow" : type;
54
- const expand = shouldExpand<Expandables>(token as Expandables, opts.expand[`${expandType}`], filePath);
55
- if (expand) {
56
- const expandedToken = expandToken(token as DesignToken, expandType === "shadow", handleTokenStudioVariables);
57
- return expandedToken;
58
- }
59
- } else if (typeof token.value === "string") {
60
- token.value = handleTokenStudioVariables(token.value);
61
- acc[key] = token;
62
- } else {
63
- acc[key] = token;
64
- }
65
- } else if (typeof token === "object") {
66
- acc[key] = expandComposites(token as DeepKeyTokenMap, filePath, transformOpts);
67
- }
68
- return acc;
69
- }, returnSlice);
70
-
71
- return newDictionary || {};
72
- }
@@ -1,191 +0,0 @@
1
- import { registerTransforms } from "@tokens-studio/sd-transforms";
2
- import StyleDictionary from "style-dictionary";
3
- import { expandComposites } from "./parse/expandComposites.js";
4
- import { formatSCSS } from "./format/scss.js";
5
- import { matchExclusions } from "./utils/regex.js";
6
- import { matchList } from "./utils/matchList.js";
7
- import { nameCamelCase } from "./transform/nameCamelCase.js";
8
- import { nameKebabCase } from "./transform/nameKebabCase.js";
9
- import { parseName } from "./utils/parseName.js";
10
- import { Theme } from "./getThemes.js";
11
- import { formatJs, formatTs } from "./format/javascript.js";
12
-
13
- /**
14
- * Style Dictionary runner configuration overrides.
15
- *
16
- * @param {string} tokenDir the directory containing design token files
17
- * @param {string} buildPath the directory to write generated assets to
18
- * @param {Theme} theme the theme configuration to use to generate the platform asset files
19
- * @param {string} theme.name the name of the theme. This will be used as the basis for the generated asset file names.
20
- * @param {string[]} theme.enabled an array of partial file names matching the token files which should be included in the output
21
- * @param {string[]} theme.disabled an array of partial file names matching the token files which should explicitly not be included in the output
22
- * @param {string[]} theme.source an array of partial file names matching the token files which should not always be included in the output but who's values should be used for variables references in the "enabled" files
23
- */
24
- export const run = async (
25
- tokenDir = "tokens",
26
- buildPath = "dist",
27
- theme: Pick<Theme, "enabled" | "disabled" | "name" | "source">
28
- ): Promise<void> => {
29
- const fileName = parseName(theme.name);
30
- const include = theme.source.map((tokenFile) => `${tokenDir}/${tokenFile}.json`);
31
- const source = theme.enabled.map((tokenFile) => `${tokenDir}/${tokenFile}.json`);
32
- const options = {
33
- enabled: theme.enabled,
34
- source: theme.source,
35
- disabled: theme.disabled,
36
- outputReferences: false,
37
- sourceReferencesOnly: false,
38
- };
39
-
40
- // Here we are registering the Transforms provided by Token Studio
41
- // https://github.com/tokens-studio/sd-transforms
42
- // @ts-expect-error - @token-studio does not keep their types up to date.
43
- await registerTransforms(StyleDictionary, {
44
- expand: false,
45
- });
46
-
47
- // Register custom formatter https://amzn.github.io/style-dictionary/#/formats?id=custom-formats
48
- StyleDictionary.registerFormat({
49
- name: "calcite/scss",
50
- formatter: formatSCSS,
51
- });
52
-
53
- StyleDictionary.registerFormat({
54
- name: "calcite/js-module",
55
- formatter: formatJs,
56
- });
57
-
58
- StyleDictionary.registerFormat({
59
- name: "calcite/ts-module",
60
- formatter: formatTs,
61
- });
62
-
63
- // Registering Style Dictionary transformers https://amzn.github.io/style-dictionary/#/transforms?id=defining-custom-transforms
64
- StyleDictionary.registerTransform({
65
- name: "name/calcite/camel",
66
- type: "name",
67
- transformer: nameCamelCase,
68
- });
69
-
70
- StyleDictionary.registerTransform({
71
- name: "name/calcite/kebab",
72
- type: "name",
73
- transformer: nameKebabCase,
74
- });
75
-
76
- StyleDictionary.registerFilter({
77
- name: "filterSource",
78
- matcher: (token) => token.isSource,
79
- });
80
-
81
- // We are programmatically creating the Style Dictionary configuration here
82
- // https://amzn.github.io/style-dictionary/#/config
83
- const sd = StyleDictionary.extend({
84
- source,
85
- include,
86
- platforms: {
87
- js: {
88
- buildPath: `${buildPath}/js/`,
89
- files: [
90
- {
91
- destination: `${fileName}.js`,
92
- format: "calcite/js-module",
93
- filter: "filterSource",
94
- },
95
- {
96
- destination: `${fileName}.d.ts`,
97
- format: "calcite/ts-module",
98
- filter: "filterSource",
99
- },
100
- ],
101
- },
102
- es6: {
103
- transformGroup: "js",
104
- buildPath: `${buildPath}/es6/`,
105
- files: [
106
- {
107
- format: "javascript/es6",
108
- destination: `${fileName}.js`,
109
- filter: "filterSource",
110
- options: { ...options, outputReferences: true },
111
- },
112
- {
113
- format: "typescript/es6-declarations",
114
- destination: `${fileName}.d.ts`,
115
- filter: "filterSource",
116
- options: { ...options, outputReferences: true },
117
- },
118
- ],
119
- },
120
- css: {
121
- prefix: "calcite",
122
- transforms: [
123
- "ts/descriptionToComment",
124
- "ts/size/px",
125
- "ts/opacity",
126
- "ts/size/lineheight",
127
- "ts/type/fontWeight",
128
- "ts/resolveMath",
129
- "ts/size/css/letterspacing",
130
- "ts/color/css/hexrgba",
131
- "ts/color/modifiers",
132
- "name/calcite/kebab",
133
- ],
134
- buildPath: `${buildPath}/css/`,
135
- files: [
136
- {
137
- destination: `${fileName}.css`,
138
- format: "css/variables",
139
- filter: /headless/gi.test(fileName) ? null : "filterSource",
140
- options: /headless/gi.test(fileName) ? { ...options, outputReferences: true } : options,
141
- },
142
- ],
143
- },
144
- scss: {
145
- prefix: "calcite",
146
- transforms: [
147
- "ts/descriptionToComment",
148
- "ts/size/px",
149
- "ts/opacity",
150
- "ts/size/lineheight",
151
- "ts/type/fontWeight",
152
- "ts/resolveMath",
153
- "ts/size/css/letterspacing",
154
- "ts/color/css/hexrgba",
155
- "ts/color/modifiers",
156
- "name/calcite/kebab",
157
- ],
158
- buildPath: `${buildPath}/scss/`,
159
- files: [
160
- {
161
- destination: `${fileName}.scss`,
162
- format: "calcite/scss",
163
- filter: /headless/gi.test(fileName) ? null : "filterSource",
164
- options: /headless/gi.test(fileName) ? { ...options, outputReferences: true } : options,
165
- },
166
- ],
167
- },
168
- },
169
- parsers: [
170
- {
171
- pattern: /\.json$/,
172
- parse: (file) => {
173
- if (matchList(file.filePath, [...include, ...theme.source, ...theme.enabled], matchExclusions)) {
174
- const obj = JSON.parse(file.contents);
175
- const expanded = expandComposites(obj, file.filePath);
176
- return expanded;
177
- }
178
-
179
- return {};
180
- },
181
- },
182
- ],
183
- });
184
-
185
- try {
186
- sd.cleanAllPlatforms();
187
- sd.buildAllPlatforms();
188
- } catch (error) {
189
- console.error(error);
190
- }
191
- };