-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.ts
66 lines (55 loc) · 2.13 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
// This plugin will open a modal to prompt the user to enter a number, and
// it will then create that many rectangles on the screen.
// This file holds the main code for the plugins. It has access to the *document*.
// You can access browser APIs in the <script> tag inside "ui.html" which has a
// full browser environment (see documentation).
// This shows the HTML page in "ui.html".
figma.showUI(__html__, { width: 400, height: 250 });
// Calls to "parent.postMessage" from within the HTML page will trigger this
// callback. The callback will be passed the "pluginMessage" property of the
// posted message.
figma.ui.onmessage = msg => {
if(msg.type === 'delete-all'){
figma.getLocalEffectStyles().forEach(style => style.remove())
figma.getLocalPaintStyles().forEach(style => style.remove())
figma.getLocalTextStyles().forEach(style => style.remove())
}
if(msg.type === 'import-style'){
//Text styles
let textStyles = msg.style.texts
textStyles.forEach(async data => {
await figma.loadFontAsync(data.fontName)
let text = figma.createTextStyle()
text.name = data.name
text.fontName = data.fontName
text.fontSize = data.fontSize
text.lineHeight = {unit: "PIXELS", value: data.lineHeight}
})
//Paints (Colour fills)
let paints = msg.style.paints
paints.forEach(data => {
let paint = figma.createPaintStyle()
paint.name = data.name
switch(data.type){
case "SOLID":
paint.paints = [{type: data.type, color: data.color, opacity: data.opacity}]
break;
}
})
let shadows = msg.style.shadows
shadows.forEach(data =>{
let shadow = figma.createEffectStyle()
shadow.effects = data.effects
shadow.name = data.name
})
let blurs = msg.style.blurs
blurs.forEach(data =>{
let blur = figma.createEffectStyle()
blur.effects = data.effects
blur.name = data.name
})
}
}
// Make sure to close the plugin when you're done. Otherwise the plugin will
// keep running, which shows the cancel button at the bottom of the screen.
// figma.closePlugin();