-
Notifications
You must be signed in to change notification settings - Fork 317
/
Copy pathimport.html
executable file
·132 lines (130 loc) · 2.88 KB
/
import.html
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<style>
:root {
--spacing: 0.8rem;
}
* {
box-sizing: border-box;
}
body {
background-color: var(--figma-color-bg);
color: var(--figma-color-text);
margin: 0;
padding: var(--spacing);
}
html,
body {
height: 100%;
}
form {
display: flex;
flex-direction: column;
gap: var(--spacing);
height: 100%;
}
button {
appearance: none;
border-radius: 4px;
padding: var(--spacing);
}
input,
textarea {
font-family: Andale Mono, monospace;
font-size: 0.9rem;
padding: var(--spacing);
}
textarea {
flex: 1;
white-space: pre;
}
form > * {
display: block;
width: 100%;
}
button {
background-color: var(--figma-color-bg-brand);
border: none;
color: var(--figma-color-text-onbrand);
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue",
sans-serif;
font-weight: bold;
}
input,
textarea {
background-color: var(--figma-color-bg-secondary);
color: var(--figma-color-text-secondary);
border: 2px solid var(--figma-color-border);
}
input:focus,
textarea:focus {
border-color: var(--figma-color-border-selected);
outline: none;
}
</style>
<form>
<input
placeholder="Collection Name"
required
type="text"
value="Wild Examples"
/>
<textarea required placeholder="Tokens JSON">
{
"color": {
"grouptyped": {
"$type": "color",
"brown": { "$value": "#a2845e" },
"danger-deep": { "$value": "{color.valuetyped.danger}" }
},
"valuetyped": {
"red": {
"$value": "{color.deep.deep.deep.deep.deep}"
},
"danger": { "$value": "{color.valuetyped.red}" }
},
"deep": {"deep": {"deep": {"deep": {"deep": {"$type": "color", "$value": "#FF0000" }}}}}
},
"spacing": {
"$type": "number",
"some numbers": {
"spacer0": {"$value": 0},
"spacerXs": {"$value": 4},
"spacerS": {"$value": 8},
"spacerM": {"$value": 16},
"spacerX": {"$value": 24},
"spacerXl": {"$value": 32},
"spacerXxl": {"$value": 40},
"spacex": {
"funniness": {"$value": 0},
"cleverness": {"$value": 1}
}
}
}
}
</textarea
>
<button type="submit">Import Variables</button>
</form>
<script>
document.querySelector("form").addEventListener("submit", (e) => {
const fileName = document.querySelector("input").value.trim();
const body = document.querySelector("textarea").value.trim();
e.preventDefault();
if (isValidJSON(body) && fileName) {
parent.postMessage(
{ pluginMessage: { fileName, body, type: "IMPORT" } },
"*"
);
} else {
alert("Invalid filename or JSON");
}
});
function isValidJSON(body) {
try {
JSON.parse(body);
return true;
} catch (e) {
return false;
}
}
</script>