-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.js
55 lines (46 loc) · 1.61 KB
/
code.js
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
figma.showUI(__html__, { width: 320, height: 480 });
let selectionArr = figma.currentPage.selection;
figma.ui.onmessage = msg => {
if (msg.inputData) {
if (selectionArr[0]) {
if (figma.currentPage.selection[0].type != 'TEXT') {
figma.notify('📌 Select text layers', { timeout: 1 })
}
} else {
figma.notify('📌 Select text layers', { timeout: 1 })
}
figma.on('selectionchange', () => {
if (figma.currentPage.selection[0]) {
if (figma.currentPage.selection[0].type === 'TEXT') {
selectionArr = []
if (figma.currentPage.selection.length > 0) {
figma.currentPage.selection.forEach(item => {
selectionArr.push(item)
})
} else {
selectionArr = figma.currentPage.selection[0]
}
}
else {
figma.notify('📌 Select text layers', { timeout: 1 })
}
}
})
async function nodeFont(nodeItem) {
await figma.loadFontAsync(nodeItem.fontName)
nodeItem.characters = msg.inputData;
selectionArr = []
}
selectionArr.forEach(node => {
if (node.lenth > 0) {
node.forEach(item => {
nodeFont(item)
})
} else {
nodeFont(node)
}
});
} else {
figma.notify('🤷 No data', { timeout: 1 })
}
};