Skip to content

Commit e365e9e

Browse files
committed
[css-variables] Per WG resolution, define <any-value> appropriately. Rework bits of the spec to use it.
--HG-- extra : rebase_source : 59c6c044a8847335c10bd578c349d7b966292dc2
1 parent 03d5ca8 commit e365e9e

2 files changed

Lines changed: 74 additions & 56 deletions

File tree

css-variables/Overview.html

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ <h2 id="introduction" data-level="1"><span class="secno">1 </span>
149149
<p> This specification defines an open-ended set of properties called <a data-autolink="link" href="#custom-property">custom properties</a>,
150150
which are used to define <a data-autolink="link" href="#cascading-variable">variables</a>.
151151

152-
</p><table class="propdef"><tbody><tr><th>Name:</th><td><dfn id="var-">var-*</dfn></td></tr><tr><th>Value:</th><td>[ <a data-autolink="link" class="production" href="#value-production"><var>&lt;value&gt;</var></a> | <a data-autolink="link" class="production" href="#cdo-production"><var>&lt;CDO&gt;</var></a> | <a data-autolink="link" class="production" href="#cdc-production"><var>&lt;CDC&gt;</var></a> ]+</td></tr><tr><th>Initial:</th><td>(nothing, see prose)</td></tr><tr><th>Applies to:</th><td>all elements</td></tr><tr><th>Inherited:</th><td>yes</td></tr><tr><th>Computed value:</th><td>specified value with variables substituted (but see prose for "invalid variables")</td></tr><tr><th>Media:</th><td>all</td></tr><tr><th>Animatable:</th><td>no</td></tr></tbody></table>
152+
</p><table class="propdef"><tbody><tr><th>Name:</th><td><dfn id="var-">var-*</dfn></td></tr><tr><th>Value:</th><td><a data-autolink="link" class="production" href="#any-value-production"><var>&lt;any-value&gt;</var></a></td></tr><tr><th>Initial:</th><td>(nothing, see prose)</td></tr><tr><th>Applies to:</th><td>all elements</td></tr><tr><th>Inherited:</th><td>yes</td></tr><tr><th>Computed value:</th><td>specified value with variables substituted (but see prose for "invalid variables")</td></tr><tr><th>Media:</th><td>all</td></tr><tr><th>Animatable:</th><td>no</td></tr></tbody></table>
153153
<p class="issue">
154154
Should variables have special animation behavior,
155155
such that they just never animate,
@@ -221,18 +221,30 @@ <h2 id="introduction" data-level="1"><span class="secno">1 </span>
221221
while using <span data-autolink="maybe" class="css">var(FOO)</span> will refer to the second.
222222
</p></div>
223223

224-
<p> <a data-autolink="link" href="#custom-property">Custom properties</a> are extremely permissive in their value,
225-
accepting any value that the core syntax of CSS allows,
226-
plus the CDO and CDC tokens (written "&lt;!--" and "--&gt;").
227-
The <dfn id="value-production">&lt;value&gt;</dfn> in its grammar corresponds to the "value" production
228-
in <a href="http://www.w3.org/TR/CSS2/syndata.html#tokenization">CSS 2.1 Chapter 4.1</a> <a data-autolink="biblio" data-biblio-type="normative" title="CSS21" href="#css21">[CSS21]</a>,
229-
while <dfn id="cdo-production">&lt;CDO&gt;</dfn> and <dfn id="cdc-production">&lt;CDC&gt;</dfn> correspond to the tokens of the same name
230-
from the same chapter.
231-
232-
</p><p class="note">
233-
Custom properties can contain a trailing <span data-autolink="maybe" class="css">!important</span>,
234-
but this is automatically removed from the property's value by the CSS parser,
235-
and makes the custom property "important" in the CSS cascade.
224+
<p> The allowed syntax for <a data-autolink="link" href="#custom-property">custom properties</a> is extremely permissive.
225+
The <dfn id="any-value-production">&lt;any-value&gt;</dfn> production matches <em>any</em> sequence of one or more tokens,
226+
so long as the sequence does not contain
227+
<a data-autolink="link" class="production"><var>&lt;bad-string&gt;</var></a>,
228+
<a data-autolink="link" class="production"><var>&lt;bad-url&gt;</var></a>,
229+
unmatched &lt;&lt;)&gt;&gt;, &lt;&lt;]&gt;&gt;, or &lt;&lt;}&gt;&gt;,
230+
or top-level <a data-autolink="link" class="production"><var>&lt;semicolon&gt;</var></a> tokens.
231+
232+
</p><p class="note"> Note: This definition,
233+
along with the general CSS syntax rules,
234+
imply that a custom property value never includes an unmatched quote or bracket,
235+
and so cannot have any effect on larger syntax constructs,
236+
like the enclosing style rule,
237+
when reserialized.
238+
239+
</p><p class="note"> Note: Custom properties can contain a trailing <span data-autolink="maybe" class="css">!important</span>,
240+
but this is automatically removed from the property's value by the CSS parser,
241+
and makes the custom property "important" in the CSS cascade.
242+
243+
</p><p class="note"> Note: While <a data-autolink="link" class="production" href="#any-value-production"><var>&lt;any-value&gt;</var></a> must represent at least one token,
244+
that one token may be whitespace.
245+
This implies that <span data-autolink="maybe" class="css">var-foo: ;</span> is valid,
246+
and the corresponding <span data-autolink="maybe" class="css">var(foo)</span> call would have a single space as its substitution value,
247+
but <span data-autolink="maybe" class="css">var-foo:;</span> is invalid.
236248

