From b1e2c8fd5cb5dfa46bc440a12eafaf56cd844b1c Mon Sep 17 00:00:00 2001 From: Philipp Tanlak Date: Mon, 24 Nov 2025 20:54:57 +0100 Subject: Docs --- .../tailwindcss/src/util/withAlphaVariable.js | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 node_modules/tailwindcss/src/util/withAlphaVariable.js (limited to 'node_modules/tailwindcss/src/util/withAlphaVariable.js') diff --git a/node_modules/tailwindcss/src/util/withAlphaVariable.js b/node_modules/tailwindcss/src/util/withAlphaVariable.js new file mode 100644 index 0000000..15aedb7 --- /dev/null +++ b/node_modules/tailwindcss/src/util/withAlphaVariable.js @@ -0,0 +1,49 @@ +import { parseColor, formatColor } from './color' + +export function withAlphaValue(color, alphaValue, defaultValue) { + if (typeof color === 'function') { + return color({ opacityValue: alphaValue }) + } + + let parsed = parseColor(color, { loose: true }) + + if (parsed === null) { + return defaultValue + } + + return formatColor({ ...parsed, alpha: alphaValue }) +} + +export default function withAlphaVariable({ color, property, variable }) { + let properties = [].concat(property) + if (typeof color === 'function') { + return { + [variable]: '1', + ...Object.fromEntries( + properties.map((p) => { + return [p, color({ opacityVariable: variable, opacityValue: `var(${variable})` })] + }) + ), + } + } + + const parsed = parseColor(color) + + if (parsed === null) { + return Object.fromEntries(properties.map((p) => [p, color])) + } + + if (parsed.alpha !== undefined) { + // Has an alpha value, return color as-is + return Object.fromEntries(properties.map((p) => [p, color])) + } + + return { + [variable]: '1', + ...Object.fromEntries( + properties.map((p) => { + return [p, formatColor({ ...parsed, alpha: `var(${variable})` })] + }) + ), + } +} -- cgit v1.2.3