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