-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.ts
77 lines (73 loc) · 1.73 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
66
67
68
69
70
71
72
73
74
75
76
77
function findMaxSize() {
let maxWidth = 0;
let maxHeight = 0;
for (const node of figma.currentPage.selection) {
if (node.width > maxWidth) {
maxWidth = node.width;
}
if (node.height > maxHeight) {
maxHeight = node.height;
}
}
return [maxWidth, maxHeight];
}
function findMinSize() {
let minWidth = figma.currentPage.selection[0].width;
let minHeight = figma.currentPage.selection[0].height;
for (const node of figma.currentPage.selection) {
if (node.width < minWidth) {
minWidth = node.width;
}
if (node.height < minHeight) {
minHeight = node.height;
}
}
return [minWidth, minHeight];
}
function findStartPoint() {
let top = 0;
let left = 0;
for (const node of figma.currentPage.selection) {
console.log(typeof node.x);
if (node.x < left) {
left = node.x;
}
if (node.y < top || top === 0) {
top = node.y;
}
}
return [left, top];
}
const maxArray = findMaxSize();
const minArray = findMinSize();
for (const node of figma.currentPage.selection) {
let width, height;
switch (figma.command) {
case "align-to-smallest":
[width, height] = minArray;
break;
case "align-to-biggest":
[width, height] = maxArray;
break;
case "align-to-widest":
width = maxArray[0];
height = node.height;
break;
case "align-to-narrowest":
width = minArray[0];
height = node.height;
break;
case "align-to-tallest":
width = node.width;
height = maxArray[1];
break;
case "align-to-shortest":
width = node.width;
height = minArray[1];
break;
}
if (width && height && "resize" in node) {
node.resize(width, height);
}
}
figma.closePlugin("Done");