source: frontend/node_modules/tailwindcss/src/util/prefixSelector.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 992 bytes
Line 
1import parser from 'postcss-selector-parser'
2
3/**
4 * @template {string | import('postcss-selector-parser').Root} T
5 *
6 * Prefix all classes in the selector with the given prefix
7 *
8 * It can take either a string or a selector AST and will return the same type
9 *
10 * @param {string} prefix
11 * @param {T} selector
12 * @param {boolean} prependNegative
13 * @returns {T}
14 */
15export default function (prefix, selector, prependNegative = false) {
16 if (prefix === '') {
17 return selector
18 }
19
20 /** @type {import('postcss-selector-parser').Root} */
21 let ast = typeof selector === 'string' ? parser().astSync(selector) : selector
22
23 ast.walkClasses((classSelector) => {
24 let baseClass = classSelector.value
25 let shouldPlaceNegativeBeforePrefix = prependNegative && baseClass.startsWith('-')
26
27 classSelector.value = shouldPlaceNegativeBeforePrefix
28 ? `-${prefix}${baseClass.slice(1)}`
29 : `${prefix}${baseClass}`
30 })
31
32 return typeof selector === 'string' ? ast.toString() : ast
33}
Note: See TracBrowser for help on using the repository browser.