figma-tokens-flattener 1.0.16 → 1.0.17

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 (3) hide show
  1. package/consts.js +3 -0
  2. package/index.js +21 -0
  3. package/package.json +1 -1
package/consts.js ADDED
@@ -0,0 +1,3 @@
1
+ const REUSED_KEYS = ["lineType", "fontWeightItalic", "boxShadow", "boxShadowSecondary", "boxShadowTertiary", "focusPrimary", "focusError", "focusWarning", "colorMenuDarkBg", "colorMenuSubItemBg"];
2
+
3
+ module.exports = REUSED_KEYS;
package/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
+ const REUSED_KEYS = require('./consts.js');
5
6
 
6
7
  /* Color */
7
8
  function flattenColorGroups(colorGroups) {
@@ -410,6 +411,22 @@ function flattenComponentsTokens(componentsTokens, contextTokens) {
410
411
  return flattened;
411
412
  }
412
413
 
414
+ function addReusedTokens(lightTokens, darkTokens) {
415
+ const reusedCollection = {};
416
+
417
+ Object.keys(lightTokens).forEach((key) => {
418
+ const value = lightTokens[key];
419
+
420
+ if (typeof value === 'number' || REUSED_KEYS.includes(key)) {
421
+ reusedCollection[key] = value;
422
+ }
423
+
424
+ });
425
+
426
+ // darkTokens will take precedence in case of a key match.
427
+ return { ...darkTokens, ...reusedCollection };
428
+ }
429
+
413
430
  function flatten() {
414
431
  const configFilePath = path.resolve('./figma-tokens-flattener-config.json');
415
432
  let config = {};
@@ -503,6 +520,10 @@ function flatten() {
503
520
  const flattenDefaultValues = flattenDefaultValueTokens(allTokensData[darkDefaultKey]);
504
521
  darkTokens = { ...flattenDefaultValues, ...darkTokens };
505
522
 
523
+ // The tokens of the light theme contain numeric values, while the dark theme does not contain them to avoid duplication.
524
+ // Need to add these values, and some lines (shadows, focus, etc.) because only the light theme has them too.
525
+ darkTokens = addReusedTokens(lightTokens, darkTokens);
526
+
506
527
  const flattenedComponents = flattenComponentsTokens(allTokensData[darkFullKey], darkTokens);
507
528
  darkTokens = { ...darkTokens, components: flattenedComponents };
508
529
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "figma-tokens-flattener",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "description": "A tool for transforming Ant Design tokens from Tokens Studio for Figma (Single file) into flat style mappings for light and dark themes.",
5
5
  "main": "index.js",
6
6
  "bin": {