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/prefixSelector.js | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 node_modules/tailwindcss/src/util/prefixSelector.js (limited to 'node_modules/tailwindcss/src/util/prefixSelector.js') diff --git a/node_modules/tailwindcss/src/util/prefixSelector.js b/node_modules/tailwindcss/src/util/prefixSelector.js new file mode 100644 index 0000000..93cbeb9 --- /dev/null +++ b/node_modules/tailwindcss/src/util/prefixSelector.js @@ -0,0 +1,33 @@ +import parser from 'postcss-selector-parser' + +/** + * @template {string | import('postcss-selector-parser').Root} T + * + * Prefix all classes in the selector with the given prefix + * + * It can take either a string or a selector AST and will return the same type + * + * @param {string} prefix + * @param {T} selector + * @param {boolean} prependNegative + * @returns {T} + */ +export default function (prefix, selector, prependNegative = false) { + if (prefix === '') { + return selector + } + + /** @type {import('postcss-selector-parser').Root} */ + let ast = typeof selector === 'string' ? parser().astSync(selector) : selector + + ast.walkClasses((classSelector) => { + let baseClass = classSelector.value + let shouldPlaceNegativeBeforePrefix = prependNegative && baseClass.startsWith('-') + + classSelector.value = shouldPlaceNegativeBeforePrefix + ? `-${prefix}${baseClass.slice(1)}` + : `${prefix}${baseClass}` + }) + + return typeof selector === 'string' ? ast.toString() : ast +} -- cgit v1.2.3