-
-
Notifications
You must be signed in to change notification settings - Fork 162
/
Copy pathmain.js
47 lines (36 loc) · 1.57 KB
/
main.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
// **-------------** Fit To Artboard **-------------**
// A simple and time saving XD plugin made by Valentin de Bruyn
// @valentindb | http://etaminstudio.com
var commands = require("commands", "scenegraph");
var nodeTopLeft;
var nodeBounds;
var currentNode;
var artboardWidth;
var artboardHeight;
function FitWidthToArtboard(selection) {
currentNode = selection.items[0];
artboardWidth = selection.focusedArtboard.width;
console.log(currentNode.parent.width);
console.log(currentNode.isContainer);
console.log(selection.focusedArtboard);
currentNode.width = artboardWidth;
nodeBounds = currentNode.localBounds; // node's bounds in its own local coordinates
nodeTopLeft = {x: nodeBounds.x, y: nodeBounds.y}; // node's top left corner in its own local coordinates
currentNode.placeInParentCoordinates(nodeTopLeft, {x: 0,y: currentNode.topLeftInParent.y});
}
function FitHeightToArtboard(selection) {
currentNode = selection.items[0];
artboardHeight = selection.focusedArtboard.height;
console.log(currentNode.parent.height);
console.log(currentNode.isContainer);
currentNode.height = artboardHeight;
nodeBounds = currentNode.localBounds; // node's bounds in its own local coordinates
nodeTopLeft = {x: nodeBounds.x, y: nodeBounds.y}; // node's top left corner in its own local coordinates
currentNode.placeInParentCoordinates(nodeTopLeft, {y: 0,x: currentNode.topLeftInParent.x});
}
module.exports = {
commands: {
fitWidthToArtboard: FitWidthToArtboard,
fitHeightToArtboard: FitHeightToArtboard
}
};