@@ -310,7 +310,7 @@ public function convertNode(DOMNode $node, int $level = 0): DOMNode
310
310
$ this ->handleHtml ($ node );
311
311
$ this ->handleText ($ node );
312
312
$ this ->stripEventHandlers ($ node );
313
- $ this ->handleSlots ($ node );
313
+ $ this ->handleSlots ($ node, $ level );
314
314
$ this ->cleanupAttributes ($ node );
315
315
$ this ->addScopedAttribute ($ node , $ level );
316
316
}
@@ -762,15 +762,15 @@ public function handleBinding(string $value, string $name, ?DOMElement $node = n
762
762
if (preg_match ('/^`(.*)`$/ ' , $ element , $ match )) {
763
763
$ dynamicValues [] = $ this ->handleTemplateStringBinding ($ match [1 ], $ twigOutput );
764
764
} elseif (preg_match ('/^\{(.*)\}$/ ' , $ element , $ match )) {
765
- $ this ->handleObjectBinding ([$ match [1 ]], $ dynamicValues , $ twigOutput );
765
+ $ this ->handleObjectBinding ([$ match [1 ]], $ dynamicValues , $ twigOutput, $ name === ' style ' );
766
766
} else {
767
767
$ dynamicValues [] = $ element ;
768
768
}
769
769
}
770
770
} elseif (preg_match ($ regexObjectBinding , $ value , $ matches )) {
771
771
$ this ->logger ->debug ('- object binding ' , ['value ' => $ value ]);
772
772
$ items = explode (', ' , $ matches ['elements ' ]);
773
- $ this ->handleObjectBinding ($ items , $ dynamicValues , $ twigOutput );
773
+ $ this ->handleObjectBinding ($ items , $ dynamicValues , $ twigOutput, $ name === ' style ' );
774
774
} elseif (preg_match ($ regexTemplateString , $ value , $ matches )) {
775
775
// <div :class="`abc ${someDynamicClass}`">
776
776
$ this ->logger ->debug ('- template string binding ' , ['value ' => $ value ]);
@@ -795,13 +795,15 @@ public function handleBinding(string $value, string $name, ?DOMElement $node = n
795
795
* @param string[] $dynamicValues
796
796
* @throws ReflectionException
797
797
*/
798
- protected function handleObjectBinding (array $ items , array &$ dynamicValues , bool $ twigOutput ): void
798
+ protected function handleObjectBinding (array $ items , array &$ dynamicValues , bool $ twigOutput, bool $ isStyle ): void
799
799
{
800
- $ regexObjectElements = '/[" \']?(?<class>[^" \']+)[" \']?\s*:\s*(?<condition>[^,]+)/x ' ;
800
+ $ regexObjectElements = '/(?<isString> [" \']?) (?<class>[^" \']+)[" \']?\s*:\s*(?<condition>[^,]+)/x ' ;
801
801
foreach ($ items as $ item ) {
802
802
if (preg_match ($ regexObjectElements , $ item , $ matchElement )) {
803
803
$ dynamicValues [] = $ this ->builder ->prepareBindingOutput (
804
- $ this ->builder ->refactorCondition ($ matchElement ['condition ' ]) . ' ? \'' . $ matchElement ['class ' ] . '\'' ,
804
+ $ isStyle && !$ matchElement ['isString ' ]
805
+ ? '\'' . $ this ->camelCaseToKebabCase ($ matchElement ['class ' ]) . ': \' + ' . $ matchElement ['condition ' ]
806
+ : $ this ->builder ->refactorCondition ($ matchElement ['condition ' ]) . ' ? \'' . $ matchElement ['class ' ] . '\'' ,
805
807
$ twigOutput
806
808
);
807
809
}
@@ -1345,15 +1347,15 @@ protected function createVariableBlock(): string
1345
1347
/**
1346
1348
* @throws Exception
1347
1349
*/
1348
- protected function handleSlots (DOMElement $ node ): void
1350
+ protected function handleSlots (DOMElement $ node, int $ level ): void
1349
1351
{
1350
1352
if ($ node ->nodeName !== 'slot ' ) {
1351
1353
return ;
1352
1354
}
1353
1355
1354
1356
if ($ node ->hasChildNodes ()) {
1355
1357
foreach ($ node ->childNodes as $ childNode ) {
1356
- $ this ->convertNode ($ childNode );
1358
+ $ this ->convertNode ($ childNode, $ level + 1 );
1357
1359
}
1358
1360
}
1359
1361
@@ -1528,4 +1530,9 @@ private function replaceAttributeWithIfConditionPlaceholders(string $html): stri
1528
1530
1529
1531
return $ html ;
1530
1532
}
1533
+
1534
+ private function camelCaseToKebabCase (string $ text ): string
1535
+ {
1536
+ return strtolower (preg_replace ('/([a-z])([A-Z])/ ' , '\1-\2 ' , $ text ));
1537
+ }
1531
1538
}
0 commit comments