@@ -54,6 +54,60 @@ export const get = {
5454} ;
5555
5656export const camelToKebabCase = ( property : string ) => {
57+ const toKebabCase = ( str : string ) => str . replace ( / ( [ A - Z ] ) / g, '-$1' ) . toLowerCase ( ) ;
58+
59+ if ( property . startsWith ( 'hasClassChild' ) ) {
60+ const afterProp = property . slice ( 'hasClassChild' . length ) ;
61+ const afterNotKebab = afterProp . replace ( / _ / g, '-' ) . toLowerCase ( ) ;
62+ return `:has(> .${ afterNotKebab } )` ;
63+ }
64+
65+ if ( property . startsWith ( 'hasClassPlus' ) ) {
66+ const afterProp = property . slice ( 'hasClassPlus' . length ) ;
67+ const afterNotKebab = afterProp . replace ( / _ / g, '-' ) . toLowerCase ( ) ;
68+ return `:has(+ .${ afterNotKebab } )` ;
69+ }
70+
71+ if ( isHasCCCType ( property ) ) {
72+ const regex = / ^ h a s C l a s s ( .* ?) C h i l d ( .* ?) $ / ;
73+ const matches = property . match ( regex ) ;
74+ if ( matches ) {
75+ const [ , class1 , class2 ] = matches ;
76+ return `:has(.${ class1 . replace ( / _ / g, '-' ) . toLowerCase ( ) } > ${
77+ pascalCaseHtmlTags . includes ( class2 ) ? class2 . toLowerCase ( ) : '.' + class2 . replace ( / _ / g, '-' ) . toLowerCase ( )
78+ } )`;
79+ }
80+ }
81+
82+ if ( isHasCPCType ( property ) ) {
83+ const regex = / ^ h a s C l a s s ( .* ?) P l u s ( .* ?) $ / ;
84+ const matches = property . match ( regex ) ;
85+ if ( matches ) {
86+ const [ , class1 , class2 ] = matches ;
87+ return `:has(.${ class1 . replace ( / _ / g, '-' ) . toLowerCase ( ) } + ${
88+ pascalCaseHtmlTags . includes ( class2 ) ? class2 . toLowerCase ( ) : '.' + class2 . replace ( / _ / g, '-' ) . toLowerCase ( )
89+ } )`;
90+ }
91+ }
92+
93+ if ( isHasECEType ( property ) ) {
94+ const regex = / ^ h a s ( .* ?) C h i l d ( .* ?) $ / ;
95+ const matches = property . match ( regex ) ;
96+ if ( matches ) {
97+ const [ , tag1 , tag2 ] = matches ;
98+ return `:has(${ tag1 . toLowerCase ( ) } > ${ pascalCaseHtmlTags . includes ( tag2 ) ? tag2 . toLowerCase ( ) : '.' + tag2 . replace ( / _ / g, '-' ) . toLowerCase ( ) } )` ;
99+ }
100+ }
101+
102+ if ( isHasEPEType ( property ) ) {
103+ const regex = / ^ h a s ( .* ?) P l u s ( .* ?) $ / ;
104+ const matches = property . match ( regex ) ;
105+ if ( matches ) {
106+ const [ , tag1 , tag2 ] = matches ;
107+ return `:has(${ tag1 . toLowerCase ( ) } + ${ pascalCaseHtmlTags . includes ( tag2 ) ? tag2 . toLowerCase ( ) : '.' + tag2 . replace ( / _ / g, '-' ) . toLowerCase ( ) } )` ;
108+ }
109+ }
110+
57111 const pseudoCamelPropWithArgs = [
58112 'nthChild' ,
59113 'nthLastChild' ,
@@ -62,95 +116,43 @@ export const camelToKebabCase = (property: string) => {
62116 'lang' ,
63117 'notClass' ,
64118 'not' ,
65- 'hasClassChild' ,
66- 'hasClassPlus' ,
67119 'hasClass' ,
68120 'hasChild' ,
69121 'hasPlus' ,
70122 'has' ,
71123 ] ;
72124
73- const toKebabCase = ( str : string ) => str . replace ( / ( [ A - Z ] ) / g, '-$1' ) . toLowerCase ( ) ;
74-
75125 for ( const prop of pseudoCamelPropWithArgs ) {
76126 const index = property . indexOf ( prop ) ;
77127 if ( index !== - 1 ) {
78128 const afterProp = property . slice ( index + prop . length ) ;
79129 const afterNotKebab = afterProp . replace ( / _ / g, '-' ) . toLowerCase ( ) ;
80130
81- if ( prop === 'notClass' ) {
131+ if ( property . startsWith ( 'notClass' ) ) {
82132 return `:not(.${ afterNotKebab } )` ;
83133 }
84134
85- if ( prop === 'not' ) {
135+ if ( property . startsWith ( 'not' ) ) {
86136 if ( property . includes ( 'not(' ) ) {
87137 return `:not${ afterProp . toLowerCase ( ) } ` ;
88138 } else {
89139 return `:not(${ afterProp . toLowerCase ( ) } )` ;
90140 }
91141 }
92142
93- if ( isHasCCCType ( property ) ) {
94- const regex = / ^ h a s C l a s s ( .* ?) C h i l d ( .* ?) $ / ;
95- const matches = property . match ( regex ) ;
96- if ( matches ) {
97- const [ , class1 , class2 ] = matches ;
98- return `:has(.${ class1 . replace ( / _ / g, '-' ) . toLowerCase ( ) } > ${
99- pascalCaseHtmlTags . includes ( class2 ) ? class2 . toLowerCase ( ) : '.' + class2 . replace ( / _ / g, '-' ) . toLowerCase ( )
100- } )`;
101- }
102- }
103-
104- if ( isHasCPCType ( property ) ) {
105- const regex = / ^ h a s C l a s s ( .* ?) P l u s ( .* ?) $ / ;
106- const matches = property . match ( regex ) ;
107- if ( matches ) {
108- const [ , class1 , class2 ] = matches ;
109- return `:has(.${ class1 . replace ( / _ / g, '-' ) . toLowerCase ( ) } + ${
110- pascalCaseHtmlTags . includes ( class2 ) ? class2 . toLowerCase ( ) : '.' + class2 . replace ( / _ / g, '-' ) . toLowerCase ( )
111- } )`;
112- }
113- }
114-
115- if ( prop === 'hasClassChild' ) {
116- return `:has(> .${ afterNotKebab } )` ;
117- }
118-
119- if ( prop === 'hasClassPlus' ) {
120- return `:has(+ .${ afterNotKebab } )` ;
121- }
122-
123- if ( prop === 'hasClass' ) {
143+ if ( property . startsWith ( 'hasClass' ) ) {
124144 return `:has(.${ afterNotKebab } )` ;
125145 }
126146
127- if ( isHasECEType ( property ) ) {
128- const regex = / ^ h a s ( .* ?) C h i l d ( .* ?) $ / ;
129- const matches = property . match ( regex ) ;
130- if ( matches ) {
131- const [ , tag1 , tag2 ] = matches ;
132- return `:has(${ tag1 . toLowerCase ( ) } > ${ pascalCaseHtmlTags . includes ( tag2 ) ? tag2 . toLowerCase ( ) : '.' + tag2 . replace ( / _ / g, '-' ) . toLowerCase ( ) } )` ;
133- }
134- }
135-
136- if ( isHasEPEType ( property ) ) {
137- const regex = / ^ h a s ( .* ?) P l u s ( .* ?) $ / ;
138- const matches = property . match ( regex ) ;
139- if ( matches ) {
140- const [ , tag1 , tag2 ] = matches ;
141- return `:has(${ tag1 . toLowerCase ( ) } + ${ pascalCaseHtmlTags . includes ( tag2 ) ? tag2 . toLowerCase ( ) : '.' + tag2 . replace ( / _ / g, '-' ) . toLowerCase ( ) } )` ;
142- }
143- }
144-
145- if ( prop === 'hasChild' ) {
147+ if ( property . startsWith ( 'hasChild' ) ) {
146148 return `:has(> ${ afterProp . toLowerCase ( ) } )` ;
147149 }
148150
149- if ( prop === 'hasPlus' ) {
151+ if ( property . startsWith ( 'hasPlus' ) ) {
150152 return `:has(+ ${ afterProp . toLowerCase ( ) } )` ;
151153 }
152154
153- if ( prop === 'has' ) {
155+ if ( property . startsWith ( 'has' ) ) {
154156 if ( property . includes ( 'has(' ) ) {
155157 return `:has${ afterProp . toLowerCase ( ) } ` ;
156158 } else {
0 commit comments