@apify/ui-library 0.71.1-featcolortokens-178953.55 → 0.71.1-featcolortokens-178953.56

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apify/ui-library",
3
- "version": "0.71.1-featcolortokens-178953.55+af467915b4b",
3
+ "version": "0.71.1-featcolortokens-178953.56+f2721db5883",
4
4
  "description": "React UI library used by apify.com",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -69,5 +69,5 @@
69
69
  "typescript": "^5.1.6",
70
70
  "typescript-eslint": "^8.24.0"
71
71
  },
72
- "gitHead": "af467915b4b5c3c48c090c932c5f9b51ab765411"
72
+ "gitHead": "f2721db58831367f5fa059e0fa1e1d9224ff5624"
73
73
  }
@@ -1,20 +1,24 @@
1
1
  import StyleDictionary from 'style-dictionary';
2
2
 
3
+ const DO_NOT_EXPORT_COMMENT = `/**
4
+ * Do not edit directly, this file was auto-generated.
5
+ */
6
+ `;
7
+
3
8
  function toCamelCase(str) {
4
9
  return str
5
10
  .toLowerCase()
6
11
  .replace(/[^a-zA-Z0-9]+(.)/g, (_, chr) => chr.toUpperCase());
7
12
  }
8
13
 
14
+ /**
15
+ * Converts an object to a TypeScript literal representation with proper indentation
16
+ * that can be written to a TypeScript file.
17
+ */
9
18
  function objectToTSLiteral(obj, indentLevel = 0) {
10
19
  const indent = (level) => ' '.repeat(level); // 2-space indent
11
20
 
12
- if (Array.isArray(obj)) {
13
- if (obj.length === 0) return '[]';
14
- return `[\n${obj
15
- .map((item) => indent(indentLevel + 1) + objectToTSLiteral(item, indentLevel + 1))
16
- .join(',\n')}\n${indent(indentLevel)}]`;
17
- } if (obj && typeof obj === 'object') {
21
+ if (obj && typeof obj === 'object') {
18
22
  const entries = Object.entries(obj);
19
23
  if (entries.length === 0) return '{}';
20
24
  return `{\n${entries
@@ -23,35 +27,40 @@ function objectToTSLiteral(obj, indentLevel = 0) {
23
27
  )
24
28
  .join('\n')}\n${indent(indentLevel)}}${indentLevel > 0 ? ',' : ''}`;
25
29
  } if (typeof obj === 'string') {
26
- return `'${obj}',`; // add quotes and escape
30
+ return `'${obj}',`;
27
31
  }
28
32
  return String(obj);
29
33
  }
30
34
 
35
+ /**
36
+ * Build color tokens for a given theme.
37
+ * @param theme {string} - The theme to build tokens, 'light' or 'dark'.
38
+ */
31
39
  async function buildTheme(theme) {
40
+ // Transform to replace 'semantic' and 'decorative' with 'color' in token names
41
+ // Example: 'semantic-neutral-text' becomes 'color-neutral-text'
32
42
  StyleDictionary.registerTransform({
33
43
  name: 'name/prefix-color-name',
34
44
  type: 'name',
35
45
  transform: (prop) => {
36
- // replace 'semantic' and 'decorative' with 'color' in the full token name
37
46
  return prop.name
38
47
  .replace(/^semantic/, 'color')
39
48
  .replace(/^decorative/, 'color');
40
49
  },
41
50
  });
42
51
 
52
+ // Format to generate typescript file that exports CSS variables as a string
53
+ // Example: export const tokens = `--color-neutral-text: #000; --color-primary: #fff;`
43
54
  StyleDictionary.registerFormat({
44
55
  name: 'typescript/css-variables-string',
45
56
  format: ({ dictionary, options }) => {
46
57
  const lines = dictionary.allTokens.map((token) => ` --${token.name}: ${token.$value};`);
47
- return `/**
48
- * Do not edit directly, this file was auto-generated.
49
- */
50
-
51
- export const ${options.varName ?? 'tokens'} = \`\n${lines.join('\n')}\n\`;\n`;
58
+ return `${DO_NOT_EXPORT_COMMENT}\nexport const ${options.varName ?? 'tokens'} = \`\n${lines.join('\n')}\n\`;\n`;
52
59
  },
53
60
  });
54
61
 
62
+ // Format to generate typescript file that exports CSS properties as an object
63
+ // Example: export const tokens = { colorNeutralText: 'var(--color-neutral-text)', colorPrimary: 'var(--color-primary)' };
55
64
  StyleDictionary.registerFormat({
56
65
  name: 'typescript/css-properties',
57
66
  format: ({ dictionary, options }) => {
@@ -69,14 +78,12 @@ export const ${options.varName ?? 'tokens'} = \`\n${lines.join('\n')}\n\`;\n`;
69
78
  current[path[path.length - 1]] = `var(--${token.name})`;
70
79
  });
71
80
 
72
- return `/**
73
- * Do not edit directly, this file was auto-generated.
74
- */
75
-
76
- export const ${options.varName ?? 'tokens'} = ${objectToTSLiteral(properties)} as const;\n`;
81
+ return `${DO_NOT_EXPORT_COMMENT}\nexport const ${options.varName ?? 'tokens'} = ${objectToTSLiteral(properties)} as const;\n`;
77
82
  },
78
83
  });
