Skip to content

Commit 7c9fac0

Browse files
committed
[css-extensions] Start upgrading custom selectors based on ML feedback.
1 parent 7c75742 commit 7c9fac0

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

css-extensions/Overview.bs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,34 @@ Extension Names</h2>
4242
without ever having to worry about colliding with CSS-defined names.
4343

4444
<h2 id='custom-selectors'>
45-
Custom Selectors</h2>
45+
<dfn lt="custom selector">Custom Selectors</dfn></h2>
4646

47-
A <dfn>custom selector</dfn> is defined with the ''@custom-selector'' rule:
47+
A <dfn>declarative custom selector</dfn> is defined with the ''@custom-selector'' rule:
4848

49-
<pre class='prod'><dfn>@custom-selector</dfn> = @custom-selector <<extension-name>> <<selector>> ;</pre>
49+
<pre class='prod'>
50+
<dfn>@custom-selector</dfn> = @custom-selector <<custom-selector>> <<selector>> ;
51+
<dfn>&lt;custom-selector></dfn> = <<custom-arg>>? : <<extension-name>> [ ( <<custom-arg>>+#? ) ]? ;
52+
<dfn>&lt;custom-arg></dfn> = $ <<ident-token>> ;
53+
</pre>
54+
55+
Where there must be no whitespace
56+
between <code>:</code> and <<extension-name>>
57+
or between <code>$</code> and <<ident-token>>
58+
in the above definitions.
59+
60+
<div class='issue'>
61+
<pre>
62+
// Arguments are specified with $foo.
63+
// An arg before the pseudo-class captures the rest of the compound selector.
64+
@custom-selector $rest:--n-siblings($n, $sel) {
65+
specificity: $sel;
66+
// assumes $sel is a selector, parses it and uses its specificity
67+
// otherwise, specificity is [0,1,0]
68+
expansion: $rest:nth-child(1 of $sel):nth-last-child($n of $sel),
69+
:nth-child(1 of $sel):nth-last-child($n of $sel) ~ $rest;
70+
}
71+
</pre>
72+
</div>
5073

5174
This defines a <a>custom selector</a> which is written as a <a spec=selectors>pseudo-class</a> with the given <<extension-name>>,
5275
and represents a '':matches()'' selector using the provided <<selector>> as its argument.

0 commit comments

Comments
 (0)