@atlaskit/tokens 0.13.2 → 0.13.4
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/CHANGELOG.md +51 -0
- package/css/atlassian-dark.css +437 -249
- package/css/atlassian-legacy-dark.css +437 -249
- package/css/atlassian-legacy-light.css +437 -249
- package/css/atlassian-light.css +445 -257
- package/css/atlassian-spacing.css +31 -31
- package/css/atlassian-typography.css +6 -6
- package/dist/cjs/artifacts/palettes-raw/legacy-palette.js +340 -340
- package/dist/cjs/artifacts/palettes-raw/palette.js +611 -611
- package/dist/cjs/artifacts/palettes-raw/spacing-scale.js +35 -35
- package/dist/cjs/artifacts/palettes-raw/typography-palette.js +43 -43
- package/dist/cjs/artifacts/replacement-mapping.js +112 -112
- package/dist/cjs/artifacts/token-default-values.js +262 -168
- package/dist/cjs/artifacts/token-names.js +258 -164
- package/dist/cjs/artifacts/tokens-raw/atlassian-dark.js +5394 -3033
- package/dist/cjs/artifacts/tokens-raw/atlassian-legacy-dark.js +5382 -3021
- package/dist/cjs/artifacts/tokens-raw/atlassian-legacy-light.js +5246 -2885
- package/dist/cjs/artifacts/tokens-raw/atlassian-light.js +5300 -2939
- package/dist/cjs/artifacts/tokens-raw/atlassian-spacing.js +702 -622
- package/dist/cjs/artifacts/tokens-raw/atlassian-typography.js +80 -60
- package/dist/cjs/artifacts/typescript/atlassian-dark-token-names.js +403 -0
- package/dist/cjs/{figma/types.js → artifacts/typescript/atlassian-dark-types-internal.js} +0 -0
- package/dist/cjs/artifacts/typescript/atlassian-dark-types.js +5 -0
- package/dist/cjs/artifacts/typescript/atlassian-light-token-default-values.js +100 -6
- package/dist/cjs/artifacts/typescript/atlassian-light-token-names.js +403 -0
- package/dist/cjs/artifacts/typescript/atlassian-light-types-internal.js +5 -0
- package/dist/cjs/artifacts/typescript/atlassian-light-types.js +5 -0
- package/dist/cjs/entry-points/figma-sync.js +23 -0
- package/dist/cjs/get-token-value.js +1 -1
- package/dist/cjs/get-token.js +1 -1
- package/dist/cjs/palettes/palette.js +3 -3
- package/dist/cjs/tokens/atlassian-dark/color/chart.js +420 -0
- package/dist/cjs/tokens/atlassian-legacy-dark/color/chart.js +440 -0
- package/dist/cjs/tokens/atlassian-legacy-light/color/chart.js +440 -0
- package/dist/cjs/tokens/atlassian-light/color/accent.js +1 -1
- package/dist/cjs/tokens/atlassian-light/color/chart.js +420 -0
- package/dist/cjs/tokens/default/color/background.js +2 -2
- package/dist/cjs/tokens/default/color/border.js +1 -1
- package/dist/cjs/tokens/default/color/chart.js +890 -0
- package/dist/cjs/tokens/default/color/icon.js +1 -1
- package/dist/cjs/tokens/default/color/text.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/artifacts/palettes-raw/legacy-palette.js +340 -340
- package/dist/es2019/artifacts/palettes-raw/palette.js +611 -611
- package/dist/es2019/artifacts/palettes-raw/spacing-scale.js +35 -35
- package/dist/es2019/artifacts/palettes-raw/typography-palette.js +43 -43
- package/dist/es2019/artifacts/replacement-mapping.js +112 -112
- package/dist/es2019/artifacts/token-default-values.js +262 -168
- package/dist/es2019/artifacts/token-names.js +258 -164
- package/dist/es2019/artifacts/tokens-raw/atlassian-dark.js +5394 -3033
- package/dist/es2019/artifacts/tokens-raw/atlassian-legacy-dark.js +5382 -3021
- package/dist/es2019/artifacts/tokens-raw/atlassian-legacy-light.js +5246 -2885
- package/dist/es2019/artifacts/tokens-raw/atlassian-light.js +5300 -2939
- package/dist/es2019/artifacts/tokens-raw/atlassian-spacing.js +702 -622
- package/dist/es2019/artifacts/tokens-raw/atlassian-typography.js +80 -60
- package/dist/es2019/artifacts/typescript/atlassian-dark-token-names.js +395 -0
- package/dist/es2019/{figma/types.js → artifacts/typescript/atlassian-dark-types-internal.js} +0 -0
- package/dist/{esm/figma/types.js → es2019/artifacts/typescript/atlassian-dark-types.js} +0 -0
- package/dist/es2019/artifacts/typescript/atlassian-light-token-default-values.js +100 -6
- package/dist/es2019/artifacts/typescript/atlassian-light-token-names.js +395 -0
- package/dist/es2019/artifacts/typescript/atlassian-light-types-internal.js +1 -0
- package/dist/es2019/artifacts/typescript/atlassian-light-types.js +1 -0
- package/dist/es2019/entry-points/figma-sync.js +3 -0
- package/dist/es2019/get-token-value.js +1 -1
- package/dist/es2019/get-token.js +1 -1
- package/dist/es2019/palettes/palette.js +3 -3
- package/dist/es2019/tokens/atlassian-dark/color/chart.js +413 -0
- package/dist/es2019/tokens/atlassian-legacy-dark/color/chart.js +433 -0
- package/dist/es2019/tokens/atlassian-legacy-light/color/chart.js +433 -0
- package/dist/es2019/tokens/atlassian-light/color/accent.js +1 -1
- package/dist/es2019/tokens/atlassian-light/color/chart.js +413 -0
- package/dist/es2019/tokens/default/color/background.js +2 -2
- package/dist/es2019/tokens/default/color/border.js +1 -1
- package/dist/es2019/tokens/default/color/chart.js +883 -0
- package/dist/es2019/tokens/default/color/icon.js +1 -1
- package/dist/es2019/tokens/default/color/text.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/artifacts/palettes-raw/legacy-palette.js +340 -340
- package/dist/esm/artifacts/palettes-raw/palette.js +611 -611
- package/dist/esm/artifacts/palettes-raw/spacing-scale.js +35 -35
- package/dist/esm/artifacts/palettes-raw/typography-palette.js +43 -43
- package/dist/esm/artifacts/replacement-mapping.js +112 -112
- package/dist/esm/artifacts/token-default-values.js +262 -168
- package/dist/esm/artifacts/token-names.js +258 -164
- package/dist/esm/artifacts/tokens-raw/atlassian-dark.js +5394 -3033
- package/dist/esm/artifacts/tokens-raw/atlassian-legacy-dark.js +5382 -3021
- package/dist/esm/artifacts/tokens-raw/atlassian-legacy-light.js +5246 -2885
- package/dist/esm/artifacts/tokens-raw/atlassian-light.js +5300 -2939
- package/dist/esm/artifacts/tokens-raw/atlassian-spacing.js +702 -622
- package/dist/esm/artifacts/tokens-raw/atlassian-typography.js +80 -60
- package/dist/esm/artifacts/typescript/atlassian-dark-token-names.js +395 -0
- package/dist/esm/artifacts/typescript/atlassian-dark-types-internal.js +1 -0
- package/dist/esm/artifacts/typescript/atlassian-dark-types.js +1 -0
- package/dist/esm/artifacts/typescript/atlassian-light-token-default-values.js +100 -6
- package/dist/esm/artifacts/typescript/atlassian-light-token-names.js +395 -0
- package/dist/esm/artifacts/typescript/atlassian-light-types-internal.js +1 -0
- package/dist/esm/artifacts/typescript/atlassian-light-types.js +1 -0
- package/dist/esm/entry-points/figma-sync.js +3 -0
- package/dist/esm/get-token-value.js +1 -1
- package/dist/esm/get-token.js +1 -1
- package/dist/esm/palettes/palette.js +3 -3
- package/dist/esm/tokens/atlassian-dark/color/chart.js +413 -0
- package/dist/esm/tokens/atlassian-legacy-dark/color/chart.js +433 -0
- package/dist/esm/tokens/atlassian-legacy-light/color/chart.js +433 -0
- package/dist/esm/tokens/atlassian-light/color/accent.js +1 -1
- package/dist/esm/tokens/atlassian-light/color/chart.js +413 -0
- package/dist/esm/tokens/default/color/background.js +2 -2
- package/dist/esm/tokens/default/color/border.js +1 -1
- package/dist/esm/tokens/default/color/chart.js +883 -0
- package/dist/esm/tokens/default/color/icon.js +1 -1
- package/dist/esm/tokens/default/color/text.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/artifacts/palettes-raw/legacy-palette.d.ts +5 -5
- package/dist/types/artifacts/palettes-raw/palette.d.ts +5 -5
- package/dist/types/artifacts/palettes-raw/spacing-scale.d.ts +1 -1
- package/dist/types/artifacts/palettes-raw/typography-palette.d.ts +1 -1
- package/dist/types/artifacts/replacement-mapping.d.ts +1 -1
- package/dist/types/artifacts/token-default-values.d.ts +262 -168
- package/dist/types/artifacts/token-names.d.ts +516 -328
- package/dist/types/artifacts/tokens-raw/atlassian-dark.d.ts +42 -37
- package/dist/types/artifacts/tokens-raw/atlassian-legacy-dark.d.ts +42 -37
- package/dist/types/artifacts/tokens-raw/atlassian-legacy-light.d.ts +38 -33
- package/dist/types/artifacts/tokens-raw/atlassian-light.d.ts +38 -33
- package/dist/types/artifacts/tokens-raw/atlassian-spacing.d.ts +22 -17
- package/dist/types/artifacts/tokens-raw/atlassian-typography.d.ts +2 -1
- package/dist/types/artifacts/types-internal.d.ts +2 -2
- package/dist/types/artifacts/types.d.ts +2 -2
- package/dist/types/artifacts/typescript/atlassian-dark-token-names.d.ts +784 -0
- package/dist/types/artifacts/typescript/atlassian-dark-types-internal.d.ts +6 -0
- package/dist/types/artifacts/typescript/atlassian-dark-types.d.ts +6 -0
- package/dist/types/artifacts/typescript/atlassian-light-token-default-values.d.ts +100 -6
- package/dist/types/artifacts/typescript/atlassian-light-token-names.d.ts +784 -0
- package/dist/types/artifacts/typescript/atlassian-light-types-internal.d.ts +6 -0
- package/dist/types/artifacts/typescript/atlassian-light-types.d.ts +6 -0
- package/dist/types/entry-points/figma-sync.d.ts +3 -0
- package/dist/types/tokens/atlassian-dark/color/chart.d.ts +4 -0
- package/dist/types/tokens/atlassian-dark/utility/utility.d.ts +1 -1
- package/dist/types/tokens/atlassian-legacy-dark/color/chart.d.ts +4 -0
- package/dist/types/tokens/atlassian-legacy-dark/utility/utility.d.ts +1 -1
- package/dist/types/tokens/atlassian-legacy-light/color/chart.d.ts +4 -0
- package/dist/types/tokens/atlassian-legacy-light/utility/utility.d.ts +1 -1
- package/dist/types/tokens/atlassian-light/color/chart.d.ts +4 -0
- package/dist/types/tokens/atlassian-light/utility/utility.d.ts +1 -1
- package/dist/types/tokens/default/color/chart.d.ts +4 -0
- package/dist/types/tokens/default/utility/utility.d.ts +1 -1
- package/dist/types/types.d.ts +224 -0
- package/figma-sync/package.json +17 -0
- package/package.json +6 -3
- package/report.api.md +515 -327
- package/tmp/api-report-tmp.d.ts +515 -327
- package/dist/cjs/figma/synchronize-figma-tokens.js +0 -220
- package/dist/es2019/figma/synchronize-figma-tokens.js +0 -212
- package/dist/esm/figma/synchronize-figma-tokens.js +0 -216
- package/dist/types/figma/synchronize-figma-tokens.d.ts +0 -24
- package/dist/types/figma/types.d.ts +0 -40
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
// ----------------------------------------------------
|
|
8
|
-
// ----------------------------------------------------
|
|
9
|
-
// !!!WARNING!!!
|
|
10
|
-
// This file is made to copy and paste into Figma.
|
|
11
|
-
// If you make changes make sure to check the built output here:
|
|
12
|
-
// `packages/design-system/tokens/dist/cjs/figma/tokens-to-figma.js`
|
|
13
|
-
// If any Babel imports are added you will need to modify your code so they aren't
|
|
14
|
-
// as they won't work in a browser!
|
|
15
|
-
// ----------------------------------------------------
|
|
16
|
-
// ----------------------------------------------------
|
|
17
|
-
|
|
18
|
-
/* eslint-disable no-param-reassign */
|
|
19
|
-
|
|
20
|
-
/* eslint-disable no-console */
|
|
21
|
-
function hexToPercent(hex) {
|
|
22
|
-
var percent = parseInt(hex, 16) * 100; // Ensure the value is capped between 0 and 100
|
|
23
|
-
|
|
24
|
-
return Math.max(0, Math.min(Math.round(percent / 255), 100));
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function createPaint(hex) {
|
|
28
|
-
var hexValue = hex;
|
|
29
|
-
|
|
30
|
-
if (!hexValue.startsWith('#')) {
|
|
31
|
-
throw new Error('hex should start with hash');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (hexValue.length === 4) {
|
|
35
|
-
// We have a 3 character shorthand hex, expand it!
|
|
36
|
-
hexValue = hexValue.split('').map(function (char) {
|
|
37
|
-
return char === '#' ? char : "".concat(char).concat(char);
|
|
38
|
-
}).join('');
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (hexValue.length !== 9 && hexValue.length !== 7) {
|
|
42
|
-
throw new Error('hex invalid length');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
var r = parseInt(hexValue.slice(1, 3), 16) / 255;
|
|
46
|
-
var g = parseInt(hexValue.slice(3, 5), 16) / 255;
|
|
47
|
-
var b = parseInt(hexValue.slice(5, 7), 16) / 255;
|
|
48
|
-
var alphaHex = hexValue.slice(7, 9);
|
|
49
|
-
var opacity = alphaHex ? hexToPercent(alphaHex) : 100;
|
|
50
|
-
return {
|
|
51
|
-
type: 'SOLID',
|
|
52
|
-
visible: true,
|
|
53
|
-
opacity: opacity / 100,
|
|
54
|
-
blendMode: 'NORMAL',
|
|
55
|
-
color: {
|
|
56
|
-
r: r,
|
|
57
|
-
g: g,
|
|
58
|
-
b: b
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function createEffects(value) {
|
|
64
|
-
return value.map(function (shadow) {
|
|
65
|
-
// Reuse this to get the rgb value of the hex.
|
|
66
|
-
var _createPaint = createPaint(shadow.color),
|
|
67
|
-
color = _createPaint.color;
|
|
68
|
-
|
|
69
|
-
return {
|
|
70
|
-
blendMode: 'NORMAL',
|
|
71
|
-
color: {
|
|
72
|
-
r: color.r,
|
|
73
|
-
g: color.g,
|
|
74
|
-
b: color.b,
|
|
75
|
-
a: shadow.opacity
|
|
76
|
-
},
|
|
77
|
-
offset: shadow.offset,
|
|
78
|
-
radius: shadow.radius,
|
|
79
|
-
spread: shadow.spread,
|
|
80
|
-
type: shadow.inset ? 'INNER_SHADOW' : 'DROP_SHADOW',
|
|
81
|
-
visible: true
|
|
82
|
-
};
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Formats a token description for use in Figma,
|
|
87
|
-
* including deprecated warnings
|
|
88
|
-
*
|
|
89
|
-
* @param token
|
|
90
|
-
*/
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
function formatDescription(token) {
|
|
94
|
-
var description = token.attributes.description.trim() || '';
|
|
95
|
-
|
|
96
|
-
if (token.attributes.state === 'deprecated') {
|
|
97
|
-
// The token is deprecated. Prefix a warning to the description!
|
|
98
|
-
// If the token has multiple replacement options,
|
|
99
|
-
// flatten them into a string
|
|
100
|
-
var replacements = Array.isArray(token.attributes.replacement) ? token.attributes.replacement.join(' | ') : token.attributes.replacement; // If the token has replacements, prefix them to the description
|
|
101
|
-
|
|
102
|
-
var prefix = replacements ? "use ".concat(replacements, " instead") : 'do not use';
|
|
103
|
-
description = "DEPRECATED ".concat(prefix, ". \n").concat(description);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return description;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Adds tokens under a specified theme as paint styles to Figma.
|
|
111
|
-
*
|
|
112
|
-
* @param {*} themeName name of the theme, e.g. "dark". Tokens will be added under this folder name.
|
|
113
|
-
* @param {*} tokens
|
|
114
|
-
* @param {*} renameMap mapping object for tokens that should be renamed. example { 'old/token': 'new/token'}
|
|
115
|
-
*/
|
|
116
|
-
function synchronizeFigmaTokens(themeName, tokens) {
|
|
117
|
-
var renameMap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
118
|
-
var figma = window.figma;
|
|
119
|
-
var localPaintStyles = figma.getLocalPaintStyles();
|
|
120
|
-
var localEffectStyles = figma.getLocalEffectStyles();
|
|
121
|
-
localEffectStyles.forEach(function (style) {
|
|
122
|
-
// If there's a rename mapping for this style name
|
|
123
|
-
// Rename it first, then follow up with value updates
|
|
124
|
-
if (renameMap[style.name]) {
|
|
125
|
-
console.log("=> ".concat(style.name, " renamed to ").concat(renameMap[style.name], "!"));
|
|
126
|
-
style.name = renameMap[style.name];
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
var token = tokens[style.name]; // The local style was in our theme, but no more!
|
|
130
|
-
// It's time to delete it.
|
|
131
|
-
|
|
132
|
-
if (!token) {
|
|
133
|
-
console.log("=> ".concat(style.name, " shadow style no longer exists, removing."));
|
|
134
|
-
style.remove();
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (token.attributes.group !== 'shadow') {
|
|
139
|
-
// Effect exists in our token set.
|
|
140
|
-
// The token is no longer an effect style, time to remove it!
|
|
141
|
-
console.log("=> ".concat(style.name, " is no longer a shadow, removing!"));
|
|
142
|
-
style.remove();
|
|
143
|
-
return;
|
|
144
|
-
} // It's still an effect! Update it.
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
console.log("=> ".concat(style.name, " shadow style has been updated!"));
|
|
148
|
-
style.effects = createEffects(token.value);
|
|
149
|
-
style.description = formatDescription(token); // Remove from themeValues so it isn't picked up as a new token.
|
|
150
|
-
|
|
151
|
-
delete tokens[style.name];
|
|
152
|
-
}); // Iterate through all local figma styles first
|
|
153
|
-
// If it still exists in themeValues, update it (and then remove from themeValues)
|
|
154
|
-
// If it doesn't exist, delete the local figma style
|
|
155
|
-
// For all themeValues remaining we will add them as new
|
|
156
|
-
|
|
157
|
-
localPaintStyles.forEach(function (style) {
|
|
158
|
-
// If there's a rename mapping for this style name
|
|
159
|
-
// Rename it first, then follow up with value updates
|
|
160
|
-
if (renameMap[style.name]) {
|
|
161
|
-
console.log("=> ".concat(style.name, " renamed to ").concat(renameMap[style.name], "!"));
|
|
162
|
-
style.name = renameMap[style.name];
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
var token = tokens[style.name]; // The local style was in our theme, but no more!
|
|
166
|
-
// It's time to delete it.
|
|
167
|
-
|
|
168
|
-
if (!token) {
|
|
169
|
-
console.log("=> ".concat(style.name, " paint style no longer exists, removing."));
|
|
170
|
-
style.remove();
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (token.attributes.group !== 'paint') {
|
|
175
|
-
// The token is no longer a paint style, time to remove it!
|
|
176
|
-
console.log("=> ".concat(style.name, " is no longer a paint, removing!"));
|
|
177
|
-
style.remove();
|
|
178
|
-
return;
|
|
179
|
-
} // Local style exists that also exists in our tokens!
|
|
180
|
-
// Update it and then remove from themeValues.
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
console.log("=> ".concat(style.name, " paint style has been updated!")); // Mutating is how Figma updates.
|
|
184
|
-
|
|
185
|
-
style.paints = [createPaint(token.value)];
|
|
186
|
-
style.description = formatDescription(token); // Remove from themeValues so it isn't picked up as a new token.
|
|
187
|
-
|
|
188
|
-
delete tokens[style.name];
|
|
189
|
-
}); // eslint-disable-next-line guard-for-in
|
|
190
|
-
|
|
191
|
-
for (var key in tokens) {
|
|
192
|
-
var token = tokens[key];
|
|
193
|
-
|
|
194
|
-
if (token.attributes.group === 'paint') {
|
|
195
|
-
var newStyle = figma.createPaintStyle();
|
|
196
|
-
newStyle.name = key;
|
|
197
|
-
newStyle.description = formatDescription(token);
|
|
198
|
-
newStyle.paints = [createPaint(token.value)];
|
|
199
|
-
console.log("=> ".concat(key, " paint style has been added!"));
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (token.attributes.group === 'shadow') {
|
|
203
|
-
var _newStyle = figma.createEffectStyle();
|
|
204
|
-
|
|
205
|
-
_newStyle.name = key;
|
|
206
|
-
_newStyle.description = formatDescription(token);
|
|
207
|
-
_newStyle.effects = createEffects(token.value);
|
|
208
|
-
console.log("=> ".concat(key, " shadow style has been added!"));
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
if (typeof module !== 'undefined') {
|
|
214
|
-
module.exports = {
|
|
215
|
-
synchronizeFigmaTokens: synchronizeFigmaTokens,
|
|
216
|
-
createPaint: createPaint,
|
|
217
|
-
createEffects: createEffects,
|
|
218
|
-
formatDescription: formatDescription
|
|
219
|
-
};
|
|
220
|
-
}
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
// ----------------------------------------------------
|
|
2
|
-
// ----------------------------------------------------
|
|
3
|
-
// !!!WARNING!!!
|
|
4
|
-
// This file is made to copy and paste into Figma.
|
|
5
|
-
// If you make changes make sure to check the built output here:
|
|
6
|
-
// `packages/design-system/tokens/dist/cjs/figma/tokens-to-figma.js`
|
|
7
|
-
// If any Babel imports are added you will need to modify your code so they aren't
|
|
8
|
-
// as they won't work in a browser!
|
|
9
|
-
// ----------------------------------------------------
|
|
10
|
-
// ----------------------------------------------------
|
|
11
|
-
|
|
12
|
-
/* eslint-disable no-param-reassign */
|
|
13
|
-
|
|
14
|
-
/* eslint-disable no-console */
|
|
15
|
-
function hexToPercent(hex) {
|
|
16
|
-
const percent = parseInt(hex, 16) * 100; // Ensure the value is capped between 0 and 100
|
|
17
|
-
|
|
18
|
-
return Math.max(0, Math.min(Math.round(percent / 255), 100));
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function createPaint(hex) {
|
|
22
|
-
let hexValue = hex;
|
|
23
|
-
|
|
24
|
-
if (!hexValue.startsWith('#')) {
|
|
25
|
-
throw new Error('hex should start with hash');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (hexValue.length === 4) {
|
|
29
|
-
// We have a 3 character shorthand hex, expand it!
|
|
30
|
-
hexValue = hexValue.split('').map(char => char === '#' ? char : `${char}${char}`).join('');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (hexValue.length !== 9 && hexValue.length !== 7) {
|
|
34
|
-
throw new Error('hex invalid length');
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const r = parseInt(hexValue.slice(1, 3), 16) / 255;
|
|
38
|
-
const g = parseInt(hexValue.slice(3, 5), 16) / 255;
|
|
39
|
-
const b = parseInt(hexValue.slice(5, 7), 16) / 255;
|
|
40
|
-
const alphaHex = hexValue.slice(7, 9);
|
|
41
|
-
const opacity = alphaHex ? hexToPercent(alphaHex) : 100;
|
|
42
|
-
return {
|
|
43
|
-
type: 'SOLID',
|
|
44
|
-
visible: true,
|
|
45
|
-
opacity: opacity / 100,
|
|
46
|
-
blendMode: 'NORMAL',
|
|
47
|
-
color: {
|
|
48
|
-
r,
|
|
49
|
-
g,
|
|
50
|
-
b
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function createEffects(value) {
|
|
56
|
-
return value.map(shadow => {
|
|
57
|
-
// Reuse this to get the rgb value of the hex.
|
|
58
|
-
const {
|
|
59
|
-
color
|
|
60
|
-
} = createPaint(shadow.color);
|
|
61
|
-
return {
|
|
62
|
-
blendMode: 'NORMAL',
|
|
63
|
-
color: {
|
|
64
|
-
r: color.r,
|
|
65
|
-
g: color.g,
|
|
66
|
-
b: color.b,
|
|
67
|
-
a: shadow.opacity
|
|
68
|
-
},
|
|
69
|
-
offset: shadow.offset,
|
|
70
|
-
radius: shadow.radius,
|
|
71
|
-
spread: shadow.spread,
|
|
72
|
-
type: shadow.inset ? 'INNER_SHADOW' : 'DROP_SHADOW',
|
|
73
|
-
visible: true
|
|
74
|
-
};
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Formats a token description for use in Figma,
|
|
79
|
-
* including deprecated warnings
|
|
80
|
-
*
|
|
81
|
-
* @param token
|
|
82
|
-
*/
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
function formatDescription(token) {
|
|
86
|
-
let description = token.attributes.description.trim() || '';
|
|
87
|
-
|
|
88
|
-
if (token.attributes.state === 'deprecated') {
|
|
89
|
-
// The token is deprecated. Prefix a warning to the description!
|
|
90
|
-
// If the token has multiple replacement options,
|
|
91
|
-
// flatten them into a string
|
|
92
|
-
const replacements = Array.isArray(token.attributes.replacement) ? token.attributes.replacement.join(' | ') : token.attributes.replacement; // If the token has replacements, prefix them to the description
|
|
93
|
-
|
|
94
|
-
const prefix = replacements ? `use ${replacements} instead` : 'do not use';
|
|
95
|
-
description = `DEPRECATED ${prefix}. \n${description}`;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return description;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Adds tokens under a specified theme as paint styles to Figma.
|
|
103
|
-
*
|
|
104
|
-
* @param {*} themeName name of the theme, e.g. "dark". Tokens will be added under this folder name.
|
|
105
|
-
* @param {*} tokens
|
|
106
|
-
* @param {*} renameMap mapping object for tokens that should be renamed. example { 'old/token': 'new/token'}
|
|
107
|
-
*/
|
|
108
|
-
function synchronizeFigmaTokens(themeName, tokens, renameMap = {}) {
|
|
109
|
-
const figma = window.figma;
|
|
110
|
-
const localPaintStyles = figma.getLocalPaintStyles();
|
|
111
|
-
const localEffectStyles = figma.getLocalEffectStyles();
|
|
112
|
-
localEffectStyles.forEach(style => {
|
|
113
|
-
// If there's a rename mapping for this style name
|
|
114
|
-
// Rename it first, then follow up with value updates
|
|
115
|
-
if (renameMap[style.name]) {
|
|
116
|
-
console.log(`=> ${style.name} renamed to ${renameMap[style.name]}!`);
|
|
117
|
-
style.name = renameMap[style.name];
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const token = tokens[style.name]; // The local style was in our theme, but no more!
|
|
121
|
-
// It's time to delete it.
|
|
122
|
-
|
|
123
|
-
if (!token) {
|
|
124
|
-
console.log(`=> ${style.name} shadow style no longer exists, removing.`);
|
|
125
|
-
style.remove();
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (token.attributes.group !== 'shadow') {
|
|
130
|
-
// Effect exists in our token set.
|
|
131
|
-
// The token is no longer an effect style, time to remove it!
|
|
132
|
-
console.log(`=> ${style.name} is no longer a shadow, removing!`);
|
|
133
|
-
style.remove();
|
|
134
|
-
return;
|
|
135
|
-
} // It's still an effect! Update it.
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
console.log(`=> ${style.name} shadow style has been updated!`);
|
|
139
|
-
style.effects = createEffects(token.value);
|
|
140
|
-
style.description = formatDescription(token); // Remove from themeValues so it isn't picked up as a new token.
|
|
141
|
-
|
|
142
|
-
delete tokens[style.name];
|
|
143
|
-
}); // Iterate through all local figma styles first
|
|
144
|
-
// If it still exists in themeValues, update it (and then remove from themeValues)
|
|
145
|
-
// If it doesn't exist, delete the local figma style
|
|
146
|
-
// For all themeValues remaining we will add them as new
|
|
147
|
-
|
|
148
|
-
localPaintStyles.forEach(style => {
|
|
149
|
-
// If there's a rename mapping for this style name
|
|
150
|
-
// Rename it first, then follow up with value updates
|
|
151
|
-
if (renameMap[style.name]) {
|
|
152
|
-
console.log(`=> ${style.name} renamed to ${renameMap[style.name]}!`);
|
|
153
|
-
style.name = renameMap[style.name];
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const token = tokens[style.name]; // The local style was in our theme, but no more!
|
|
157
|
-
// It's time to delete it.
|
|
158
|
-
|
|
159
|
-
if (!token) {
|
|
160
|
-
console.log(`=> ${style.name} paint style no longer exists, removing.`);
|
|
161
|
-
style.remove();
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if (token.attributes.group !== 'paint') {
|
|
166
|
-
// The token is no longer a paint style, time to remove it!
|
|
167
|
-
console.log(`=> ${style.name} is no longer a paint, removing!`);
|
|
168
|
-
style.remove();
|
|
169
|
-
return;
|
|
170
|
-
} // Local style exists that also exists in our tokens!
|
|
171
|
-
// Update it and then remove from themeValues.
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
console.log(`=> ${style.name} paint style has been updated!`); // Mutating is how Figma updates.
|
|
175
|
-
|
|
176
|
-
style.paints = [createPaint(token.value)];
|
|
177
|
-
style.description = formatDescription(token); // Remove from themeValues so it isn't picked up as a new token.
|
|
178
|
-
|
|
179
|
-
delete tokens[style.name];
|
|
180
|
-
}); // eslint-disable-next-line guard-for-in
|
|
181
|
-
|
|
182
|
-
for (const key in tokens) {
|
|
183
|
-
const token = tokens[key];
|
|
184
|
-
|
|
185
|
-
if (token.attributes.group === 'paint') {
|
|
186
|
-
const newStyle = figma.createPaintStyle();
|
|
187
|
-
newStyle.name = key;
|
|
188
|
-
newStyle.description = formatDescription(token);
|
|
189
|
-
newStyle.paints = [createPaint(token.value)];
|
|
190
|
-
console.log(`=> ${key} paint style has been added!`);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (token.attributes.group === 'shadow') {
|
|
194
|
-
const newStyle = figma.createEffectStyle();
|
|
195
|
-
newStyle.name = key;
|
|
196
|
-
newStyle.description = formatDescription(token);
|
|
197
|
-
newStyle.effects = createEffects(token.value);
|
|
198
|
-
console.log(`=> ${key} shadow style has been added!`);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
if (typeof module !== 'undefined') {
|
|
204
|
-
module.exports = {
|
|
205
|
-
synchronizeFigmaTokens,
|
|
206
|
-
createPaint,
|
|
207
|
-
createEffects,
|
|
208
|
-
formatDescription
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
export {};
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
// ----------------------------------------------------
|
|
2
|
-
// ----------------------------------------------------
|
|
3
|
-
// !!!WARNING!!!
|
|
4
|
-
// This file is made to copy and paste into Figma.
|
|
5
|
-
// If you make changes make sure to check the built output here:
|
|
6
|
-
// `packages/design-system/tokens/dist/cjs/figma/tokens-to-figma.js`
|
|
7
|
-
// If any Babel imports are added you will need to modify your code so they aren't
|
|
8
|
-
// as they won't work in a browser!
|
|
9
|
-
// ----------------------------------------------------
|
|
10
|
-
// ----------------------------------------------------
|
|
11
|
-
|
|
12
|
-
/* eslint-disable no-param-reassign */
|
|
13
|
-
|
|
14
|
-
/* eslint-disable no-console */
|
|
15
|
-
function hexToPercent(hex) {
|
|
16
|
-
var percent = parseInt(hex, 16) * 100; // Ensure the value is capped between 0 and 100
|
|
17
|
-
|
|
18
|
-
return Math.max(0, Math.min(Math.round(percent / 255), 100));
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function createPaint(hex) {
|
|
22
|
-
var hexValue = hex;
|
|
23
|
-
|
|
24
|
-
if (!hexValue.startsWith('#')) {
|
|
25
|
-
throw new Error('hex should start with hash');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (hexValue.length === 4) {
|
|
29
|
-
// We have a 3 character shorthand hex, expand it!
|
|
30
|
-
hexValue = hexValue.split('').map(function (char) {
|
|
31
|
-
return char === '#' ? char : "".concat(char).concat(char);
|
|
32
|
-
}).join('');
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (hexValue.length !== 9 && hexValue.length !== 7) {
|
|
36
|
-
throw new Error('hex invalid length');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
var r = parseInt(hexValue.slice(1, 3), 16) / 255;
|
|
40
|
-
var g = parseInt(hexValue.slice(3, 5), 16) / 255;
|
|
41
|
-
var b = parseInt(hexValue.slice(5, 7), 16) / 255;
|
|
42
|
-
var alphaHex = hexValue.slice(7, 9);
|
|
43
|
-
var opacity = alphaHex ? hexToPercent(alphaHex) : 100;
|
|
44
|
-
return {
|
|
45
|
-
type: 'SOLID',
|
|
46
|
-
visible: true,
|
|
47
|
-
opacity: opacity / 100,
|
|
48
|
-
blendMode: 'NORMAL',
|
|
49
|
-
color: {
|
|
50
|
-
r: r,
|
|
51
|
-
g: g,
|
|
52
|
-
b: b
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function createEffects(value) {
|
|
58
|
-
return value.map(function (shadow) {
|
|
59
|
-
// Reuse this to get the rgb value of the hex.
|
|
60
|
-
var _createPaint = createPaint(shadow.color),
|
|
61
|
-
color = _createPaint.color;
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
blendMode: 'NORMAL',
|
|
65
|
-
color: {
|
|
66
|
-
r: color.r,
|
|
67
|
-
g: color.g,
|
|
68
|
-
b: color.b,
|
|
69
|
-
a: shadow.opacity
|
|
70
|
-
},
|
|
71
|
-
offset: shadow.offset,
|
|
72
|
-
radius: shadow.radius,
|
|
73
|
-
spread: shadow.spread,
|
|
74
|
-
type: shadow.inset ? 'INNER_SHADOW' : 'DROP_SHADOW',
|
|
75
|
-
visible: true
|
|
76
|
-
};
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Formats a token description for use in Figma,
|
|
81
|
-
* including deprecated warnings
|
|
82
|
-
*
|
|
83
|
-
* @param token
|
|
84
|
-
*/
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
function formatDescription(token) {
|
|
88
|
-
var description = token.attributes.description.trim() || '';
|
|
89
|
-
|
|
90
|
-
if (token.attributes.state === 'deprecated') {
|
|
91
|
-
// The token is deprecated. Prefix a warning to the description!
|
|
92
|
-
// If the token has multiple replacement options,
|
|
93
|
-
// flatten them into a string
|
|
94
|
-
var replacements = Array.isArray(token.attributes.replacement) ? token.attributes.replacement.join(' | ') : token.attributes.replacement; // If the token has replacements, prefix them to the description
|
|
95
|
-
|
|
96
|
-
var prefix = replacements ? "use ".concat(replacements, " instead") : 'do not use';
|
|
97
|
-
description = "DEPRECATED ".concat(prefix, ". \n").concat(description);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return description;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Adds tokens under a specified theme as paint styles to Figma.
|
|
105
|
-
*
|
|
106
|
-
* @param {*} themeName name of the theme, e.g. "dark". Tokens will be added under this folder name.
|
|
107
|
-
* @param {*} tokens
|
|
108
|
-
* @param {*} renameMap mapping object for tokens that should be renamed. example { 'old/token': 'new/token'}
|
|
109
|
-
*/
|
|
110
|
-
function synchronizeFigmaTokens(themeName, tokens) {
|
|
111
|
-
var renameMap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
112
|
-
var figma = window.figma;
|
|
113
|
-
var localPaintStyles = figma.getLocalPaintStyles();
|
|
114
|
-
var localEffectStyles = figma.getLocalEffectStyles();
|
|
115
|
-
localEffectStyles.forEach(function (style) {
|
|
116
|
-
// If there's a rename mapping for this style name
|
|
117
|
-
// Rename it first, then follow up with value updates
|
|
118
|
-
if (renameMap[style.name]) {
|
|
119
|
-
console.log("=> ".concat(style.name, " renamed to ").concat(renameMap[style.name], "!"));
|
|
120
|
-
style.name = renameMap[style.name];
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
var token = tokens[style.name]; // The local style was in our theme, but no more!
|
|
124
|
-
// It's time to delete it.
|
|
125
|
-
|
|
126
|
-
if (!token) {
|
|
127
|
-
console.log("=> ".concat(style.name, " shadow style no longer exists, removing."));
|
|
128
|
-
style.remove();
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (token.attributes.group !== 'shadow') {
|
|
133
|
-
// Effect exists in our token set.
|
|
134
|
-
// The token is no longer an effect style, time to remove it!
|
|
135
|
-
console.log("=> ".concat(style.name, " is no longer a shadow, removing!"));
|
|
136
|
-
style.remove();
|
|
137
|
-
return;
|
|
138
|
-
} // It's still an effect! Update it.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
console.log("=> ".concat(style.name, " shadow style has been updated!"));
|
|
142
|
-
style.effects = createEffects(token.value);
|
|
143
|
-
style.description = formatDescription(token); // Remove from themeValues so it isn't picked up as a new token.
|
|
144
|
-
|
|
145
|
-
delete tokens[style.name];
|
|
146
|
-
}); // Iterate through all local figma styles first
|
|
147
|
-
// If it still exists in themeValues, update it (and then remove from themeValues)
|
|
148
|
-
// If it doesn't exist, delete the local figma style
|
|
149
|
-
// For all themeValues remaining we will add them as new
|
|
150
|
-
|
|
151
|
-
localPaintStyles.forEach(function (style) {
|
|
152
|
-
// If there's a rename mapping for this style name
|
|
153
|
-
// Rename it first, then follow up with value updates
|
|
154
|
-
if (renameMap[style.name]) {
|
|
155
|
-
console.log("=> ".concat(style.name, " renamed to ").concat(renameMap[style.name], "!"));
|
|
156
|
-
style.name = renameMap[style.name];
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
var token = tokens[style.name]; // The local style was in our theme, but no more!
|
|
160
|
-
// It's time to delete it.
|
|
161
|
-
|
|
162
|
-
if (!token) {
|
|
163
|
-
console.log("=> ".concat(style.name, " paint style no longer exists, removing."));
|
|
164
|
-
style.remove();
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (token.attributes.group !== 'paint') {
|
|
169
|
-
// The token is no longer a paint style, time to remove it!
|
|
170
|
-
console.log("=> ".concat(style.name, " is no longer a paint, removing!"));
|
|
171
|
-
style.remove();
|
|
172
|
-
return;
|
|
173
|
-
} // Local style exists that also exists in our tokens!
|
|
174
|
-
// Update it and then remove from themeValues.
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
console.log("=> ".concat(style.name, " paint style has been updated!")); // Mutating is how Figma updates.
|
|
178
|
-
|
|
179
|
-
style.paints = [createPaint(token.value)];
|
|
180
|
-
style.description = formatDescription(token); // Remove from themeValues so it isn't picked up as a new token.
|
|
181
|
-
|
|
182
|
-
delete tokens[style.name];
|
|
183
|
-
}); // eslint-disable-next-line guard-for-in
|
|
184
|
-
|
|
185
|
-
for (var key in tokens) {
|
|
186
|
-
var token = tokens[key];
|
|
187
|
-
|
|
188
|
-
if (token.attributes.group === 'paint') {
|
|
189
|
-
var newStyle = figma.createPaintStyle();
|
|
190
|
-
newStyle.name = key;
|
|
191
|
-
newStyle.description = formatDescription(token);
|
|
192
|
-
newStyle.paints = [createPaint(token.value)];
|
|
193
|
-
console.log("=> ".concat(key, " paint style has been added!"));
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (token.attributes.group === 'shadow') {
|
|
197
|
-
var _newStyle = figma.createEffectStyle();
|
|
198
|
-
|
|
199
|
-
_newStyle.name = key;
|
|
200
|
-
_newStyle.description = formatDescription(token);
|
|
201
|
-
_newStyle.effects = createEffects(token.value);
|
|
202
|
-
console.log("=> ".concat(key, " shadow style has been added!"));
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if (typeof module !== 'undefined') {
|
|
208
|
-
module.exports = {
|
|
209
|
-
synchronizeFigmaTokens: synchronizeFigmaTokens,
|
|
210
|
-
createPaint: createPaint,
|
|
211
|
-
createEffects: createEffects,
|
|
212
|
-
formatDescription: formatDescription
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
export {};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { PaintToken, ShadowToken } from '../types';
|
|
2
|
-
import type { FigmaEffect, FigmaPaint } from './types';
|
|
3
|
-
declare function createPaint(hex: string): FigmaPaint;
|
|
4
|
-
declare function createEffects(value: ShadowToken<string>['value']): FigmaEffect[];
|
|
5
|
-
/**
|
|
6
|
-
* Formats a token description for use in Figma,
|
|
7
|
-
* including deprecated warnings
|
|
8
|
-
*
|
|
9
|
-
* @param token
|
|
10
|
-
*/
|
|
11
|
-
declare function formatDescription(token: PaintToken<string> | ShadowToken<string>): string;
|
|
12
|
-
export declare type CreateEffects = typeof createEffects;
|
|
13
|
-
export declare type CreatePaint = typeof createPaint;
|
|
14
|
-
export declare type FormatDescription = typeof formatDescription;
|
|
15
|
-
/**
|
|
16
|
-
* Adds tokens under a specified theme as paint styles to Figma.
|
|
17
|
-
*
|
|
18
|
-
* @param {*} themeName name of the theme, e.g. "dark". Tokens will be added under this folder name.
|
|
19
|
-
* @param {*} tokens
|
|
20
|
-
* @param {*} renameMap mapping object for tokens that should be renamed. example { 'old/token': 'new/token'}
|
|
21
|
-
*/
|
|
22
|
-
declare function synchronizeFigmaTokens(themeName: string, tokens: Record<string, PaintToken<string> | ShadowToken<string>>, renameMap?: Record<string, string>): void;
|
|
23
|
-
export declare type SynchronizeFigmaTokens = typeof synchronizeFigmaTokens;
|
|
24
|
-
export {};
|