79
84
 
85
+ // Format to generate typescript file that exports CSS colors as an object
86
+ // Example: export const tokens = { colorNeutralText: '#000', colorPrimary: '#fff' };
80
87
  StyleDictionary.registerFormat({
81
88
  name: 'typescript/css-colors',
82
89
  format: ({ dictionary, options }) => {
@@ -87,24 +94,23 @@ export const ${options.varName ?? 'tokens'} = ${objectToTSLiteral(properties)} a
87
94
  properties[name] = token.$value;
88
95
  });
89
96
 
90
- return `/**
91
- * Do not edit directly, this file was auto-generated.
92
- */
93
-
94
- export const ${options.varName ?? 'tokens'} = ${objectToTSLiteral(properties)} as const;\n`;
97
+ return `${DO_NOT_EXPORT_COMMENT}\nexport const ${options.varName ?? 'tokens'} = ${objectToTSLiteral(properties)} as const;\n`;
95
98
  },
96
99
  });
97
100
 
101
+ // Select only tokens for semantic and decorative colors
98
102
  StyleDictionary.registerFilter({
99
103
  name: 'only-colors',
100
104
  filter: (token) => ['Semantic', 'Decorative'].includes(token.path[0]),
101
105
  });
102
106
 
107
+ // Select only tokens for palette colors
103
108
  StyleDictionary.registerFilter({
104
109
  name: 'only-palette',
105
110
  filter: (token) => ['Palette'].includes(token.path[0]),
106
111
  });
107
112
 
113
+ // Select only tokens for theme colors (Decorative and Palette)
108
114
  StyleDictionary.registerFilter({
109
115
  name: 'only-theme',
110
116
  filter: (token) => ['Decorative', 'Palette'].includes(token.path[0]),
@@ -1,29 +0,0 @@
1
- {
2
- "source": ["src/design_system/figma_color_tokens.light.json", "src/design_system/figma_color_tokens.dark.json"],
3
- "platforms": {
4
- "scss": {
5
- "transformGroup": "scss",
6
- "buildPath": "build/",
7
- "files": [
8
- {
9
- "destination": "scss/_variables.scss",
10
- "format": "css/variables"
11
- },
12
- {
13
- "destination": "scss/_variables.dark.scss",
14
- "format": "css/variables-dark"
15
- }
16
- ]
17
- },
18
- "android": {
19
- "transformGroup": "android",
20
- "buildPath": "build/android/",
21
- "files": [
22
- {
23
- "destination": "font_dimens.xml",
24
- "format": "android/fontDimens"
25
- }
26
- ]
27
- }
28
- }
29
- }