tokens-bruecke 2.8.0

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/README.md ADDED
@@ -0,0 +1,655 @@
1
+ # TokensBrücke — Figma plugin
2
+
3
+ <a href="https://www.figma.com/community/plugin/1254538877056388290" target="_blank">
4
+ <img src="./readme-assets/preview.webp" alt="preview" width="100%">
5
+ </a>
6
+
7
+ ## What is this plugin for?
8
+
9
+ The plugin converts Figma variables into design-tokens JSON that are compatible with the latest [Design Tokens specification](https://design-tokens.github.io/community-group/format/).
10
+
11
+ ---
12
+
13
+ ## Table of contents
14
+
15
+ - [TokensBrücke — Figma plugin](#tokensbrücke--figma-plugin)
16
+ - [What is this plugin for?](#what-is-this-plugin-for)
17
+ - [Table of contents](#table-of-contents)
18
+ - [New version 2.0.0](#new-version-200)
19
+ - [How to use](#how-to-use)
20
+ - [General settings](#general-settings)
21
+ - [Color mode](#color-mode)
22
+ - [Include styles](#include-styles)
23
+ - [Add styles to](#add-styles-to)
24
+ - [Include variable scopes](#include-variable-scopes)
25
+ - [Use DTCG keys format](#use-dtcg-keys-format)
26
+ - [Include `.value` string for aliases](#include-value-string-for-aliases)
27
+ - [Include Figma metadata](#include-figma-metadata)
28
+ - [Use as cli tool](#use-as-cli-tool)
29
+ - [Installation](#installation)
30
+ - [Usage](#usage)
31
+ - [Options](#options)
32
+ - [CLI Configuration File](#cli-configuration-file)
33
+ - [Push to server](#push-to-server)
34
+ - [JSONBin](#jsonbin)
35
+ - [GitHub](#github)
36
+ - [GitHub PR](#github-pr)
37
+ - [GitLab](#gitlab)
38
+ - [Custom server](#custom-server)
39
+ - [Show output](#show-output)
40
+ - [Config autosaving](#config-autosaving)
41
+ - [Styles support](#styles-support)
42
+ - [Typography](#typography)
43
+ - [Colors](#colors)
44
+ - [Grids](#grids)
45
+ - [Shadows](#shadows)
46
+ - [Blur](#blur)
47
+ - [Multiple `Shadow` and `Blur` styles support](#multiple-shadow-and-blur-styles-support)
48
+ - [Tokens structure](#tokens-structure)
49
+ - [Aliases handling](#aliases-handling)
50
+ - [Include `.value` string for aliases](#include-value-string-for-aliases-1)
51
+ - [Handle variables from another file](#handle-variables-from-another-file)
52
+ - [Handle modes](#handle-modes)
53
+ - [Variables types conversion](#variables-types-conversion)
54
+ - [Design tokens types](#design-tokens-types)
55
+ - [Scopes lemitations](#scopes-lemitations)
56
+ - [Style Dictionary support](#style-dictionary-support)
57
+ - [Contribution 🚧](#contribution-)
58
+ - [Feedback](#feedback)
59
+
60
+ ---
61
+
62
+ ## New version 2.0.0
63
+
64
+ In the new version of the plugin all mode variables moved into the `$extensions` / `modes` object.
65
+ This is how Terrazzo (formerly “Cobalt UI”) works with multiple modes. Check it here — [https://terrazzo.app/docs/](https://terrazzo.app/docs/)
66
+
67
+ You can download and install previos version `1.6.1` here — [github.com/tokens-bruecke/figma-plugin/files/13536853/build.zip](https://github.com/tokens-bruecke/figma-plugin/files/13536853/build.zip)
68
+
69
+ ## How to use
70
+
71
+ 1. Install the plugin from the [Figma Community](https://www.figma.com/community/plugin/1254538877056388290).
72
+ 2. Make sure you have variables in your Figma file.
73
+ 3. Run the plugin.
74
+ 4. Adjust the settings.
75
+ 5. Then you can download the JSON file or push it to on of the [supported services](#link).
76
+
77
+ ---
78
+
79
+ ## General settings
80
+
81
+ ### Color mode
82
+
83
+ Allows you to choose the color mode for the generated JSON. Default value is `HEX`. The plugin supports the following color modes:
84
+
85
+ - `HEX` — HEX color format. Could be converted into `HEXA` if the color has an alpha channel.
86
+ - `RGBA CSS` — RGBA color format in CSS syntax, e.g. `rgba(0, 0, 0, 0.5)`.
87
+ - `RGBA Object` — RGBA color format in object syntax, e.g. `{ r: 0, g: 0, b: 0, a: 0.5 }`.
88
+ - `HSLA CSS` — HSLA color format in CSS syntax, e.g. `hsla(0, 0%, 0%, 0.5)`.
89
+ - `HSLA Object` — HSLA color format in object syntax, e.g. `{ h: 0, s: 0, l: 0, a: 0.5 }`.
90
+
91
+ ### Include styles
92
+
93
+ Allows you to include styles into the generated JSON. See more about styles support in the [Styles support](#styles-support) section.
94
+
95
+ There is an option to rename each style's group and give it a custom name for better organization.
96
+
97
+ ![rename-styles](readme-assets/rename-styles.gif)
98
+
99
+ ### Add styles to
100
+
101
+ Allows you to choose where to put styles in the generated JSON. By default, the selected value is `Keep separate`. In this case styles will be added into the root of the JSON and will be treated as collections. There is also an option to add styles into the corresponding collection (fig.4).
102
+
103
+ ![fig.4](readme-assets/fig4.webp)
104
+
105
+ ### Include variable scopes
106
+
107
+ Each Figma variable has a [scope property](https://www.figma.com/plugin-docs/api/VariableScope). The plugin allows you to include scopes into the generated JSON. It will be included as an array of strings without any transformations.
108
+
109
+ ```json
110
+ {
111
+ "button": {
112
+ "background": {
113
+ "type": "color",
114
+ "value": "#000000",
115
+ "scopes": ["ALL_SCOPES"]
116
+ }
117
+ }
118
+ }
119
+ ```
120
+
121
+ ### Use DTCG keys format
122
+
123
+ Is `off` by default. Currently many design tokens tools doesn't support [DTCG keys format](https://design-tokens.github.io/community-group/format/#character-restrictions). All DTCG keys are prefixed with `$` symbol.
124
+
125
+ ```json
126
+ // Without DTCG keys format
127
+ {
128
+ "button": {
129
+ "background": {
130
+ "type": "color",
131
+ "value": "#000000"
132
+ }
133
+ }
134
+ }
135
+
136
+ // With DTCG keys format
137
+ {
138
+ "button": {
139
+ "background": {
140
+ "$type": "color",
141
+ "$value": "#000000",
142
+ }
143
+ }
144
+ }
145
+ ```
146
+
147
+ ### Include `.value` string for aliases
148
+
149
+ Is `off` by default. Allows you to include `.value` string to the end of the path for aliases. It will be added to the alias string.
150
+
151
+ ```json
152
+ {
153
+ "button": {
154
+ "background": {
155
+ "type": "color",
156
+ "value": "{colors.light.primary.10.value}"
157
+ }
158
+ }
159
+ }
160
+ ```
161
+
162
+ If the format is `DTCG`:
163
+
164
+ ```json
165
+ {
166
+ "button": {
167
+ "background": {
168
+ "$type": "color",
169
+ "$value": "{colors.light.primary.10.$value}"
170
+ }
171
+ }
172
+ }
173
+ ```
174
+
175
+ ![fig.13](readme-assets/fig13.webp)
176
+
177
+ ### Include Figma metadata
178
+
179
+ Is `off` by default. Allows you to include Figma metadata like `styleId`, `variableId`, etc. into the generated JSON. It will be added to the `$extensions` object.
180
+
181
+ ```json
182
+ "figma": {
183
+ "codeSyntax": {},
184
+ "variableId": "VariableID:1:4",
185
+ "collection": {
186
+ "id": "VariableCollectionId:1:3",
187
+ "name": "Primitives",
188
+ "defaultModeId": "1:0"
189
+ }
190
+ }
191
+ ```
192
+
193
+ ---
194
+
195
+ ## Use as cli tool
196
+
197
+ > [!WARNING]
198
+ > ⚠️ You need a Figma Enterprise plan to use the Figma REST API for variables.
199
+
200
+ ### Installation
201
+
202
+ To install the CLI globally, run:
203
+
204
+ ```bash
205
+ pnpm add -g tokens-bruecke
206
+ #or npm install -g tokens-bruecke
207
+ ```
208
+
209
+ This will make the `tokens-bruecke` command available globally on your system.
210
+
211
+ ### Usage
212
+
213
+ After installation, you can run the CLI tool using:
214
+
215
+ ```bash
216
+ tokens-bruecke [options]
217
+ ```
218
+
219
+ For example:
220
+
221
+ ```bash
222
+ tokens-bruecke --api-key $FIGMA_TOKEN --file-key $FIGMA_FILE --config config.json --output out/tokens.json
223
+ ```
224
+
225
+ This will fetch figma variables and export them in `out/tokens.json`
226
+
227
+ ### Options
228
+
229
+ Same options than the plugin are available throught the usage of a json file.
230
+
231
+ ### CLI Configuration File
232
+
233
+ You can use a JSON configuration file to specify the export options for the CLI.
234
+
235
+ ```json
236
+ {
237
+ "includedStyles": {
238
+ "text": { "isIncluded": true, "customName": "typography" },
239
+ "effects": { "isIncluded": false, "customName": "effects" },
240
+ "grids": { "isIncluded": false, "customName": "grids" },
241
+ "colors": { "isIncluded": false, "customName": "colors" }
242
+ },
243
+ "includeScopes": true,
244
+ "useDTCGKeys": false,
245
+ "includeValueStringKeyToAlias": true,
246
+ "includeFigmaMetaData": false, // Include Figma metadata like styleId, variableId, etc.
247
+ "colorMode": "hex", // "hex" | "rgba-object" | "rgba-css" | "hsla-object" | "hsla-css";
248
+ "storeStyleInCollection": "none" // Name of one of your collection or "none" to keep them separated
249
+ }
250
+ ```
251
+
252
+ Save this JSON file and pass it to the CLI using the `--config` option:
253
+
254
+ ---
255
+
256
+ ## Push to server
257
+
258
+ With this feature you can connect a server and push the generated JSON directly to it. At the moment the plugin supports [JSONBin](https://jsonbin.io), [GitHub](https://github.com) and custom servers.
259
+
260
+ ![fig.5](readme-assets/fig5.webp)
261
+
262
+ If you connected multiple servers, the plugin will try to push the tokens to all of them one by one.
263
+ In ordere to test if your credentials are valid you can make a test request by clicking the `Push to server` button (fig.6).
264
+
265
+ ![fig.6](readme-assets/fig6.webp)
266
+
267
+ ### [JSONBin](https://jsonbin.io)
268
+
269
+ 1. Open [JSONBin](https://jsonbin.io) and create an account.
270
+ 2. Generate a [new API key](https://jsonbin.io/api-reference/access-keys/create).
271
+ 3. If you want to use an existing bin, copy its ID. Otherwise just leave the ID field empty in the plugin settings.
272
+ 4. Add a name for the bin.
273
+
274
+ ![fig.7](readme-assets/fig7.webp)
275
+
276
+ ### [GitHub](https://github.com)
277
+
278
+ 1. You need to create a [personal access token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) with `repo` scope.
279
+ 2. In the plugin settings paste the token into the `Personal access token` field.
280
+ 3. Add an owner name, repository name and a branch name.
281
+ 4. In the file name field you can specify a path to the file. If the file doesn't exist, it will be created. If the file exists, it will be overwritten. File name should include the file extension, e.g. `tokens.json`.
282
+ 5. You can also specify a commit message.
283
+
284
+ ![fig.8](readme-assets/fig8.webp)
285
+
286
+ ### [GitHub PR](https://github.com)
287
+
288
+ All the steps are the same as for the [GitHub](#github) server, except the last two.
289
+
290
+ - **PR title**. You can specify a title for the PR. If you leave it empty, the plugin will use `chore(tokens): update tokens` as a default title.
291
+ - **PR body**. You can specify a body for the PR. If you leave it empty, the plugin won't add any body to the PR.
292
+
293
+ ![fig.12](readme-assets/fig12.webp)
294
+
295
+ ### [GitLab](https://gitlab.com)
296
+
297
+ 1. You need to create a [project access token](https://docs.gitlab.com/ee/user/project/settings/project_access_tokens.html) with `api` scope.
298
+ 2. In the plugin settings paste the token into the `Project access token` field.
299
+ 3. Add an owner name, repository name and a branch name.
300
+ 4. In the file name field you can specify a path to the file. If the file doesn't exist, it will be created. If the file exists, it will be overwritten. File name should include the file extension, e.g. `tokens.json`. 5. You can also specify a commit message.
301
+
302
+ ![fig.11](readme-assets/fig11.webp)
303
+
304
+ ### Custom server
305
+
306
+ There is a possibilty to connect a custom server. In order to do that you need to specify a URL, a method (by default it's `POST`) and headers.
307
+
308
+ ![fig.9](readme-assets/fig9.webp)
309
+
310
+ ---
311
+
312
+ ## Show output
313
+
314
+ If you want to see the generated JSON, you can enable the `Show output` option. The plugin will show the JSON in the sidebar. The output doesn't update automatically, in order to optimize the performance. So, if you want to see the updated JSON, you need to click the `Update` button.
315
+
316
+ ![fig.10](readme-assets/fig10.webp)
317
+
318
+ ---
319
+
320
+ ## Config autosaving
321
+
322
+ The plugin saves the config automatically. So, you don't need to set it up every time you run the plugin.
323
+
324
+ ---
325
+
326
+ ## Styles support
327
+
328
+ The plugin can support some styles and effects too. Until Figma will support all the styles and effects, the plugin will convert them into the corresponding design tokens types. But it's not a backward compatibility, it's a temporary solution until Figma will support all the styles and effects as variables.
329
+
330
+ Supported styles:
331
+
332
+ - Typography
333
+ - Colors
334
+ - Grids
335
+ - Shadows (including `inset` shadows)
336
+ - Blur (including `background` and `layer` blur)
337
+
338
+ ### Typography
339
+
340
+ ```json
341
+ "extralight": {
342
+ "type": "typography",
343
+ "value": {
344
+ "fontFamily": "Inter",
345
+ "fontWeight": 400,
346
+ "fontSize": "18px",
347
+ "lineHeight": "28px",
348
+ "letterSpacing": "0%"
349
+ },
350
+ "description": "",
351
+ "extensions": {
352
+ "styleId": "S:0ffe98ad785a13839980113831d5fbaf21724594,"
353
+ }
354
+ }
355
+ ```
356
+
357
+ ### Colors
358
+
359
+ The plugin supports solid colors and gradients (linear, radial, angular, diamond). Color styles are converted to DTCG format with support for variable aliases.
360
+
361
+ ```json
362
+ // Solid color
363
+ "primary": {
364
+ "type": "color",
365
+ "value": "#ff0000"
366
+ }
367
+
368
+ // Solid color with variable alias
369
+ "secondary": {
370
+ "type": "color",
371
+ "value": "{colors.base.primary}"
372
+ }
373
+
374
+ // Gradient
375
+ "skeleton-ramp": {
376
+ "type": "gradient",
377
+ "value": [
378
+ {
379
+ "color": "{clr.scale.ntrl.80}",
380
+ "position": 0
381
+ },
382
+ {
383
+ "color": "{clr.scale.ntrl.95}",
384
+ "position": 0.5
385
+ },
386
+ {
387
+ "color": "#eae9e8",
388
+ "position": 1
389
+ }
390
+ ]
391
+ }
392
+ ```
393
+
394
+ ### Grids
395
+
396
+ In Figma you can add as many grids in the style as you want. But the plugin will take only first two grids and treat the first one as `column` grid and the second one as `row` grid.
397
+
398
+ ```json
399
+ // Column grid
400
+ "1024": {
401
+ "type": "grid",
402
+ "value": {
403
+ "columnCount": 12,
404
+ "columnGap": "20px",
405
+ "columnMargin": "40px"
406
+ }
407
+ }
408
+
409
+ // Row grid
410
+ "1024": {
411
+ "type": "grid",
412
+ "value": {
413
+ "rowCount": 12,
414
+ "rowGap": "20px",
415
+ "rowMargin": "40px"
416
+ }
417
+ }
418
+
419
+ // Both grids
420
+ "1024": {
421
+ "type": "grid",
422
+ "value": {
423
+ "columnCount": 12,
424
+ "columnGap": "20px",
425
+ "columnMargin": "40px",
426
+ "rowCount": 12,
427
+ "rowGap": "20px",
428
+ "rowMargin": "40px"
429
+ }
430
+ }
431
+ ```
432
+
433
+ ### Shadows
434
+
435
+ The plugin supports `drop-shadow` and `inner-shadow` effects. If the effect is `inner-shadow`, the plugin will set the `inset` property to `true`.
436
+
437
+ ```json
438
+ "xl": {
439
+ "type": "shadow",
440
+ "value": {
441
+ "inset": false,
442
+ "color": "#0000000a",
443
+ "offsetX": "0px",
444
+ "offsetY": "10px",
445
+ "blur": "10px",
446
+ "spread": "-5px"
447
+ }
448
+ }
449
+ ```
450
+
451
+ ### Blur
452
+
453
+ The plugin supports `background` and `layer` blur effects. In order to distinguish between them, the plugin adds the `role` property to the generated JSON.
454
+
455
+ ```json
456
+ // Background blur
457
+ "sm": {
458
+ "type": "blur",
459
+ "value": {
460
+ "role": "background",
461
+ "blur": "4px"
462
+ }
463
+ }
464
+
465
+ // Layer blur
466
+ "md": {
467
+ "type": "blur",
468
+ "value": {
469
+ "role": "layer",
470
+ "blur": "12px"
471
+ }
472
+ }
473
+ ```
474
+
475
+ ### Multiple `Shadow` and `Blur` styles support
476
+
477
+ If the style has multiple `Shadow` or `Blur` styles, the plugin will add them into the array.
478
+
479
+ ```json
480
+ "new-sh": {
481
+ "$type": "shadow",
482
+ "$value": [
483
+ {
484
+ "inset": false,
485
+ "color": "#e4505040",
486
+ "offsetX": "0px",
487
+ "offsetY": "4px",
488
+ "blur": "54px",
489
+ "spread": "0px"
490
+ },
491
+ {
492
+ "inset": false,
493
+ "color": "#5b75ff40",
494
+ "offsetX": "0px",
495
+ "offsetY": "4px",
496
+ "blur": "24px",
497
+ "spread": "0px"
498
+ },
499
+ {
500
+ "inset": false,
501
+ "color": "#00000040",
502
+ "offsetX": "0px",
503
+ "offsetY": "4px",
504
+ "blur": "4px",
505
+ "spread": "0px"
506
+ }
507
+ ]
508
+ }
509
+ ```
510
+
511
+ ---
512
+
513
+ ## Tokens structure
514
+
515
+ Plugin first takes the `collection` name, then the `group` and then the `variable` name (fig.1).
516
+ Mode variables will be wrapped under the `$extensions` objects
517
+
518
+ ![fig.1](readme-assets/fig1.webp)
519
+
520
+ For example, if you have a collection named `clr-theme`, mode named `light` and variable named `dark`, the plugin will generate the following JSON:
521
+
522
+ ```json
523
+ "clr-theme": {
524
+ "container-outline/mid": {
525
+ "type": "color",
526
+ "value": "{clr-core.ntrl.40}",
527
+ "description": "",
528
+ "$extensions": {
529
+ "mode": {
530
+ "light": "{clr-core.ntrl.40}",
531
+ "dark": "{clr-core.ntrl.55}"
532
+ }
533
+ }
534
+ }
535
+ }
536
+ ,
537
+ ```
538
+
539
+ ![fig.2](readme-assets/fig2.webp)
540
+
541
+ Figma automatically merges groups and their names into a single name, e.g. `Base/Primary/10` (fig.2). In this case, the plugin will generate the following JSON:
542
+
543
+ ```json
544
+ {
545
+ "base": {
546
+ "primary": {
547
+ "10": {
548
+ "type": "color",
549
+ "value": "#000000"
550
+ }
551
+ }
552
+ }
553
+ }
554
+ ```
555
+
556
+ ## Aliases handling
557
+
558
+ All aliases are converted into the alias string format from the [Design Tokens specification](https://design-tokens.github.io/community-group/format/#aliases-references).
559
+
560
+ ```json
561
+ {
562
+ "button": {
563
+ "background": {
564
+ "type": "color",
565
+ "value": "{colors.primary.10}"
566
+ }
567
+ }
568
+ }
569
+ ```
570
+
571
+ ### Include `.value` string for aliases
572
+
573
+ You can switch on the `Include .value string for aliases` option in [the plugin settings](#include-value-string-for-aliases).
574
+
575
+ ---
576
+
577
+ ### Handle variables from another file
578
+
579
+ Imagine you have a library from another file with "base" variables. And you use this variables in your current file.
580
+
581
+ The plugin will generate the alias name anyway, but it will be a path to the variable as if it was in the current file.
582
+
583
+ ```json
584
+ {
585
+ "button": {
586
+ "background": {
587
+ "type": "color",
588
+ "value": "{colors.primary.10}"
589
+ }
590
+ }
591
+ }
592
+ ```
593
+
594
+ The plugin wouldn't include the variable into the generated JSON in order to avoid duplicates or conflicts with JSON files you can generate from another Figma files.
595
+
596
+ So you will need to merge the file with the base variables from one file with another where you use them. Otherwise tools like Style Dictionary wouldn't be able to resolve the aliases.
597
+
598
+ ---
599
+
600
+ ### Handle modes
601
+
602
+ If there is only one mode — the plugin wouldn't include it in a generated JSON.
603
+ If there are multiple modes, the plugin will place them under the `$extensions` objects.
604
+
605
+ It follows the same pattern as used by [Cobalt](https://cobalt-ui.pages.dev/guides/modes#with-modes)
606
+
607
+ ---
608
+
609
+ ## Variables types conversion
610
+
611
+ Unlike design tokens, Figma variables now [support only 4 types](https://www.figma.com/plugin-docs/api/VariableResolvedDataType) — `COLOR`, `BOOLEAN`, `FLOAT` and `STRING`. So, the plugin converts them into the corresponding types from the [Design Tokens specification](https://design-tokens.github.io/community-group/format/#types).
612
+
613
+ | Figma type | Design Tokens type |
614
+ | ---------- | ----------------------------------------------------------------------------------- |
615
+ | COLOR | [color](https://design-tokens.github.io/community-group/format/#color) |
616
+ | BOOLEAN | _boolean_ \* |
617
+ | FLOAT | [dimension](https://design-tokens.github.io/community-group/format/#dimension) \*\* |
618
+ | STRING | _string_ \* |
619
+
620
+ \* native JSON types. The specification doesn't restrict the type of the value, so it could be any JSON type. Also see [this issue](https://github.com/design-tokens/community-group/issues/120#issuecomment-1279527414).
621
+
622
+ \*\* currently figma supports only the `FLOAT` type for dimensions, that could be used only for `px` values. So, the plugin converts `FLOAT` values into `dimension` type with `px` unit.
623
+
624
+ ---
625
+
626
+ ## Design tokens types
627
+
628
+ In order to validate types, the plugin uses the [Design Tokens types](https://github.com/PavelLaptev/tokens-bruecke/blob/main/token-types.d.ts).
629
+
630
+ ---
631
+
632
+ ## Scopes lemitations
633
+
634
+ In order to convert `FONT-WEIGHT` and `OPACITY` types into valid values you should specify thme as scopes in the Figma variables. The plugin will read the first scope and convert it into the valid value. If there are multiple scopes, the plugin will take the first one.
635
+
636
+ - `FONT_WEIGHT` scope will be converted into `string` type.
637
+ - `OPACITY` scope will be converted into `number` type.
638
+
639
+ ---
640
+
641
+ ## Style Dictionary support
642
+
643
+ There is a set of utils for [Style Dictionary](https://github.com/tokens-bruecke/sd-utils).
644
+
645
+ ---
646
+
647
+ ## Contribution 🚧
648
+
649
+ Comming soon.
650
+
651
+ ---
652
+
653
+ ## Feedback
654
+
655
+ If you have any questions or suggestions, feel free to [create an issue](https://github.com/tokens-bruecke/figma-plugin/issues)