-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.ts
More file actions
57 lines (40 loc) · 1.44 KB
/
code.ts
File metadata and controls
57 lines (40 loc) · 1.44 KB
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
const selection = getFilteredSelection()
let mylength = selection.length;
if (selection.length === 0) {
figma.notify("⚠️ Please select at least one layer beforehand.", {
error: true,
})
figma.closePlugin();
}
if (selection.length > 0) {
for(let i = 0; i < mylength; i++) {
let width = selection[i].width;
let height = selection[i].height;
let nodes = [];
// Flip each selected layers W & H
// @ts-expect-error
if (height < 0.01 && width >= 0.01) { nodes.push(selection[i].resize(0.01, width))} else
// @ts-expect-error
if (height >= 0.01 && width < 0.01) { nodes.push(selection[i].resize(height, 0.01))}
// @ts-expect-error
else { nodes.push(selection[i].resize(height, width))}
}
if (selection.length === 1) {
figma.closePlugin('1 layer resized');
} else {
figma.closePlugin(`${selection.length} layers resized`)
}
}
function getFilteredSelection() {
return figma.currentPage.selection.filter(
(node) =>
(node.type === "FRAME" ||
node.type === "RECTANGLE" ||
node.type === "ELLIPSE" ||
node.type === "POLYGON" ||
node.type === "TEXT" ||
node.type === "SHAPE_WITH_TEXT" ||
node.type === "COMPONENT" ||
node.type === "GROUP")
)
}