@atlaskit/tokens 0.2.0 → 0.4.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 (120) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +28 -0
  3. package/babel-plugin/package.json +7 -0
  4. package/css/atlassian-dark.css +89 -88
  5. package/css/atlassian-light.css +89 -88
  6. package/dist/cjs/artifacts/rename-mapping.js +23 -0
  7. package/dist/cjs/{tokens → artifacts}/token-default-values.js +22 -21
  8. package/dist/cjs/artifacts/token-names.js +101 -0
  9. package/dist/cjs/artifacts/tokens-raw/atlassian-dark.js +1786 -0
  10. package/dist/cjs/artifacts/tokens-raw/atlassian-light.js +1766 -0
  11. package/dist/cjs/artifacts/types.js +5 -0
  12. package/dist/cjs/{entry-points/token-default-values.js → babel-plugin/index.js} +2 -2
  13. package/dist/cjs/babel-plugin/plugin.js +176 -0
  14. package/dist/cjs/entry-points/rename-mapping.js +1 -1
  15. package/dist/cjs/entry-points/token-names.js +1 -1
  16. package/dist/cjs/figma/synchronize-figma-tokens.js +43 -41
  17. package/dist/cjs/get-token.js +1 -1
  18. package/dist/cjs/index.js +4 -4
  19. package/dist/cjs/tokens/atlassian-dark/utility/utility.js +3 -0
  20. package/dist/cjs/tokens/atlassian-light/utility/utility.js +3 -0
  21. package/dist/cjs/tokens/default/color/accent.js +26 -13
  22. package/dist/cjs/tokens/default/color/background.js +98 -49
  23. package/dist/cjs/tokens/default/color/border.js +4 -2
  24. package/dist/cjs/tokens/default/color/icon-border.js +10 -5
  25. package/dist/cjs/tokens/default/color/overlay.js +4 -2
  26. package/dist/cjs/tokens/default/color/text.js +28 -14
  27. package/dist/cjs/tokens/default/shadow/shadow.js +4 -2
  28. package/dist/cjs/tokens/default/utility/utility.js +10 -2
  29. package/dist/cjs/tokens/palette.js +145 -260
  30. package/dist/cjs/version.json +1 -1
  31. package/dist/es2019/artifacts/rename-mapping.js +16 -0
  32. package/dist/es2019/{tokens → artifacts}/token-default-values.js +22 -21
  33. package/dist/es2019/artifacts/token-names.js +94 -0
  34. package/dist/es2019/artifacts/tokens-raw/atlassian-dark.js +1779 -0
  35. package/dist/es2019/artifacts/tokens-raw/atlassian-light.js +1759 -0
  36. package/dist/es2019/artifacts/types.js +1 -0
  37. package/dist/es2019/babel-plugin/index.js +1 -0
  38. package/dist/es2019/babel-plugin/plugin.js +151 -0
  39. package/dist/es2019/entry-points/rename-mapping.js +1 -1
  40. package/dist/es2019/entry-points/token-names.js +1 -1
  41. package/dist/es2019/figma/synchronize-figma-tokens.js +43 -41
  42. package/dist/es2019/get-token.js +1 -1
  43. package/dist/es2019/tokens/atlassian-dark/utility/utility.js +3 -0
  44. package/dist/es2019/tokens/atlassian-light/utility/utility.js +3 -0
  45. package/dist/es2019/tokens/default/color/accent.js +26 -13
  46. package/dist/es2019/tokens/default/color/background.js +103 -49
  47. package/dist/es2019/tokens/default/color/border.js +4 -2
  48. package/dist/es2019/tokens/default/color/icon-border.js +28 -5
  49. package/dist/es2019/tokens/default/color/overlay.js +4 -2
  50. package/dist/es2019/tokens/default/color/text.js +35 -14
  51. package/dist/es2019/tokens/default/shadow/shadow.js +12 -2
  52. package/dist/es2019/tokens/default/utility/utility.js +10 -2
  53. package/dist/es2019/tokens/palette.js +145 -260
  54. package/dist/es2019/version.json +1 -1
  55. package/dist/esm/artifacts/rename-mapping.js +16 -0
  56. package/dist/esm/{tokens → artifacts}/token-default-values.js +22 -21
  57. package/dist/esm/artifacts/token-names.js +94 -0
  58. package/dist/esm/artifacts/tokens-raw/atlassian-dark.js +1779 -0
  59. package/dist/esm/artifacts/tokens-raw/atlassian-light.js +1759 -0
  60. package/dist/esm/artifacts/types.js +1 -0
  61. package/dist/esm/babel-plugin/index.js +1 -0
  62. package/dist/esm/babel-plugin/plugin.js +158 -0
  63. package/dist/esm/entry-points/rename-mapping.js +1 -1
  64. package/dist/esm/entry-points/token-names.js +1 -1
  65. package/dist/esm/figma/synchronize-figma-tokens.js +43 -41
  66. package/dist/esm/get-token.js +1 -1
  67. package/dist/esm/tokens/atlassian-dark/utility/utility.js +3 -0
  68. package/dist/esm/tokens/atlassian-light/utility/utility.js +3 -0
  69. package/dist/esm/tokens/default/color/accent.js +26 -13
  70. package/dist/esm/tokens/default/color/background.js +98 -49
  71. package/dist/esm/tokens/default/color/border.js +4 -2
  72. package/dist/esm/tokens/default/color/icon-border.js +10 -5
  73. package/dist/esm/tokens/default/color/overlay.js +4 -2
  74. package/dist/esm/tokens/default/color/text.js +28 -14
  75. package/dist/esm/tokens/default/shadow/shadow.js +4 -2
  76. package/dist/esm/tokens/default/utility/utility.js +10 -2
  77. package/dist/esm/tokens/palette.js +145 -260
  78. package/dist/esm/version.json +1 -1
  79. package/dist/types/artifacts/rename-mapping.d.ts +17 -0
  80. package/dist/types/{tokens → artifacts}/token-default-values.d.ts +21 -20
  81. package/dist/types/artifacts/token-names.d.ts +184 -0
  82. package/dist/types/artifacts/tokens-raw/atlassian-dark.d.ts +80 -0
  83. package/dist/types/artifacts/tokens-raw/atlassian-light.d.ts +56 -0
  84. package/dist/types/artifacts/types.d.ts +4 -0
  85. package/dist/types/babel-plugin/index.d.ts +1 -0
  86. package/dist/types/babel-plugin/plugin.d.ts +14 -0
  87. package/dist/types/entry-points/babel-plugin.d.ts +1 -0
  88. package/dist/types/entry-points/rename-mapping.d.ts +1 -1
  89. package/dist/types/entry-points/token-names.d.ts +2 -2
  90. package/dist/types/get-token.d.ts +1 -1
  91. package/dist/types/index.d.ts +1 -1
  92. package/dist/types/tokens/atlassian-dark/utility/utility.d.ts +10 -2
  93. package/dist/types/tokens/atlassian-light/utility/utility.d.ts +10 -2
  94. package/dist/types/tokens/default/utility/utility.d.ts +138 -2
  95. package/dist/types/types.d.ts +49 -14
  96. package/package.json +17 -6
  97. package/tokens-browser-extension/README.md +28 -0
  98. package/tokens-browser-extension/atlassian-theme.css +449 -0
  99. package/tokens-browser-extension/background.js +75 -0
  100. package/tokens-browser-extension/content-script.js +75 -0
  101. package/tokens-browser-extension/devtools.html +1 -0
  102. package/tokens-browser-extension/devtools.js +14 -0
  103. package/tokens-browser-extension/manifest.json +36 -0
  104. package/tokens-browser-extension/messageback-script.js +10 -0
  105. package/tokens-browser-extension/messaging.js +36 -0
  106. package/tokens-browser-extension/panel.html +25 -0
  107. package/tokens-browser-extension/panel.js +46 -0
  108. package/tokens-browser-extension/toast.png +0 -0
  109. package/dist/cjs/tokens/rename-mapping.js +0 -29
  110. package/dist/cjs/tokens/token-names.js +0 -100
  111. package/dist/es2019/entry-points/token-default-values.js +0 -1
  112. package/dist/es2019/tokens/rename-mapping.js +0 -21
  113. package/dist/es2019/tokens/token-names.js +0 -93
  114. package/dist/esm/entry-points/token-default-values.js +0 -1
  115. package/dist/esm/tokens/rename-mapping.js +0 -21
  116. package/dist/esm/tokens/token-names.js +0 -93
  117. package/dist/types/entry-points/token-default-values.d.ts +0 -1
  118. package/dist/types/tokens/rename-mapping.d.ts +0 -24
  119. package/dist/types/tokens/token-names.d.ts +0 -182
  120. package/token-default-values/package.json +0 -7
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export { default } from './plugin';
@@ -0,0 +1,151 @@
1
+ import * as t from '@babel/types';
2
+ import tokenDefaultValues from '../artifacts/token-default-values';
3
+ import tokenNames from '../artifacts/token-names';
4
+ export default function plugin() {
5
+ return {
6
+ visitor: {
7
+ CallExpression(path, state) {
8
+ const tokenImportScope = getTokenImportScope(path);
9
+
10
+ if (!tokenImportScope) {
11
+ return;
12
+ } // Check arguments have correct format
13
+
14
+
15
+ if (!path.node.arguments[0]) {
16
+ throw new Error(`token() requires at least one argument`);
17
+ } else if (!t.isStringLiteral(path.node.arguments[0])) {
18
+ throw new Error(`token() must have a string as the first argument`);
19
+ } else if (path.node.arguments.length > 2) {
20
+ throw new Error(`token() does not accept ${path.node.arguments.length} arguments`);
21
+ } // Check the token exists
22
+
23
+
24
+ const tokenName = path.node.arguments[0].value;
25
+ const cssTokenValue = tokenNames[tokenName];
26
+
27
+ if (!cssTokenValue) {
28
+ throw new Error(`token '${tokenName}' does not exist`);
29
+ }
30
+
31
+ var replacementNode; // if no fallback is set, optionally find one from the default theme
32
+
33
+ if (path.node.arguments.length < 2) {
34
+ if (state.opts.shouldUseAutoFallback) {
35
+ replacementNode = t.stringLiteral(`var(${cssTokenValue}, ${getDefaultFallback(tokenName)})`);
36
+ } else {
37
+ replacementNode = t.stringLiteral(`var(${cssTokenValue})`);
38
+ }
39
+ } // Handle fallbacks
40
+
41
+
42
+ const fallback = path.node.arguments[1];
43
+
44
+ if (t.isStringLiteral(fallback)) {
45
+ // String literals can be concatenated into css variable call
46
+ // Empty string fallbacks are ignored. For now, as the user did specify a fallback, no default is inserted
47
+ replacementNode = t.stringLiteral(fallback.value ? `var(${cssTokenValue}, ${fallback.value})` : `var(${cssTokenValue})`);
48
+ } else if (t.isExpression(fallback)) {
49
+ // Expressions should be placed in a template string/literal
50
+ replacementNode = t.templateLiteral([t.templateElement({
51
+ cooked: `var(${cssTokenValue}, `,
52
+ // Currently we create a "raw" value by inserting escape characters via regex (https://github.com/babel/babel/issues/9242)
53
+ raw: `var(${cssTokenValue.replace(/\\|`|\${/g, '\\$&')}, `
54
+ }, false), t.templateElement({
55
+ raw: ')',
56
+ cooked: ')'
57
+ }, true)], [fallback]);
58
+ } // Replace path and call scope.crawl() to refresh the scope bindings + references
59
+
60
+
61
+ replacementNode && path.replaceWith(replacementNode); // @ts-ignore crawl is a valid property
62
+
63
+ tokenImportScope.crawl();
64
+ },
65
+
66
+ Program: {
67
+ exit(path) {
68
+ path.traverse({
69
+ ImportDeclaration(path) {
70
+ // remove import of 'token'
71
+ if (path.node.source.value !== '@atlaskit/tokens') {
72
+ return;
73
+ }
74
+
75
+ path.get('specifiers').forEach(specifier => {
76
+ if (!specifier.isImportSpecifier()) {
77
+ return;
78
+ }
79
+
80
+ if (getNonAliasedImportName(specifier.node) !== 'token') {
81
+ return;
82
+ }
83
+
84
+ const binding = path.scope.bindings[getAliasedImportName(specifier.node)]; // if no longer used, remove
85
+
86
+ if (!binding.referenced) {
87
+ specifier.remove();
88
+ }
89
+ }); // remove '@atlaskit/tokens' import if it is no longer needed
90
+
91
+ if (path.get('specifiers').length === 0) {
92
+ path.remove();
93
+ }
94
+ }
95
+
96
+ });
97
+ }
98
+
99
+ }
100
+ }
101
+ };
102
+ }
103
+
104
+ function getDefaultFallback(tokenName) {
105
+ return tokenDefaultValues[tokenName];
106
+ }
107
+
108
+ function getNonAliasedImportName(node) {
109
+ if (t.isIdentifier(node.imported)) {
110
+ return node.imported.name;
111
+ }
112
+
113
+ return node.imported.value;
114
+ }
115
+
116
+ function getAliasedImportName(node) {
117
+ return node.local.name;
118
+ }
119
+ /**
120
+ * Determine if the current call is to a token function, and
121
+ * return the relevant scope
122
+ */
123
+
124
+
125
+ function getTokenImportScope(path) {
126
+ const callee = path.node.callee;
127
+
128
+ if (!t.isIdentifier(callee)) {
129
+ return undefined;
130
+ }
131
+
132
+ const binding = getTokenBinding(path.scope, callee.name);
133
+
134
+ if (!binding || !t.isImportSpecifier(binding.path.node)) {
135
+ return undefined;
136
+ }
137
+
138
+ return getNonAliasedImportName(binding.path.node) === 'token' ? binding.scope : undefined;
139
+ }
140
+
141
+ function getTokenBinding(scope, name) {
142
+ if (!scope) {
143
+ return undefined;
144
+ }
145
+
146
+ if (scope.bindings[name]) {
147
+ return scope.bindings[name];
148
+ } else {
149
+ return getTokenBinding(scope.parent, name);
150
+ }
151
+ }
@@ -1 +1 @@
1
- export { default } from '../tokens/rename-mapping';
1
+ export { default } from '../artifacts/rename-mapping';
@@ -1 +1 @@
1
- export { default } from '../tokens/token-names';
1
+ export { default } from '../artifacts/token-names';
@@ -95,28 +95,29 @@ function synchronizeFigmaTokens(themeName, tokens, renameMap = {}) {
95
95
  style.name = renameMap[style.name];
96
96
  }
97
97
 
98
- const token = tokens[style.name];
99
-
100
- if (token) {
101
- if (token.attributes.group !== 'shadow') {
102
- // Effect exists in our token set.
103
- // The token is no longer an effect style, time to remove it!
104
- console.log(`=> ${style.name} is no longer a shadow, removing!`);
105
- style.remove();
106
- } else {
107
- // It's still an effect! Update it.
108
- console.log(`=> ${style.name} shadow style has been updated!`);
109
- style.effects = createEffects(token.value);
110
- style.description = token.attributes.description || ''; // Remove from themeValues so it isn't picked up as a new token.
111
-
112
- delete tokens[style.name];
113
- }
114
- } else if (style.name.startsWith(themeName)) {
115
- // The local style was in our theme, but no more!
116
- // It's time to delete it.
98
+ const token = tokens[style.name]; // The local style was in our theme, but no more!
99
+ // It's time to delete it.
100
+
101
+ if (!token) {
117
102
  console.log(`=> ${style.name} shadow style no longer exists, removing.`);
118
103
  style.remove();
104
+ return;
119
105
  }
106
+
107
+ if (token.attributes.group !== 'shadow') {
108
+ // Effect exists in our token set.
109
+ // The token is no longer an effect style, time to remove it!
110
+ console.log(`=> ${style.name} is no longer a shadow, removing!`);
111
+ style.remove();
112
+ return;
113
+ } // It's still an effect! Update it.
114
+
115
+
116
+ console.log(`=> ${style.name} shadow style has been updated!`);
117
+ style.effects = createEffects(token.value);
118
+ style.description = (token.attributes.description || '').trim(); // Remove from themeValues so it isn't picked up as a new token.
119
+
120
+ delete tokens[style.name];
120
121
  }); // Iterate through all local figma styles first
121
122
  // If it still exists in themeValues, update it (and then remove from themeValues)
122
123
  // If it doesn't exist, delete the local figma style
@@ -130,29 +131,30 @@ function synchronizeFigmaTokens(themeName, tokens, renameMap = {}) {
130
131
  style.name = renameMap[style.name];
131
132
  }
132
133
 
133
- const token = tokens[style.name];
134
-
135
- if (token) {
136
- if (token.attributes.group !== 'paint') {
137
- // The token is no longer a paint style, time to remove it!
138
- console.log(`=> ${style.name} is no longer a paint, removing!`);
139
- style.remove();
140
- } else {
141
- // Local style exists that also exists in our tokens!
142
- // Update it and then remove from themeValues.
143
- console.log(`=> ${style.name} paint style has been updated!`); // Mutating is how Figma updates.
144
-
145
- style.paints = [createPaint(token.value)];
146
- style.description = token.attributes.description || ''; // Remove from themeValues so it isn't picked up as a new token.
147
-
148
- delete tokens[style.name];
149
- }
150
- } else if (style.name.startsWith(themeName)) {
151
- // The local style was in our theme, but no more!
152
- // It's time to delete it.
134
+ const token = tokens[style.name]; // The local style was in our theme, but no more!
135
+ // It's time to delete it.
136
+
137
+ if (!token) {
153
138
  console.log(`=> ${style.name} paint style no longer exists, removing.`);
154
139
  style.remove();
140
+ return;
155
141
  }
142
+
143
+ if (token.attributes.group !== 'paint') {
144
+ // The token is no longer a paint style, time to remove it!
145
+ console.log(`=> ${style.name} is no longer a paint, removing!`);
146
+ style.remove();
147
+ return;
148
+ } // Local style exists that also exists in our tokens!
149
+ // Update it and then remove from themeValues.
150
+
151
+
152
+ console.log(`=> ${style.name} paint style has been updated!`); // Mutating is how Figma updates.
153
+
154
+ style.paints = [createPaint(token.value)];
155
+ style.description = (token.attributes.description || '').trim(); // Remove from themeValues so it isn't picked up as a new token.
156
+
157
+ delete tokens[style.name];
156
158
  }); // eslint-disable-next-line guard-for-in
157
159
 
158
160
  for (const key in tokens) {
@@ -161,7 +163,7 @@ function synchronizeFigmaTokens(themeName, tokens, renameMap = {}) {
161
163
  if (token.attributes.group === 'paint') {
162
164
  const newStyle = figma.createPaintStyle();
163
165
  newStyle.name = key;
164
- newStyle.description = token.attributes.description || '';
166
+ newStyle.description = (token.attributes.description || '').trim();
165
167
  newStyle.paints = [createPaint(token.value)];
166
168
  console.log(`=> ${key} paint style has been added!`);
167
169
  }
@@ -169,7 +171,7 @@ function synchronizeFigmaTokens(themeName, tokens, renameMap = {}) {
169
171
  if (token.attributes.group === 'shadow') {
170
172
  const newStyle = figma.createEffectStyle();
171
173
  newStyle.name = key;
172
- newStyle.description = token.attributes.description || '';
174
+ newStyle.description = (token.attributes.description || '').trim();
173
175
  newStyle.effects = createEffects(token.value);
174
176
  console.log(`=> ${key} shadow style has been added!`);
175
177
  }
@@ -1,4 +1,4 @@
1
- import tokens from './tokens/token-names';
1
+ import tokens from './artifacts/token-names';
2
2
 
3
3
  function token(path, fallback) {
4
4
  if (process.env.NODE_ENV !== 'production' && !tokens[path]) {
@@ -2,6 +2,9 @@ const utility = {
2
2
  UNSAFE_util: {
3
3
  transparent: {
4
4
  value: 'transparent'
5
+ },
6
+ MISSING_TOKEN: {
7
+ value: '#FA11F2'
5
8
  }
6
9
  }
7
10
  };
@@ -2,6 +2,9 @@ const utility = {
2
2
  UNSAFE_util: {
3
3
  transparent: {
4
4
  value: 'transparent'
5
+ },
6
+ MISSING_TOKEN: {
7
+ value: '#FA11F2'
5
8
  }
6
9
  }
7
10
  };
@@ -4,79 +4,92 @@ const color = {
4
4
  boldBlue: {
5
5
  attributes: {
6
6
  group: 'paint',
7
- description: ''
7
+ state: 'active',
8
+ description: 'Use for blue backgrounds of stronger emphasis when there is no meaning tied to the color, such as bold tags.'
8
9
  }
9
10
  },
10
11
  boldGreen: {
11
12
  attributes: {
12
13
  group: 'paint',
13
- description: ''
14
+ state: 'active',
15
+ description: 'Use for green backgrounds of stronger emphasis when there is no meaning tied to the color, such as bold tags.'
14
16
  }
15
17
  },
16
18
  boldOrange: {
17
19
  attributes: {
18
20
  group: 'paint',
19
- description: ''
21
+ state: 'active',
22
+ description: 'Use for orange backgrounds of stronger emphasis when there is no meaning tied to the color, such as bold tags.'
20
23
  }
21
24
  },
22
25
  boldPurple: {
23
26
  attributes: {
24
27
  group: 'paint',
25
- description: ''
28
+ state: 'active',
29
+ description: 'Use for purple backgrounds of stronger emphasis when there is no meaning tied to the color, such as bold tags.'
26
30
  }
27
31
  },
28
32
  boldRed: {
29
33
  attributes: {
30
34
  group: 'paint',
31
- description: ''
35
+ state: 'active',
36
+ description: 'Use for red backgrounds of stronger emphasis when there is no meaning tied to the color, such as bold tags.'
32
37
  }
33
38
  },
34
39
  boldTeal: {
35
40
  attributes: {
36
41
  group: 'paint',
37
- description: ''
42
+ state: 'active',
43
+ description: 'Use for teal backgrounds of stronger emphasis when there is no meaning tied to the color, such as bold tags.'
38
44
  }
39
45
  },
40
46
  subtleBlue: {
41
47
  attributes: {
42
48
  group: 'paint',
43
- description: ''
49
+ state: 'active',
50
+ description: 'Use for blue subdued backgrounds when there is no meaning tied to the color, such as colored tags.'
44
51
  }
45
52
  },
46
53
  subtleGreen: {
47
54
  attributes: {
48
55
  group: 'paint',
49
- description: ''
56
+ state: 'active',
57
+ description: 'Use for green subdued backgrounds when there is no meaning tied to the color, such as colored tags.'
50
58
  }
51
59
  },
52
60
  subtleMagenta: {
53
61
  attributes: {
54
62
  group: 'paint',
55
- description: ''
63
+ state: 'active',
64
+ description: 'Use for magenta subdued backgrounds when there is no meaning tied to the color, such as colored tags.'
56
65
  }
57
66
  },
58
67
  subtleOrange: {
59
68
  attributes: {
60
69
  group: 'paint',
61
- description: ''
70
+ state: 'active',
71
+ description: 'Use for orange subdued backgrounds when there is no meaning tied to the color, such as colored tags.'
62
72
  }
63
73
  },
64
74
  subtlePurple: {
65
75
  attributes: {
66
76
  group: 'paint',
67
- description: ''
77
+ state: 'active',
78
+ description: 'Use for purple subdued backgrounds when there is no meaning tied to the color, such as colored tags.'
68
79
  }
69
80
  },
70
81
  subtleRed: {
71
82
  attributes: {
72
83
  group: 'paint',
73
- description: ''
84
+ state: 'active',
85
+ description: 'Use for red subdued backgrounds when there is no meaning tied to the color, such as colored tags.'
74
86
  }
75
87
  },
76
88
  subtleTeal: {
77
89
  attributes: {
78
90
  group: 'paint',
79
- description: ''
91
+ state: 'active',
92
+ description: 'Use for teal subdued backgrounds when there is no meaning tied to the color, such as colored tags.'
80
93
  }
81
94
  }
82
95
  }