@@ -40,6 +40,7 @@ public function parseSelectorString(string $selector): ParsedSelectorCollectionD
4040 $ value = null ;
4141 $ noKey = false ;
4242 $ alterNext = false ;
43+ $ isNthOfType = false ;
4344
4445 // check for elements that alter the behavior of the next element
4546 if ($ tag == '> ' ) {
@@ -71,14 +72,21 @@ public function parseSelectorString(string $selector): ParsedSelectorCollectionD
7172 else if (\trim ($ value , ', ' ) == 'last-child ' ) {
7273 $ value = 'nth-last-child(1) ' ;
7374 }
75+ else if (\trim ($ value , ', ' ) == 'first-of-type ' ) {
76+ $ value = 'nth-of-type(1) ' ;
77+ }
78+ else if (\trim ($ value , ', ' ) == 'last-of-type ' ) {
79+ $ value = 'nth-last-of-type(1) ' ;
80+ }
7481
75- if (preg_match ("/^nth-child\(\d+\)$/ " , \trim ($ value , ', ' ))) {
76- preg_match_all ("/^nth-child\((\d+)\)$/ " , \trim ($ value , ', ' ), $ matches , PREG_SET_ORDER );
77- $ key = (int ) $ matches [0 ][1 ];
78- } else if (preg_match ("/^nth-last-child\(\d+\)$/ " , \trim ($ value , ', ' ))) {
79- preg_match_all ("/^nth-last-child\((\d+)\)$/ " , \trim ($ value , ', ' ), $ matches , PREG_SET_ORDER );
80- $ key = - (int ) $ matches [0 ][1 ];
82+ if (preg_match ("/^( nth-child|nth-of-type) \(\d+\)$/ " , \trim ($ value , ', ' ))) {
83+ preg_match_all ("/^( nth-child|nth-of-type) \((\d+)\)$/ " , \trim ($ value , ', ' ), $ matches , PREG_SET_ORDER );
84+ $ key = (int ) $ matches [0 ][2 ];
85+ } else if (preg_match ("/^( nth-last-child|nth-last-of-type) \(\d+\)$/ " , \trim ($ value , ', ' ))) {
86+ preg_match_all ("/^( nth-last-child|nth-last-of-type) \((\d+)\)$/ " , \trim ($ value , ', ' ), $ matches , PREG_SET_ORDER );
87+ $ key = - (int ) $ matches [0 ][2 ];
8188 }
89+ $ isNthOfType = preg_match ("/^nth(-last)?-of-type\(\d+\)$/ " , \trim ($ value , ', ' ));
8290 }
8391
8492 // and final attribute selector
@@ -121,7 +129,8 @@ public function parseSelectorString(string $selector): ParsedSelectorCollectionD
121129 $ key ,
122130 $ value ,
123131 $ noKey ,
124- $ alterNext
132+ $ alterNext ,
133+ $ isNthOfType
125134 );
126135 if (isset ($ match [7 ]) && \is_string ($ match [7 ]) && \trim ($ match [7 ]) == ', ' ) {
127136 $ selectors [] = ParsedSelectorDTO::makeFromRules ($ rules );
0 commit comments