-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathsketch-palettes.ts
40 lines (37 loc) · 1.16 KB
/
sketch-palettes.ts
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
import Color from 'color';
import type { Template } from './index.js';
import { colorSetToVariants } from '../color-set/index.js';
import { source } from 'common-tags';
const template: Template = {
name: 'Sketch Palettes',
render: async function* (colorSet) {
const variants = colorSetToVariants(colorSet);
for (const { title, colors } of variants) {
yield {
path: `sketch-palettes-${title.kebab}.sketchpalette`,
content: JSON.stringify({
compatibleVersion: '2.0',
pluginVersion: '2.13',
colors: Object.values(colors).map((color) => {
const [red, green, blue] = Color(color).rgb().array();
return {
red,
green,
blue,
alpha: 1,
};
}),
gradients: [],
images: [],
}),
};
}
},
renderInstructions: (paths) => source`
Load the generated theme ${
paths.length > 1 ? 'files' : 'file'
} into Sketch through the [sketch-palettes](https://github.com/andrewfiorillo/sketch-palettes) plugin.
${paths.map((p) => `* \`${p}\``).join('\n')}
`,
};
export default template;