237249
</p><div class="example">
238250
For example, the following is a valid custom property:
@@ -419,8 +431,7 @@ <h2 id="using-variables" data-level="3"><span class="secno">3 </span>
419431
which can then be substituted into another property with the <a data-autolink="maybe" class="css" href="#variable-type">var()</a> function.
420432
The syntax of <a data-autolink="maybe" class="css" href="#variable-type">var()</a> is:
421433

422-
</p><pre><dfn id="variable-type" title="&lt;variable&gt;|var()">&lt;variable&gt;</dfn> = var( <var>variable-name</var> [, <a data-autolink="link" class="production" href="#fallback-type"><var>&lt;fallback&gt;</var></a> ]? )
423-
<dfn id="fallback-type">&lt;fallback&gt;</dfn> = [ <a data-autolink="link" class="production" href="#value-production"><var>&lt;value&gt;</var></a> | <a data-autolink="link" class="production" href="#cdo-production"><var>&lt;CDO&gt;</var></a> | <a data-autolink="link" class="production" href="#cdc-production"><var>&lt;CDC&gt;</var></a> ]+
434+
</p><pre class="prod"><dfn id="variable-type" title="&lt;variable&gt;|var()">&lt;variable&gt;</dfn> = var( <var>variable-name</var> [, <a data-autolink="link" class="production" href="#any-value-production"><var>&lt;any-value&gt;</var></a> ]? )
424435
</pre>
425436
<p> A variable can be used in place of any part of a value in any property on an element.
426437
Variables can not be used as
@@ -430,15 +441,13 @@ <h2 id="using-variables" data-level="3"><span class="secno">3 </span>
430441
(Doing so usually produces invalid syntax,
431442
or else a value whose meaning has no connection to the variable.)
432443

433-
</p><p> The <a data-autolink="link" class="production" href="#fallback-type"><var>&lt;fallback&gt;</var></a> value is identical to the syntax of a <a data-autolink="link" href="#custom-property">custom property</a> value:
434-
it accepts anything allowed by the core syntax of CSS
435-
(except that, since it's a value in a function rather than a value in a declaration,
436-
some tokens that were allowed in a <a data-autolink="link" href="#custom-property">custom property</a> don't work in a <a data-autolink="link" class="production" href="#fallback-type"><var>&lt;fallback&gt;</var></a> and vice versa,
437-
because they'd close the function early).
444+
</p><p> The second argument to the function, if provided,
445+
is a fallback value,
446+
which is used as the substitution value when the referenced variable is invalid.
438447

439-
</p><p class="note"> Note: The syntax of <a data-autolink="link" class="production" href="#fallback-type"><var>&lt;fallback&gt;</var></a>, like that of <a data-autolink="link" href="#custom-property">custom properties</a>, allows commas.
440-
For example, a variable use like <span data-autolink="maybe" class="css">var(foo, red, blue)</span> defines a fallback of <span data-autolink="maybe" class="css">red, blue</span>;
441-
that is, anything between the first comma and the end of the function is considered a <a data-autolink="link" class="production" href="#fallback-type"><var>&lt;fallback&gt;</var></a> value.
448+
</p><p class="note"> Note: The syntax of the fallback, like that of <a data-autolink="link" href="#custom-property">custom properties</a>, allows commas.
449+
For example, <span data-autolink="maybe" class="css">var(foo, red, blue)</span> defines a fallback of <span data-autolink="maybe" class="css">red, blue</span>;
450+
that is, anything between the first comma and the end of the function is considered a fallback value.
442451

443452
</p><p> A property value containing a variable must be assumed to be valid at parse time.
444453
It is only syntax-checked at computed-value time,
@@ -452,8 +461,8 @@ <h2 id="using-variables" data-level="3"><span class="secno">3 </span>
452461
replace the <a data-autolink="maybe" class="css" href="#variable-type">var()</a> function by the value of the corresponding <a data-autolink="link" href="#custom-property">custom property</a>.
453462

454463
</li><li>
455-
Otherwise, if the <a data-autolink="maybe" class="css" href="#variable-type">var()</a> function has a <a data-autolink="link" class="production" href="#fallback-type"><var>&lt;fallback&gt;</var></a> value as its second argument,
456-
replace the <a data-autolink="maybe" class="css" href="#variable-type">var()</a> function by the <a data-autolink="link" class="production" href="#fallback-type"><var>&lt;fallback&gt;</var></a> value.
464+
Otherwise, if the <a data-autolink="maybe" class="css" href="#variable-type">var()</a> function has a fallback value as its second argument,
465+
replace the <a data-autolink="maybe" class="css" href="#variable-type">var()</a> function by the fallback value.
457466
If there are any <a data-autolink="maybe" class="css" href="#variable-type">var()</a> references in the fallback,
458467
<a title="resolve a variable" data-autolink="link" href="#resolve-a-variable">resolve</a> them as well.
459468

@@ -925,19 +934,19 @@ <h3 class="no-ref" id="testing">
925934

926935
<h3 id="normative" class="no-num no-ref">
927936
Normative References</h3>
928-
<div data-fill-with="normative-references"><dl><dt id="rfc2119" title="RFC2119">[RFC2119]</dt><dd>S. Bradner. <a href="http://www.ietf.org/rfc/rfc2119.txt">Key words for use in RFCs to Indicate Requirement Levels</a>. URL: <a href="http://www.ietf.org/rfc/rfc2119.txt">http://www.ietf.org/rfc/rfc2119.txt</a></dd><dt id="css21" title="CSS21">[CSS21]</dt><dd>Bert Bos; et al. <a href="http://www.w3.org/TR/2011/REC-CSS2-20110607/">Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification</a>. 7 June 2011. W3C Recommendation. URL: <a href="http://www.w3.org/TR/2011/REC-CSS2-20110607/">http://www.w3.org/TR/2011/REC-CSS2-20110607/</a></dd></dl></div>
937+
<div data-fill-with="normative-references"><dl><dt id="css21" title="CSS21">[CSS21]</dt><dd>Bert Bos; et al. <a href="http://www.w3.org/TR/2011/REC-CSS2-20110607/">Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification</a>. 7 June 2011. W3C Recommendation. URL: <a href="http://www.w3.org/TR/2011/REC-CSS2-20110607/">http://www.w3.org/TR/2011/REC-CSS2-20110607/</a></dd><dt id="rfc2119" title="RFC2119">[RFC2119]</dt><dd>S. Bradner. <a href="http://www.ietf.org/rfc/rfc2119.txt">Key words for use in RFCs to Indicate Requirement Levels</a>. URL: <a href="http://www.ietf.org/rfc/rfc2119.txt">http://www.ietf.org/rfc/rfc2119.txt</a></dd></dl></div>
929938

930939
<h3 id="informative" class="no-num no-ref">
931940
Informative References</h3>
932941
<div data-fill-with="informative-references"><dl><dt id="css3color" title="CSS3COLOR">[CSS3COLOR]</dt><dd>Tantek &#199;elik; Chris Lilley; L. David Baron. <a href="http://www.w3.org/TR/2011/REC-css3-color-20110607">CSS Color Module Level 3</a>. 7 June 2011. W3C Recommendation. URL: <a href="http://www.w3.org/TR/2011/REC-css3-color-20110607">http://www.w3.org/TR/2011/REC-css3-color-20110607</a></dd></dl></div>
933942

934943
<h2 id="index" class="no-num no-ref">
935944
Index</h2>
936-
<div data-fill-with="index"><ul class="indexlist"><li>associated style declaration, <a href="#associated-style-declaration" title="section 4.1">4.1</a></li><li>cascading variable, <a href="#cascading-variable" title="section 2">2</a></li><li>&lt;CDC&gt;, <a href="#cdc-production" title="section 2">2</a></li><li>&lt;CDO&gt;, <a href="#cdo-production" title="section 2">2</a></li><li>creator, <a href="#cssvariablesdeclaration-creator" title="section 4.2">4.2</a></li><li>CSS declaration block declarations, <a href="#css-declaration-block-declarations" title="section 4.2">4.2</a></li><li>CSSStyleDeclaration, <a href="#cssstyledeclaration" title="section 4.1">4.1</a></li><li>CSSVariablesDeclaration, <a href="#cssvariablesdeclaration" title="section 4.2">4.2</a></li><li>custom property, <a href="#custom-property" title="section 2">2</a></li><li>deleter, <a href="#cssvariablesdeclaration-deleter" title="section 4.2">4.2</a></li><li>&lt;fallback&gt;, <a href="#fallback-type" title="section 3">3</a></li><li>getter, <a href="#cssvariablesdeclaration-getter" title="section 4.2">4.2</a></li><li>invalid at computed-value time, <a href="#invalid-at-computed-value-time" title="section 3.1">3.1</a></li><li>invalid variable, <a href="#invalid-variable" title="section 3.1">3.1</a></li><li>resolve a variable, <a href="#resolve-a-variable" title="section 3">3</a></li><li>setter, <a href="#cssvariablesdeclaration-setter" title="section 4.2">4.2</a></li><li>&lt;value&gt;, <a href="#value-production" title="section 2">2</a></li><li>var-*, <a href="#var-" title="section 2">2</a></li><li>var(), <a href="#variable-type" title="section 3">3</a></li><li>&lt;variable&gt;, <a href="#variable-type" title="section 3">3</a></li><li>variable, <a href="#cascading-variable" title="section 2">2</a></li></ul></div>
945+
<div data-fill-with="index"><ul class="indexlist"><li>&lt;any-value&gt;, <a href="#any-value-production" title="section 2">2</a></li><li>associated style declaration, <a href="#associated-style-declaration" title="section 4.1">4.1</a></li><li>cascading variable, <a href="#cascading-variable" title="section 2">2</a></li><li>creator, <a href="#cssvariablesdeclaration-creator" title="section 4.2">4.2</a></li><li>CSS declaration block declarations, <a href="#css-declaration-block-declarations" title="section 4.2">4.2</a></li><li>CSSStyleDeclaration, <a href="#cssstyledeclaration" title="section 4.1">4.1</a></li><li>CSSVariablesDeclaration, <a href="#cssvariablesdeclaration" title="section 4.2">4.2</a></li><li>custom property, <a href="#custom-property" title="section 2">2</a></li><li>deleter, <a href="#cssvariablesdeclaration-deleter" title="section 4.2">4.2</a></li><li>getter, <a href="#cssvariablesdeclaration-getter" title="section 4.2">4.2</a></li><li>invalid at computed-value time, <a href="#invalid-at-computed-value-time" title="section 3.1">3.1</a></li><li>invalid variable, <a href="#invalid-variable" title="section 3.1">3.1</a></li><li>resolve a variable, <a href="#resolve-a-variable" title="section 3">3</a></li><li>setter, <a href="#cssvariablesdeclaration-setter" title="section 4.2">4.2</a></li><li>var(), <a href="#variable-type" title="section 3">3</a></li><li>var-*, <a href="#var-" title="section 2">2</a></li><li>&lt;variable&gt;, <a href="#variable-type" title="section 3">3</a></li><li>variable, <a href="#cascading-variable" title="section 2">2</a></li></ul></div>
937946

938947
<h2 id="property-index" class="no-num no-ref">
939948
Property index</h2>
940-
<div data-fill-with="property-index"><table class="proptable"><thead><tr><th scope="col">Name</th><th scope="col">Value</th><th scope="col">Initial</th><th scope="col">Applies To</th><th scope="col">Inh.</th><th scope="col">%ages</th><th scope="col">Media</th><th scope="col">Computed value</th><th scope="col">Applies to</th><th scope="col">Animatable</th></tr><tr><th scope="row"><a data-property="">var-*</a></th><td>[ <a data-autolink="link" class="production"><var>&lt;value&gt;</var></a> | <a data-autolink="link" class="production"><var>&lt;CDO&gt;</var></a> | <a data-autolink="link" class="production"><var>&lt;CDC&gt;</var></a> ]+</td><td>(nothing, see prose)</td><td></td><td>yes</td><td></td><td>all</td><td>specified value with variables substituted (but see prose for "invalid variables")</td><td>all elements</td><td>no</td></tr></thead></table></div>
949+
<div data-fill-with="property-index"><table class="proptable"><thead><tr><th scope="col">Name</th><th scope="col">Value</th><th scope="col">Initial</th><th scope="col">Applies To</th><th scope="col">Inh.</th><th scope="col">%ages</th><th scope="col">Media</th><th scope="col">Computed value</th><th scope="col">Applies to</th><th scope="col">Animatable</th></tr><tr><th scope="row"><a data-property="">var-*</a></th><td><a data-autolink="link" class="production"><var>&lt;any-value&gt;</var></a></td><td>(nothing, see prose)</td><td></td><td>yes</td><td></td><td>all</td><td>specified value with variables substituted (but see prose for "invalid variables")</td><td>all elements</td><td>no</td></tr></thead></table></div>
941950

942951

943952
</body></html>

0 commit comments

Comments
 (0)