@@ -40,6 +40,7 @@ public function parseSelectorString(string $selector): ParsedSelectorCollectionD
40
40
$ value = null ;
41
41
$ noKey = false ;
42
42
$ alterNext = false ;
43
+ $ isNthOfType = false ;
43
44
44
45
// check for elements that alter the behavior of the next element
45
46
if ($ tag == '> ' ) {
@@ -64,13 +65,14 @@ public function parseSelectorString(string $selector): ParsedSelectorCollectionD
64
65
$ tag = '* ' ;
65
66
$ value = \substr ($ match [0 ], 1 );
66
67
67
- if (preg_match ("/^nth-child\(\d+\)$/ " , \trim ($ value , ', ' ))) {
68
- preg_match_all ("/^nth-child\((\d+)\)$/ " , \trim ($ value , ', ' ), $ matches , PREG_SET_ORDER );
69
- $ key = (int ) $ matches [0 ][1 ];
70
- } else if (preg_match ("/^nth-last-child\(\d+\)$/ " , \trim ($ value , ', ' ))) {
71
- preg_match_all ("/^nth-last-child\((\d+)\)$/ " , \trim ($ value , ', ' ), $ matches , PREG_SET_ORDER );
72
- $ key = - (int ) $ matches [0 ][1 ];
68
+ if (preg_match ("/^( nth-child|nth-of-type) \(\d+\)$/ " , \trim ($ value , ', ' ))) {
69
+ preg_match_all ("/^( nth-child|nth-of-type) \((\d+)\)$/ " , \trim ($ value , ', ' ), $ matches , PREG_SET_ORDER );
70
+ $ key = (int ) $ matches [0 ][2 ];
71
+ } else if (preg_match ("/^( nth-last-child|nth-last-of-type) \(\d+\)$/ " , \trim ($ value , ', ' ))) {
72
+ preg_match_all ("/^( nth-last-child|nth-last-of-type) \((\d+)\)$/ " , \trim ($ value , ', ' ), $ matches , PREG_SET_ORDER );
73
+ $ key = - (int ) $ matches [0 ][2 ];
73
74
}
75
+ $ isNthOfType = preg_match ("/^nth(-last)?-of-type\(\d+\)$/ " , \trim ($ value , ', ' ));
74
76
}
75
77
76
78
// and final attribute selector
@@ -113,7 +115,8 @@ public function parseSelectorString(string $selector): ParsedSelectorCollectionD
113
115
$ key ,
114
116
$ value ,
115
117
$ noKey ,
116
- $ alterNext
118
+ $ alterNext ,
119
+ $ isNthOfType
117
120
);
118
121
if (isset ($ match [7 ]) && \is_string ($ match [7 ]) && \trim ($ match [7 ]) == ', ' ) {
119
122
$ selectors [] = ParsedSelectorDTO::makeFromRules ($ rules );
0 commit comments