-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode copy.js
100 lines (100 loc) · 3.92 KB
/
code copy.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
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
const fontStyles = [
"Thin",
"ExtraLight",
"Light",
"Regular",
"Medium",
"SemiBold",
"Bold",
"ExtraBold",
"Black",
"Thin Italic",
"ExtraLight Italic",
"Light Italic",
"Regular Italic",
"Medium Italic",
"SemiBold Italic",
"Bold Italic",
"ExtraBold Italic",
"Black Italic",
];
if (figma.editorType === 'figma') {
if (figma.currentPage.selection[0].type === "TEXT") {
let fonts = figma.currentPage.selection;
console.log(fonts[0].fontName);
for (let i = 0; i < fonts.length; i++) {
const element = fonts[i];
// console.log(element.fontName)
function createFontDisplay(figmaElement) {
let text = figma.createText();
text.x = figmaElement.x;
text.y = figmaElement.y + figmaElement.height / 2;
text.fontName = figmaElement.fontName;
console.log(figmaElement.fontName);
// await figma.loadFontAsync({family: "Manrope", style: "Bold"})
text.characters = "Almost before we knew it, we had left the ground.";
// text.fontSize = element.height
// text.fills = [{ type: "SOLID", color: { r: 0, g: 0, b: 0}}]
}
createFontDisplay(element);
// await figma.loadFontAsync(element.fontName)
// display.fontName["style"] = "Bold"
// for (let i = 0; i < display.FontName.length; i++) {
// const element = display.FontName[i];
// console.log(i)
// }
}
const nodes = [];
nodes.push();
figma.currentPage.selection = nodes;
figma.viewport.scrollAndZoomIntoView(nodes);
figma.closePlugin();
}
// If the plugins isn't run in Figma, run this code
}
else {
// This plugin will open a window to prompt the user to enter a number, and
// it will then create that many shapes and connectors on the screen.
// This shows the HTML page in "ui.html".
figma.showUI(__html__);
// Calls to "parent.postMessage" from within the HTML page will trigger this
// callback. The callback will be passed the "pluginMessage" property of the
// posted message.
figma.ui.onmessage = msg => {
// One way of distinguishing between different types of messages sent from
// your HTML page is to use an object with a "type" property like this.
if (msg.type === 'create-shapes') {
const numberOfShapes = msg.count;
const nodes = [];
for (let i = 0; i < numberOfShapes; i++) {
const shape = figma.createShapeWithText();
// You can set shapeType to one of: 'SQUARE' | 'ELLIPSE' | 'ROUNDED_RECTANGLE' | 'DIAMOND' | 'TRIANGLE_UP' | 'TRIANGLE_DOWN' | 'PARALLELOGRAM_RIGHT' | 'PARALLELOGRAM_LEFT'
shape.shapeType = 'ROUNDED_RECTANGLE';
shape.x = i * (shape.width + 200);
shape.fills = [{ type: 'SOLID', color: { r: 1, g: 0.5, b: 0 } }];
figma.currentPage.appendChild(shape);
nodes.push(shape);
}
;
for (let i = 0; i < (numberOfShapes - 1); i++) {
const connector = figma.createConnector();
connector.strokeWeight = 8;
connector.connectorStart = {
endpointNodeId: nodes[i].id,
magnet: 'AUTO',
};
connector.connectorEnd = {
endpointNodeId: nodes[i + 1].id,
magnet: 'AUTO',
};
}
;
figma.currentPage.selection = nodes;
figma.viewport.scrollAndZoomIntoView(nodes);
}
// Make sure to close the plugin when you're done. Otherwise the plugin will
// keep running, which shows the cancel button at the bottom of the screen.
figma.closePlugin();
};
}
;