-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.ts
56 lines (37 loc) · 1.43 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
// This file holds the main code for the plugin. It has access to the *document*.
// You can access browser APIs such as the network by creating a UI which contains
// a full browser environment (see documentation).
// Runs this code if the plugin is run in Figma
if (figma.editorType === 'figma') {
figma.showUI(__html__);
for (const node of figma.currentPage.selection.map(async node => {
if (node.type === "TEXT")
await Promise.all(
node.getRangeAllFontNames(0, node.characters.length)
.map(figma.loadFontAsync)
)
}))
for (const node of figma.currentPage.selection) {
if (node.type == "TEXT")
figma.ui.postMessage({ width: node.width, text: node.characters, fontWeight: node.fontWeight, selectedRange: figma.currentPage.selectedTextRange?.node.characters.substring(figma.currentPage.selectedTextRange.start, figma.currentPage.selectedTextRange.end) })
}
figma.ui.onmessage = msg => {
console.log(msg.result)
for (const node of figma.currentPage.selection) {
if (node.type == "TEXT")
node.characters = msg.result
}
// figma.closePlugin();
}
// figma.closePlugin();
} else {
figma.showUI(__html__);
for (const node of figma.currentPage.selection) {
if (node.type == "TEXT")
figma.ui.postMessage({ width: node.width, text: node.characters })
}
figma.ui.onmessage = msg => {
console.log(msg)
figma.closePlugin();
}
};