-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcode.ts
82 lines (76 loc) · 2.42 KB
/
code.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// This plugin will generate a sample codegen plugin
// that appears in the Element tab of the Inspect panel.
// This file holds the main code for plugins. Code in this file has access to
// the *figma document* via the figma global object.
// You can access browser APIs in the <script> tag inside "ui.html" which has a
// full browser environment (See https://www.figma.com/plugin-docs/how-plugins-run).
const properties = {
sizing: "sizing",
height: "height",
width: "width",
spacing: "spacing",
verticalPadding: "verticalPadding",
horizontalPadding: "horizontalPadding",
paddingTop: "paddingTop",
paddingRight: "paddingRight",
paddingBottom: "paddingBottom",
paddingLeft: "paddingLeft",
itemSpacing: "itemSpacing",
fill: "fill",
backgroundBlur: "backgroundBlur",
border: "border",
borderTop: "borderTop",
borderRight: "borderRight",
borderBottom: "borderBottom",
borderLeft: "borderLeft",
borderColor: "borderColor",
borderRadius: "borderRadius",
borderRadiusTopLeft: "borderRadiusTopLeft",
borderRadiusTopRight: "borderRadiusTopRight",
borderRadiusBottomRight: "borderRadiusBottomRight",
borderRadiusBottomLeft: "borderRadiusBottomLeft",
borderWidth: "borderWidth",
borderWidthTop: "borderWidthTop",
borderWidthRight: "borderWidthRight",
borderWidthBottom: "borderWidthBottom",
borderWidthLeft: "borderWidthLeft",
boxShadow: "boxShadow",
opacity: "opacity",
fontFamilies: "fontFamilies",
fontWeights: "fontWeights",
fontSizes: "fontSizes",
lineHeights: "lineHeights",
typography: "typography",
composition: "composition",
letterSpacing: "letterSpacing",
paragraphSpacing: "paragraphSpacing",
textCase: "textCase",
dimension: "dimension",
textDecoration: "textDecoration",
asset: "asset",
visibility: "visibility",
text: "text",
number: "number",
tokenValue: "tokenValue",
value: "value",
tokenName: "tokenName",
description: "description",
};
// This provides the callback to generate the code.
figma.codegen.on("generate", (event: any): CodegenResult[] => {
const tokenKeys = Object.keys(properties);
const code = tokenKeys
.map((key) => {
const value = event.node.getSharedPluginData("tokens", key);
return value && `${key}: ${value};`;
})
.filter((x) => x)
.join("\n");
return [
{
language: "CSS",
code: code === "" ? "/* No Tokens found */" : code,
title: "Applied Tokens (Tokens Studio)",
},
];
});