figma-tokens-flattener 1.1.18 → 1.2.18

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 (2) hide show
  1. package/index.js +6 -4
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -19,7 +19,6 @@ function flattenColorGroups(colorGroups, variablesMap) {
19
19
  const shadeObj = shades[shadeKey];
20
20
  if (shadeObj && typeof shadeObj === 'object' && shadeObj.hasOwnProperty('value')) {
21
21
  const flatKey = `${groupName}.${shadeKey}`;
22
- // flattened[flatKey] = shadeObj.value.toLowerCase();
23
22
  let resolvedValue = resolveVariableReference(shadeObj.value, variablesMap);
24
23
  flattened[flatKey] = resolvedValue.toLowerCase();
25
24
  } else {
@@ -112,8 +111,8 @@ function flattenMapTokens(value, contextTokens, variablesMap) { // Добавл
112
111
  if (typeof value !== 'string') return value;
113
112
  const str = value.trim();
114
113
 
115
- // Checking whether the string is a reference to an external variable (for example, {Testname.core.color.100})
116
- const externalReferenceMatch = str.match(/^(\{([A-Za-z_][\w.%-]*\.[\w.%-]*\.[\w.%-]+(?:\.[\w.%-]+)*)\})$/);
114
+ // Checking whether the string is a reference to an external variable (for example, {Testname.core.color.100} or {Testname.core.color.100 00})
115
+ const externalReferenceMatch = str.match(/^(\{([A-Za-z_][\w.%-]*\.[\w.%-]*\.[\w.%-\s]+(?:\.[\w.%-\s]*)*)\})$/);
117
116
  if (externalReferenceMatch && variablesMap) {
118
117
  const fullReference = externalReferenceMatch[1];
119
118
  // Calling resolveVariableReference to substitute a value from a variablesMap
@@ -481,7 +480,7 @@ function resolveVariableReference(value, variablesMap) {
481
480
  const reference = value.slice(1, -1);
482
481
 
483
482
  const dotCount = (reference.match(/\./g) || []).length;
484
- if (dotCount < 3) {
483
+ if (dotCount < 2) {
485
484
  // Link to styles within tokens.json is not made up of variables
486
485
  return value;
487
486
  }
@@ -509,6 +508,9 @@ function resolveVariableReference(value, variablesMap) {
509
508
 
510
509
  // Checking if the final object has the 'value' property.
511
510
  if (currentLevel && typeof currentLevel === 'object' && Object.prototype.hasOwnProperty.call(currentLevel, 'value')) {
511
+ if (typeof currentLevel.value === 'string' && currentLevel.value.startsWith('{') && currentLevel.value.endsWith('}')) {
512
+ return resolveVariableReference(currentLevel.value, variablesMap);
513
+ }
512
514
  return currentLevel.value;
513
515
  } else {
514
516
  console.warn(`The final object along the path "${reference}" does not contain the 'value' property. Link: ${value}.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "figma-tokens-flattener",
3
- "version": "1.1.18",
3
+ "version": "1.2.18",
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": {