import _ from 'lodash' ; const defaultOptions = { prefix : '' , tailwindProperties : { } , } ; type TailwindCssRule = { properties : string [ ] ; pseudoElements : string [ ] ; topLevelMediaRules : string [ ] ; } ; export type TailWindCssProperties = { [ key ] : TailwindCssRule ; } ; export type OptionsArg = { prefix ? : string ; tailwindProperties ? : TailWindCssProperties ; } ; const isEqualsSorted = ( x , y ) => { return _ . isEqual ( _ . sortBy ( x ) , _ . sortBy ( y ) ) ; } ; const filterCssVariables = ( classNames ) => { return classNames ?. filter ( ( c ) => ! c . startsWith ( '--' ) ) ; } ; const doMediaRulesClash = ( mediaRule1 , mediaRule2 ) => { return isEqualsSorted ( mediaRule1 , mediaRule2 ) ; } ; const doPseudoElementsClash = ( pseudoElements1 , pseudoElements2 ) => { return isEqualsSorted ( pseudoElements1 , pseudoElements2 ) ; } ; export const overrideTailwindClasses = ( classNamesString , optionsArg = defaultOptions ) => { const options = { ... defaultOptions , ... optionsArg } ; const classNames = classNamesString . split ( /\s+/ ) ; return classNames . reduce ( ( resultSoFar , className ) => { const classNameWithoutPrefix = className . startsWith ( options . prefix ) ? className . substring ( options . prefix . length ) : className ; const tailwindCssRule = options . tailwindProperties [ classNameWithoutPrefix ] || { properties : [ ] , pseudoElements : [ ] } ; const nonClashingClasses = resultSoFar . filter ( ( r ) => { return ( ! doMediaRulesClash ( r . tailwindCssRule . topLevelMediaRules , tailwindCssRule . topLevelMediaRules ) || ! doPseudoElementsClash ( r . tailwindCssRule . pseudoElements , tailwindCssRule . pseudoElements ) || ! filterCssVariables ( r . tailwindCssRule . properties ) . some ( ( p ) => filterCssVariables ( tailwindCssRule . properties ) . includes ( p ) ) ) ; } ) ; return [ ... nonClashingClasses , { class : className , tailwindCssRule : tailwindCssRule } ] ; } , [ ] ) . map ( ( r ) => r . class ) . join ( ' ' ) ; } ;