@sit-onyx/figma-utils 1.0.0-beta.5 → 1.0.0-beta.6
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.
|
@@ -26,7 +26,7 @@ export declare const parseFigmaVariables: (apiResponse: FigmaVariablesApiRespons
|
|
|
26
26
|
* @param value Figma variable value
|
|
27
27
|
* @param allVariables Object of all variables. Needed for variables that use aliases.
|
|
28
28
|
*/
|
|
29
|
-
export declare const resolveFigmaVariableValue: (value: VariableValue, allVariables: Record<string, Variable>, remBase?: ParseFigmaVariablesOptions["remBase"]) => string;
|
|
29
|
+
export declare const resolveFigmaVariableValue: (value: VariableValue, allVariables: Record<string, Variable>, remBase?: ParseFigmaVariablesOptions["remBase"], name?: string) => string;
|
|
30
30
|
/**
|
|
31
31
|
* Converts a RGBA value to a hex color.
|
|
32
32
|
* Transparency will only be added if its not 1, e.g. "#000000" instead of "#000000ff"
|
package/dist/variables/parse.js
CHANGED
|
@@ -21,7 +21,7 @@ export const parseFigmaVariables = (apiResponse, options) => {
|
|
|
21
21
|
// parse variable value for every mode
|
|
22
22
|
Object.values(collection.modes).forEach((mode) => {
|
|
23
23
|
const variableName = normalizeVariableName(variable.name);
|
|
24
|
-
const variableValue = resolveFigmaVariableValue(variable.valuesByMode?.[mode.modeId], apiResponse.meta.variables, options?.remBase);
|
|
24
|
+
const variableValue = resolveFigmaVariableValue(variable.valuesByMode?.[mode.modeId], apiResponse.meta.variables, options?.remBase, variableName);
|
|
25
25
|
// add/update parsed variable value
|
|
26
26
|
const existingIndex = parsedData.findIndex((i) => i.modeName === mode.name);
|
|
27
27
|
if (existingIndex !== -1) {
|
|
@@ -73,8 +73,10 @@ export const parseFigmaVariables = (apiResponse, options) => {
|
|
|
73
73
|
* @param value Figma variable value
|
|
74
74
|
* @param allVariables Object of all variables. Needed for variables that use aliases.
|
|
75
75
|
*/
|
|
76
|
-
export const resolveFigmaVariableValue = (value, allVariables, remBase = 16) => {
|
|
76
|
+
export const resolveFigmaVariableValue = (value, allVariables, remBase = 16, name) => {
|
|
77
77
|
if (typeof value === "number") {
|
|
78
|
+
if (name?.includes("font-weight"))
|
|
79
|
+
return `${value}`;
|
|
78
80
|
// numeric value, parse as rem or pixel value
|
|
79
81
|
// note: value 0 should also be parsed as "0rem" instead of just "0" because otherwise
|
|
80
82
|
// the CSS variable could not be used together with "calc()"
|
|
@@ -82,6 +84,9 @@ export const resolveFigmaVariableValue = (value, allVariables, remBase = 16) =>
|
|
|
82
84
|
return `${value}px`;
|
|
83
85
|
return `${value / remBase}rem`;
|
|
84
86
|
}
|
|
87
|
+
if (typeof value === "string") {
|
|
88
|
+
return `"${value}"`;
|
|
89
|
+
}
|
|
85
90
|
if ("type" in value) {
|
|
86
91
|
// parse value as alias
|
|
87
92
|
if (value.type !== "VARIABLE_ALIAS") {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sit-onyx/figma-utils",
|
|
3
3
|
"description": "Utility functions and CLI for importing data from the Figma API into different formats (e.g. CSS, SCSS etc.)",
|
|
4
|
-
"version": "1.0.0-beta.
|
|
4
|
+
"version": "1.0.0-beta.6",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"@sit-onyx/figma-utils": "./dist/cli.js"
|