Created
September 17, 2018 12:09
-
-
Save benjohnde/4fe4d2c8b710ec8b5f631e6574384245 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function processShape(part, groupX, groupY, artboardWidth, artboardHeight) { | |
// FIX: due to react-sketchapp rendering everything into a group | |
// we need to set part to the children "ShapeGroup" but remember | |
// the parent's (x, y) | |
if (part.children().length !== 2) { | |
groupX += part.frame().x() | |
groupY += part.frame().y() | |
const name = part.name() | |
part = part.children()[1] | |
part.name = name | |
} | |
var partFrame = part.frame() | |
var x = partFrame.x() + groupX | |
var y = partFrame.y() + groupY | |
var width = partFrame.width() | |
var height = partFrame.height() | |
var points = part.layers()[0].points() | |
var x = x / artboardWidth | |
var y = y / artboardHeight | |
var width = width / artboardWidth | |
var height = height / artboardHeight | |
var shapeName = part.name() | |
const hasBorder = part.style().borders().length > 0 | |
var border = null | |
if (hasBorder) { | |
const borderStyle = part.style().borders()[0] | |
const thickness = borderStyle.thickness() | |
const color = { | |
red: borderStyle.color().red(), | |
green: borderStyle.color().green(), | |
blue: borderStyle.color().blue(), | |
alpha: borderStyle.color().alpha() | |
} | |
border = { | |
thickness, | |
color | |
} | |
} | |
const isRect = points.length == 4 | |
if (isRect) { | |
var cornerRadius = points[0].cornerRadius() / artboardWidth | |
return { | |
shapeName, | |
x, | |
y, | |
width, | |
height, | |
cornerRadius, | |
border: border | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment