1- import get from 'lodash/get'
2-
31import { PluginNotFoundException } from './exceptions/plugin-not-found-exception'
42import { functionalPlugins , namedPlugins } from './plugins'
5- import { getTailwindTheme } from './theme'
3+
64import { buildModifier } from './utils/build-modifier'
75import { calculateHexFromString } from './utils/calculate-hex-from-string'
86import { findTailwindColorFromHex } from './utils/find-tailwind-color-from-hex'
@@ -11,8 +9,11 @@ import { StringBuilder } from './utils/string-builder'
119
1210export const EMPTY_CLASSNAME = ''
1311
14- export const classname = ( ast , config ) => {
15- const theme = getTailwindTheme ( config )
12+ export const classname = ( ast ) => {
13+ if ( [ null , undefined , '' ] . includes ( ast . value ) ) {
14+ return EMPTY_CLASSNAME
15+ }
16+
1617 const stringBuilder = new StringBuilder ( )
1718 let negative = ast . negative || false
1819 stringBuilder . appendVariants ( ...ast . variants || [ ] )
@@ -40,20 +41,12 @@ export const classname = (ast, config) => {
4041 }
4142
4243 stringBuilder . addRoot ( root )
43- if ( isColor ( ast . value , theme ) ) {
44+ if ( isColor ( ast . value ) ) {
4445 const matchedPlugin = possiblePlugins . find ( plugin => plugin . type === 'color' )
4546 if ( ! matchedPlugin ) {
4647 throw new PluginNotFoundException ( ast . property )
4748 }
4849
49- const tailwindThemeColor = get ( theme [ matchedPlugin . scaleKey || 'colors' ] , ast . value . split ( '-' ) . join ( '.' ) )
50- if ( tailwindThemeColor && typeof tailwindThemeColor !== 'object' ) {
51- return stringBuilder
52- . appendModifier ( buildModifier ( ast . modifier , theme . opacity ) )
53- . addValue ( ast . value )
54- . toString ( )
55- }
56-
5750 const isRgba = ast . value . includes ( 'rgba' )
5851 if ( isRgba ) {
5952 return stringBuilder
@@ -67,9 +60,9 @@ export const classname = (ast, config) => {
6760 }
6861
6962 return stringBuilder
70- . appendModifier ( buildModifier ( color . alpha || ast . modifier , theme . opacity ) )
63+ . appendModifier ( buildModifier ( color . alpha || ast . modifier ) )
7164 . addValue (
72- findTailwindColorFromHex ( color . hex , theme [ matchedPlugin . scaleKey || 'colors' ] ) || StringBuilder . makeArbitrary ( color . hex ) ,
65+ findTailwindColorFromHex ( color . hex ) || StringBuilder . makeArbitrary ( color . hex ) ,
7366 )
7467 . toString ( )
7568 }
@@ -96,7 +89,7 @@ const findTailwindValueByUnit = (unit, matchedPlugin = {}) => {
9689 return undefined
9790 }
9891
99- if ( matchedPlugin . type === 'image' ) {
92+ if ( matchedPlugin . type === 'image' && ! unit . includes ( 'url' ) ) {
10093 unit = `url(http://github.com/%3Cspan%20class=pl-s1%3E%3Cspan%20class=pl-kos%3E$%7B%3C/span%3E%3Cspan%20class=pl-s1%3Eunit%3C/span%3E%3Cspan%20class=pl-kos%3E%7D%3C/span%3E%3C/span%3E)`
10194 }
10295
0 commit comments