How to use the @csstools/convert-colors.lab2rgb function in @csstools/convert-colors

To help you get started, we’ve selected a few @csstools/convert-colors examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github postcss / postcss-color-gray / index.js View on Github external
ast.walk(node => {
				const [lightness, alpha] = getFunctionGrayArgs(node);

				if (lightness !== undefined) {
					// rename the gray() function to rgb()
					node.value = 'rgb';

					// convert the lab gray lightness into rgb
					const [r, g, b] = lab2rgb(lightness, 0, 0).map(
						channel => Math.max(Math.min(Math.round(channel * 2.55), 255), 0)
					);

					// preserve the slash nodes within rgb()
					const openingSlash = node.first;
					const closingSlash = node.last;

					node.removeAll()
					// replace the contents of rgb with `(r,g,b`
					.append(openingSlash)
					.append(parser.number({ value: r }))
					.append(parser.comma({ value: ',' }))
					.append(parser.number({ value: g }))
					.append(parser.comma({ value: ',' }))
					.append(parser.number({ value: b }))