Created
October 19, 2021 21:39
-
-
Save oleggrishechkin/36b7555b1cf790c32bafe0bebdb7d689 to your computer and use it in GitHub Desktop.
This file contains 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
// it's color parser snippet for https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/color/ | |
// temp0 - tbody with colors | |
// returns tuple with [light css variables string, dark css variables string] - values can be copied to your css | |
Array.from(temp0) | |
.filter((node) => node.nodeName === 'TR') | |
.map((node) => { | |
const [lightNode, darkNode, nameNode] = Array.from(node.childNodes) | |
.filter((node) => node.nodeName === 'TD') | |
.slice(0, 3); | |
return [lightNode, darkNode] | |
.map( | |
(node) => | |
`rgb(${node.textContent | |
.trim() | |
.split('\n') | |
.map((text) => text.trim().slice(2)) | |
.join(', ')})` | |
) | |
.concat(nameNode.textContent.trim().replace(' (', '-').replace(')', '').toLowerCase()); | |
}) | |
.reduce( | |
(res, [lightColor, darkColor, name]) => [ | |
`${res[0]}--${name}: ${lightColor}; `, | |
`${res[1]}--${name}: ${darkColor}; ` | |
], | |
['', ''] | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment