@sit-onyx/figma-utils 1.1.1 → 1.1.2-dev-20261123100908
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/LICENSE.txt +1 -1
- package/README.md +2 -2
- package/dist/cli.js +1 -1
- package/dist/commands/import-flags.js +1 -1
- package/dist/commands/import-icons.js +1 -1
- package/dist/commands/import-variables.js +1 -1
- package/dist/types/figma.d.ts +10 -7
- package/dist/utils/optimize.d.ts +2 -1
- package/dist/utils/optimize.js +2 -1
- package/dist/variables/generate.d.ts +22 -17
- package/dist/variables/generate.js +21 -16
- package/dist/variables/parse.d.ts +10 -4
- package/dist/variables/parse.js +7 -3
- package/package.json +16 -16
package/LICENSE.txt
CHANGED
|
@@ -175,7 +175,7 @@
|
|
|
175
175
|
|
|
176
176
|
END OF TERMS AND CONDITIONS
|
|
177
177
|
|
|
178
|
-
Copyright 2023 Schwarz IT KG
|
|
178
|
+
Copyright 2023 Schwarz Digits IT KG
|
|
179
179
|
|
|
180
180
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
181
|
you may not use this file except in compliance with the License.
|
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<div align="center" style="text-align: center">
|
|
2
|
-
|
|
2
|
+
<img alt="Onyx logo" src="https://raw.githubusercontent.com/SchwarzIT/onyx/main/packages/assets/src/onyx-brand/signet.svg" height="96px">
|
|
3
3
|
</div>
|
|
4
4
|
|
|
5
5
|
<br>
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
# @sit-onyx/figma-utils
|
|
8
8
|
|
|
9
9
|
Utility functions and CLI for importing data from the Figma API into different formats (e.g. CSS, SCSS etc.).
|
|
10
|
-
Created by [Schwarz
|
|
10
|
+
Created by [Schwarz Digits](https://schwarz-digits.de).
|
|
11
11
|
|
|
12
12
|
## Use as CLI
|
|
13
13
|
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { Command } from "commander";
|
|
3
2
|
import fs from "node:fs";
|
|
4
3
|
import { fileURLToPath, URL } from "node:url";
|
|
4
|
+
import { Command } from "commander";
|
|
5
5
|
import { importFlagsCommand } from "./commands/import-flags.js";
|
|
6
6
|
import { importIconsCommand } from "./commands/import-icons.js";
|
|
7
7
|
import { importVariablesCommand } from "./commands/import-variables.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
1
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
2
|
import path from "node:path";
|
|
3
|
+
import { Command } from "commander";
|
|
4
4
|
import { writeFlagMetadata } from "../flags/generate.js";
|
|
5
5
|
import { parseComponentsToFlags } from "../flags/parse.js";
|
|
6
6
|
import { fetchFigmaComponents, fetchFigmaSVGs } from "../index.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
1
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
2
|
import path from "node:path";
|
|
3
|
+
import { Command } from "commander";
|
|
4
4
|
import { writeIconMetadata } from "../icons/generate.js";
|
|
5
5
|
import { parseComponentsToIcons } from "../icons/parse.js";
|
|
6
6
|
import { fetchFigmaComponents, fetchFigmaSVGs } from "../index.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
1
|
import fs from "node:fs";
|
|
3
2
|
import path from "node:path";
|
|
3
|
+
import { Command } from "commander";
|
|
4
4
|
import { DEFAULT_MODE_NAME, fetchFigmaVariables, generateAsCSS, generateAsJSON, generateAsSCSS, parseFigmaVariables, } from "../index.js";
|
|
5
5
|
export const importVariablesCommand = new Command("import-variables")
|
|
6
6
|
.description("CLI tool to import Figma variables into CSS, SCSS etc. variables.")
|
package/dist/types/figma.d.ts
CHANGED
|
@@ -35,17 +35,20 @@ export type ColorsAlias = {
|
|
|
35
35
|
id: string;
|
|
36
36
|
};
|
|
37
37
|
export type ParsedVariable = {
|
|
38
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* Figma mode name or undefined if its the default mode.
|
|
40
|
+
*/
|
|
39
41
|
modeName?: string;
|
|
40
42
|
/**
|
|
41
43
|
* Mapping from variable name to its value.
|
|
44
|
+
*
|
|
42
45
|
* @example
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
46
|
+
* ```json
|
|
47
|
+
* {
|
|
48
|
+
* "primary-100": "#ffffff",
|
|
49
|
+
* "border-radius-s": "1rem",
|
|
50
|
+
* }
|
|
51
|
+
* ```;
|
|
49
52
|
*/
|
|
50
53
|
variables: Record<string, string>;
|
|
51
54
|
};
|
package/dist/utils/optimize.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Optimizes the given SVG content for usage inside an icon library using [svgo](https://svgo.dev).
|
|
3
3
|
* Will apply the following optimizations:
|
|
4
|
-
*
|
|
4
|
+
*
|
|
5
|
+
* - Remove dimensions (height/width) so it can be set via CSS
|
|
5
6
|
* - "preset-default" to reduce file size and redundant information
|
|
6
7
|
* - (only if type "icon"): remove all fills so the color can be set via CSS
|
|
7
8
|
*/
|
package/dist/utils/optimize.js
CHANGED
|
@@ -2,7 +2,8 @@ import { optimize } from "svgo";
|
|
|
2
2
|
/**
|
|
3
3
|
* Optimizes the given SVG content for usage inside an icon library using [svgo](https://svgo.dev).
|
|
4
4
|
* Will apply the following optimizations:
|
|
5
|
-
*
|
|
5
|
+
*
|
|
6
|
+
* - Remove dimensions (height/width) so it can be set via CSS
|
|
6
7
|
* - "preset-default" to reduce file size and redundant information
|
|
7
8
|
* - (only if type "icon"): remove all fills so the color can be set via CSS
|
|
8
9
|
*/
|
|
@@ -16,9 +16,10 @@ export type GenerateAsCSSOptions = BaseGenerateOptions & {
|
|
|
16
16
|
/**
|
|
17
17
|
* Selector to use for the CSS format. You can use {mode} as placeholder for the mode name.
|
|
18
18
|
*
|
|
19
|
-
* @default ":root"
|
|
20
19
|
* @example
|
|
21
|
-
*
|
|
20
|
+
* for the mode named "dark", passing the selector "html.{mode}" will result in "html.dark"
|
|
21
|
+
*
|
|
22
|
+
* @default ":root"
|
|
22
23
|
*/
|
|
23
24
|
selector?: string;
|
|
24
25
|
};
|
|
@@ -44,22 +45,23 @@ export declare const generateAsSCSS: (data: ParsedVariable, options?: BaseGenera
|
|
|
44
45
|
*/
|
|
45
46
|
export declare const generateAsJSON: (data: ParsedVariable) => string;
|
|
46
47
|
/**
|
|
47
|
-
* Recursively resolves the value for the given variable name.
|
|
48
|
-
*
|
|
49
|
-
*
|
|
48
|
+
* Recursively resolves the value for the given variable name. So if the value is an alias, the
|
|
49
|
+
* output will be the actual alias value instead of a reference by name. If the value is not an
|
|
50
|
+
* alias, its value will be directly returned.
|
|
50
51
|
*
|
|
51
|
-
* @param name Variable name to resolve
|
|
52
|
-
* @param allVariables All available variables
|
|
53
52
|
* @example
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
53
|
+
* ```ts
|
|
54
|
+
* const allVariables = {
|
|
55
|
+
* "variable-a": 42,
|
|
56
|
+
* "variable-b": "{variable-a}",
|
|
57
|
+
* };
|
|
59
58
|
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
59
|
+
* const resolvedValue = resolveValue("variable-b", allVariables);
|
|
60
|
+
* // const resolvedValue = 42;
|
|
61
|
+
* ```;
|
|
62
|
+
*
|
|
63
|
+
* @param name Variable name to resolve
|
|
64
|
+
* @param allVariables All available variables
|
|
63
65
|
*/
|
|
64
66
|
export declare const resolveValue: (name: string, allVariables: ParsedVariable["variables"]) => string;
|
|
65
67
|
/**
|
|
@@ -70,8 +72,11 @@ export declare const generateTimestampComment: (modeName?: string) => string;
|
|
|
70
72
|
* Checks whether the given variable value is an alias / variable reference to another variable.
|
|
71
73
|
* Alias values are enclosed by curly braces.
|
|
72
74
|
*
|
|
73
|
-
* @example
|
|
74
|
-
*
|
|
75
|
+
* @example
|
|
76
|
+
* "{your-variable-name}";
|
|
77
|
+
*
|
|
78
|
+
* @returns `isAlias` whether the variable is an alias and `aliasName` the raw variable name without
|
|
79
|
+
* curly braces.
|
|
75
80
|
*/
|
|
76
81
|
export declare const isAliasVariable: (variableValue?: string) => {
|
|
77
82
|
isAlias: boolean;
|
|
@@ -36,22 +36,23 @@ export const generateAsJSON = (data) => {
|
|
|
36
36
|
return `${JSON.stringify(variables, null, 2)}\n`;
|
|
37
37
|
};
|
|
38
38
|
/**
|
|
39
|
-
* Recursively resolves the value for the given variable name.
|
|
40
|
-
*
|
|
41
|
-
*
|
|
39
|
+
* Recursively resolves the value for the given variable name. So if the value is an alias, the
|
|
40
|
+
* output will be the actual alias value instead of a reference by name. If the value is not an
|
|
41
|
+
* alias, its value will be directly returned.
|
|
42
42
|
*
|
|
43
|
-
* @param name Variable name to resolve
|
|
44
|
-
* @param allVariables All available variables
|
|
45
43
|
* @example
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
44
|
+
* ```ts
|
|
45
|
+
* const allVariables = {
|
|
46
|
+
* "variable-a": 42,
|
|
47
|
+
* "variable-b": "{variable-a}",
|
|
48
|
+
* };
|
|
51
49
|
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
50
|
+
* const resolvedValue = resolveValue("variable-b", allVariables);
|
|
51
|
+
* // const resolvedValue = 42;
|
|
52
|
+
* ```;
|
|
53
|
+
*
|
|
54
|
+
* @param name Variable name to resolve
|
|
55
|
+
* @param allVariables All available variables
|
|
55
56
|
*/
|
|
56
57
|
export const resolveValue = (name, allVariables) => {
|
|
57
58
|
const { isAlias, aliasName } = isAliasVariable(allVariables[name]);
|
|
@@ -72,8 +73,11 @@ export const generateTimestampComment = (modeName) => {
|
|
|
72
73
|
* Checks whether the given variable value is an alias / variable reference to another variable.
|
|
73
74
|
* Alias values are enclosed by curly braces.
|
|
74
75
|
*
|
|
75
|
-
* @example
|
|
76
|
-
*
|
|
76
|
+
* @example
|
|
77
|
+
* "{your-variable-name}";
|
|
78
|
+
*
|
|
79
|
+
* @returns `isAlias` whether the variable is an alias and `aliasName` the raw variable name without
|
|
80
|
+
* curly braces.
|
|
77
81
|
*/
|
|
78
82
|
export const isAliasVariable = (variableValue) => {
|
|
79
83
|
if (!variableValue)
|
|
@@ -89,7 +93,8 @@ export const isAliasVariable = (variableValue) => {
|
|
|
89
93
|
* @param variables Variable data (name + value)
|
|
90
94
|
* @param variablesDarkTheme Variable data (name +value) for additionally dark theme
|
|
91
95
|
* @param nameFormatter Function to format the variable name
|
|
92
|
-
* @param aliasFormatter Function to format a reference to another variable (e.g. `var(--name)` for
|
|
96
|
+
* @param aliasFormatter Function to format a reference to another variable (e.g. `var(--name)` for
|
|
97
|
+
* CSS)
|
|
93
98
|
* @param options Generator options
|
|
94
99
|
*/
|
|
95
100
|
const getCssOrScssVariableContent = (variables, nameFormatter, aliasFormatter, options) => {
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { FigmaVariablesApiResponse, ParsedVariable, RGBAValue, Variable, VariableValue } from "../types/figma.js";
|
|
2
2
|
export type ParseFigmaVariablesOptions = {
|
|
3
3
|
/**
|
|
4
|
-
* Base for converting pixel in rem. Set to `false` for disabling rem conversion and use pixel
|
|
4
|
+
* Base for converting pixel in rem. Set to `false` for disabling rem conversion and use pixel
|
|
5
|
+
* values.
|
|
6
|
+
*
|
|
5
7
|
* @default 16
|
|
6
8
|
*/
|
|
7
9
|
remBase?: number | false;
|
|
8
10
|
};
|
|
9
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* Default Figma mode name if only one mode exists and no other name is specified by the designer.
|
|
13
|
+
*/
|
|
10
14
|
export declare const DEFAULT_MODE_NAME: "Mode 1";
|
|
11
15
|
/**
|
|
12
16
|
* Parses Figma variables received from the Figma API to a minimal JSON.
|
|
@@ -18,10 +22,11 @@ export declare const DEFAULT_MODE_NAME: "Mode 1";
|
|
|
18
22
|
export declare const parseFigmaVariables: (apiResponse: FigmaVariablesApiResponse, options?: ParseFigmaVariablesOptions) => ParsedVariable[];
|
|
19
23
|
/**
|
|
20
24
|
* Resolves the given Figma variable value to a string value. Value types:
|
|
25
|
+
*
|
|
21
26
|
* - number: converted to rem, e.g. 16 => "1rem"
|
|
22
27
|
* - color: converted to HEX color, e.g. {r:1, g: 1, b: 1, a: 1} => "#ffffff"
|
|
23
|
-
* - alias: referenced with variable name, e.g. "--primary-100" => "{--primary-100}"
|
|
24
|
-
*
|
|
28
|
+
* - alias: referenced with variable name, e.g. "--primary-100" => "{--primary-100}" (curly brackets
|
|
29
|
+
* will indicate that the value is an alias / reference)
|
|
25
30
|
*
|
|
26
31
|
* @param value Figma variable value
|
|
27
32
|
* @param allVariables Object of all variables. Needed for variables that use aliases.
|
|
@@ -34,6 +39,7 @@ export declare const resolveFigmaVariableValue: (value: VariableValue, allVariab
|
|
|
34
39
|
export declare const rgbaToHex: (value: RGBAValue) => string;
|
|
35
40
|
/**
|
|
36
41
|
* Normalizes the given variable name by apply these transformations:
|
|
42
|
+
*
|
|
37
43
|
* - replace slashes with "-"
|
|
38
44
|
* - replace whitespace with "-"
|
|
39
45
|
* - replace "+" with "-"
|
package/dist/variables/parse.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Default Figma mode name if only one mode exists and no other name is specified by the designer.
|
|
3
|
+
*/
|
|
2
4
|
export const DEFAULT_MODE_NAME = "Mode 1";
|
|
3
5
|
/**
|
|
4
6
|
* Parses Figma variables received from the Figma API to a minimal JSON.
|
|
@@ -65,10 +67,11 @@ export const parseFigmaVariables = (apiResponse, options) => {
|
|
|
65
67
|
};
|
|
66
68
|
/**
|
|
67
69
|
* Resolves the given Figma variable value to a string value. Value types:
|
|
70
|
+
*
|
|
68
71
|
* - number: converted to rem, e.g. 16 => "1rem"
|
|
69
72
|
* - color: converted to HEX color, e.g. {r:1, g: 1, b: 1, a: 1} => "#ffffff"
|
|
70
|
-
* - alias: referenced with variable name, e.g. "--primary-100" => "{--primary-100}"
|
|
71
|
-
*
|
|
73
|
+
* - alias: referenced with variable name, e.g. "--primary-100" => "{--primary-100}" (curly brackets
|
|
74
|
+
* will indicate that the value is an alias / reference)
|
|
72
75
|
*
|
|
73
76
|
* @param value Figma variable value
|
|
74
77
|
* @param allVariables Object of all variables. Needed for variables that use aliases.
|
|
@@ -117,6 +120,7 @@ export const rgbaToHex = (value) => {
|
|
|
117
120
|
};
|
|
118
121
|
/**
|
|
119
122
|
* Normalizes the given variable name by apply these transformations:
|
|
123
|
+
*
|
|
120
124
|
* - replace slashes with "-"
|
|
121
125
|
* - replace whitespace with "-"
|
|
122
126
|
* - replace "+" with "-"
|
package/package.json
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sit-onyx/figma-utils",
|
|
3
|
+
"version": "1.1.2-dev-20261123100908",
|
|
3
4
|
"description": "Utility functions and CLI for importing data from the Figma API into different formats (e.g. CSS, SCSS etc.)",
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
5
|
+
"homepage": "https://onyx.schwarz/development/packages/figma-utils.html",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/SchwarzIT/onyx/issues"
|
|
8
|
+
},
|
|
7
9
|
"license": "Apache-2.0",
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
+
"author": "Schwarz Digits IT KG",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/SchwarzIT/onyx",
|
|
14
|
+
"directory": "packages/figma-utils"
|
|
10
15
|
},
|
|
11
16
|
"bin": {
|
|
12
17
|
"@sit-onyx/figma-utils": "./dist/cli.js"
|
|
@@ -14,6 +19,7 @@
|
|
|
14
19
|
"files": [
|
|
15
20
|
"dist"
|
|
16
21
|
],
|
|
22
|
+
"type": "module",
|
|
17
23
|
"types": "./dist/index.d.ts",
|
|
18
24
|
"exports": {
|
|
19
25
|
".": {
|
|
@@ -21,20 +27,14 @@
|
|
|
21
27
|
"import": "./dist/index.js"
|
|
22
28
|
}
|
|
23
29
|
},
|
|
24
|
-
"homepage": "https://onyx.schwarz/development/packages/figma-utils.html",
|
|
25
|
-
"repository": {
|
|
26
|
-
"type": "git",
|
|
27
|
-
"url": "https://github.com/SchwarzIT/onyx",
|
|
28
|
-
"directory": "packages/figma-utils"
|
|
29
|
-
},
|
|
30
|
-
"bugs": {
|
|
31
|
-
"url": "https://github.com/SchwarzIT/onyx/issues"
|
|
32
|
-
},
|
|
33
30
|
"dependencies": {
|
|
34
|
-
"commander": "^15.
|
|
31
|
+
"commander": "^15.1.0"
|
|
35
32
|
},
|
|
36
33
|
"optionalDependencies": {
|
|
37
|
-
"svgo": "^4.0
|
|
34
|
+
"svgo": "^4.1.0"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=22"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "pnpm run '/type-check|build-only/'",
|