Last active
November 6, 2022 12:52
-
-
Save PavelLaptev/b27b0b631d22ccea526686f6639bbb14 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 getPalette(stylesArtboard) { | |
// empty "palette obj" wheree we will store all colors | |
const palette = {}; | |
// get "palette" artboard | |
const paletteAtrboard = stylesArtboard.filter(item => { | |
return item.name === "palette"; | |
})[0].children; | |
// get colors from each children | |
paletteAtrboard.map(item => { | |
function rbaObj(obj) { | |
return item.fills[0].color[obj] * 255; | |
} | |
colorObj = { | |
[item.name]: { | |
value: `rgba(${rbaObj("r")}, ${rbaObj("g")}, ${rbaObj( | |
"b" | |
)}, ${item.fills[0].color.a})`, | |
type: "color" | |
} | |
}; | |
Object.assign(palette, colorObj); | |
}); | |
return palette; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment