Skip to content

Instantly share code, notes, and snippets.

@PavelLaptev
Last active November 6, 2022 12:52
Show Gist options
  • Save PavelLaptev/b27b0b631d22ccea526686f6639bbb14 to your computer and use it in GitHub Desktop.
Save PavelLaptev/b27b0b631d22ccea526686f6639bbb14 to your computer and use it in GitHub Desktop.
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