-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcode.js
More file actions
146 lines (146 loc) · 5.52 KB
/
Copy pathcode.js
File metadata and controls
146 lines (146 loc) · 5.52 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//creating figma UI
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
let data = figma.root;
//creating elements
let cover;
let frame;
let head;
let desc;
let stat;
let tagBg;
// Positioning Functions
let setPosition = (node, spacex, spacey) => { node.x = spacex, node.y = spacey; };
let xCalculator = (container, element) => {
return ((container.width / 2) - (element.width / 2));
};
let yCalculator = (container, height) => {
return (((container.height) - height) / 2);
};
// Color Functions
let setColor = (node, color) => {
function clone(val) {
return JSON.parse(JSON.stringify(val));
}
let txtfills = clone(node.fills);
txtfills[0].color = color;
node.fills = txtfills;
};
//load Elements
let loadFontHead = (msg) => __awaiter(this, void 0, void 0, function* () {
yield figma.loadFontAsync({ family: "Roboto", style: "Bold" });
head.fontName = { family: "Roboto", style: "Bold" };
head.characters = msg.name;
head.fontSize = 74;
head.textAlignHorizontal = "CENTER";
head.resize(900, head.height);
});
let loadFontDesc = (msg) => __awaiter(this, void 0, void 0, function* () {
yield figma.loadFontAsync({ family: "Roboto", style: "Regular" });
desc.fontSize = 36;
desc.resize(800, desc.height);
desc.characters = msg.desc;
});
let loadStat = (msg) => __awaiter(this, void 0, void 0, function* () {
yield figma.loadFontAsync({ family: "Roboto", style: "Regular" });
stat.fontName = { family: "Roboto", style: "Regular" };
stat.characters = msg.status;
stat.fontSize = 24;
stat.textAlignHorizontal = "CENTER";
let tagBgWidth = stat.width + 30;
let tagBgHeight = stat.height + 30;
tagBg.resize(tagBgWidth, tagBgHeight);
tagBg.cornerRadius = 500;
setColor(stat, { r: 1, g: 1, b: 1 });
setColor(tagBg, { r: 0, g: 90 / 255, b: 235 / 255 });
});
// Layout things
let setObjects = (msg) => __awaiter(this, void 0, void 0, function* () {
yield loadFontHead(msg);
yield loadFontDesc(msg);
yield loadStat(msg);
let headX = xCalculator(frame, head);
let descX = xCalculator(frame, desc);
let statX = xCalculator(frame, stat);
let tagBgX = xCalculator(frame, tagBg);
let total = head.height + desc.height + stat.height + 75;
let headY = (yCalculator(frame, total));
let descY = headY + head.height + 20;
let statY = descY + desc.height + 40;
let tagBgY = statY - 15;
setPosition(head, headX, headY);
setPosition(desc, descX, descY);
setPosition(stat, statX, statY);
setPosition(tagBg, tagBgX, tagBgY);
head.textAlignHorizontal = "CENTER";
desc.textAlignHorizontal = "CENTER";
stat.textAlignHorizontal = "CENTER";
stat.name = "status";
tagBg.name = "statbg";
});
// on user action do the following
if (figma.root.getPluginData("flag") != "1") {
figma.showUI(__html__, { width: 300, height: 300 });
console.log(figma.root.getPluginData("flag"));
console.log("hello");
figma.ui.onmessage = (msg) => __awaiter(this, void 0, void 0, function* () {
cover = figma.createPage();
frame = figma.createFrame();
head = figma.createText();
desc = figma.createText();
tagBg = figma.createRectangle();
stat = figma.createText();
cover.name = "Cover";
frame.name = "00";
frame.resize(1240, 640);
figma.root.insertChild(0, cover);
yield setObjects(msg);
frame.appendChild(head);
frame.appendChild(desc);
frame.appendChild(tagBg);
frame.appendChild(stat);
cover.appendChild(frame);
figma.currentPage = cover;
figma.notify("Cover Generated");
figma.root.setPluginData('flag', "1");
figma.root.setPluginData('Name', msg.name);
figma.root.setPluginData('Description', msg.desc);
figma.root.setPluginData('Description', msg.status);
figma.closePlugin();
});
}
else {
console.log("closing plugin");
figma.showUI(__html__, { width: 300, height: 300 });
figma.ui.postMessage(true);
figma.ui.onmessage = (msg) => __awaiter(this, void 0, void 0, function* () {
let Page = figma.root.findOne(n => n.name === "Cover");
figma.currentPage = Page;
let Text = figma.currentPage.findOne(n => n.name === "status");
let txt = Text;
let Bg = figma.currentPage.findOne(n => n.name === "statbg");
let bg = Bg;
let Fm = figma.currentPage.findOne(n => n.name === "00");
let fm = Fm;
yield SetText(txt, msg, bg, fm);
figma.notify("Cover Updated");
figma.closePlugin();
});
}
let SetText = (txt, msg, bg, fm) => __awaiter(this, void 0, void 0, function* () {
yield figma.loadFontAsync({ family: "Roboto", style: "Regular" });
txt.characters = msg.status;
let tagBgWidth = txt.width + 30;
let tagBgHeight = txt.height + 30;
bg.resize(tagBgWidth, tagBgHeight);
let statX = xCalculator(fm, txt);
let tagBgX = xCalculator(fm, bg);
setPosition(txt, statX, txt.y);
setPosition(bg, tagBgX, bg.y);
});