Skip to content

Commit 7de6415

Browse files
committed
[css-variables] Define 'resolve a variable'.
--HG-- extra : rebase_source : c3bbf8ac79e0c940a5ccaa837ee89e7d7575c85e
1 parent 95cca2a commit 7de6415

File tree

2 files changed

+48
-16
lines changed

2 files changed

+48
-16
lines changed

css-variables/Overview.html

+25-9
Original file line numberDiff line numberDiff line change
@@ -419,15 +419,31 @@ <h2 id="using-variables" data-level="3"><span class="secno">3 </span>
419419
For example, a variable use like <a data-autolink="maybe" class="css">var(foo, red, blue)</a> defines a fallback of <a data-autolink="maybe" class="css">red, blue</a>;
420420
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.
421421

422-
</p><p> If the variable named by the first argument is valid,
423-
the variable's value is substituted as normal.
424-
If the variable is invalid,
425-
and a <a data-autolink="link" class="production" href="#fallback-type"><var>&lt;fallback&gt;</var></a> was provided,
426-
the <a data-autolink="link" class="production" href="#fallback-type"><var>&lt;fallback&gt;</var></a> is substituted instead.
427-
Otherwise, the result of evaluating the <a data-autolink="maybe" class="css" href="#variable-type">var()</a> function will mean
428-
that the containing declaration is invalid at computed-value time.
422+
</p><p> A property value containing a variable must be assumed to be valid at parse time.
423+
It is only syntax-checked at computed-value time,
424+
after variable references have been <a title="resolve a variable" data-autolink="link" href="#resolve-a-variable">resolved</a>.
429425

430-
</p><div class="example">
426+
</p><p> To <dfn id="resolve-a-variable">resolve a variable</dfn> in a property's value:
427+
428+
</p><ol>
429+
<li>
430+
If the variable named by the first argument to the <a data-autolink="maybe" class="css" href="#variable-type">var()</a> function is a valid variable,
431+
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>.
432+
433+
</li><li>
434+
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,
435+
replace the <a data-autolink="maybe" class="css" href="#variable-type">var()</a> function by the <a data-autolink="link" class="production"><var>&lt;falback&gt;</var></a> value.
436+
If there are any <a data-autolink="maybe" class="css" href="#variable-type">var()</a> references in the fallback,
437+
<a title="resolve a variable" data-autolink="link" href="#resolve-a-variable">resolve</a> them as well.
438+
439+
</li><li>
440+
Otherwise,
441+
the property containing the <a data-autolink="maybe" class="css" href="#variable-type">var()</a> function is <a data-autolink="link" href="#invalid-at-computed-value-time">invalid at computed-value time</a>.
442+
443+
<p class="note"> Note: Other things can also make a property <a data-autolink="link" href="#invalid-at-computed-value-time">invalid at computed-value time</a>.
444+
</p></li></ol>
445+
446+
<div class="example">
431447
The fallback value allows for some types of defensive coding.
432448
For example,
433449
an author may create a component
@@ -895,7 +911,7 @@ <h3 id="informative" class="no-num no-ref">
895911

896912
<h2 id="index" class="no-num no-ref">
897913
Index</h2>
898-
<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>authoring tool, <a href="#authoring-tool" title="section ??">??</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>renderer, <a href="#renderer" title="section ??">??</a></li><li>setter, <a href="#cssvariablesdeclaration-setter" title="section 4.2">4.2</a></li><li>style sheet!!as conformance class, <a href="#style-sheet" title="section ??">??</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>
914+
<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>authoring tool, <a href="#authoring-tool" title="section ??">??</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>renderer, <a href="#renderer" title="section ??">??</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>style sheet!!as conformance class, <a href="#style-sheet" title="section ??">??</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>
899915

900916
<h2 id="property-index" class="no-num no-ref">
901917
Property index</h2>

css-variables/Overview.src.html

+23-7
Original file line numberDiff line numberDiff line change
@@ -362,13 +362,29 @@ <h2 id='using-variables'>
362362
For example, a variable use like ''var(foo, red, blue)'' defines a fallback of ''red, blue'';
363363
that is, anything between the first comma and the end of the function is considered a <<fallback>> value.
364364

365-
If the variable named by the first argument is valid,
366-
the variable's value is substituted as normal.
367-
If the variable is invalid,
368-
and a <<fallback>> was provided,
369-
the <<fallback>> is substituted instead.
370-
Otherwise, the result of evaluating the ''var()'' function will mean
371-
that the containing declaration is invalid at computed-value time.
365+
A property value containing a variable must be assumed to be valid at parse time.
366+
It is only syntax-checked at computed-value time,
367+
after variable references have been <a title="resolve a variable">resolved</a>.
368+
369+
To <dfn>resolve a variable</dfn> in a property's value:
370+
371+
<ol>
372+
<li>
373+
If the variable named by the first argument to the ''var()'' function is a valid variable,
374+
replace the ''var()'' function by the value of the corresponding <a>custom property</a>.
375+
376+
<li>
377+
Otherwise, if the ''var()'' function has a <<fallback>> value as its second argument,
378+
replace the ''var()'' function by the <<falback>> value.
379+
If there are any ''var()'' references in the fallback,
380+
<a title="resolve a variable">resolve</a> them as well.
381+
382+
<li>
383+
Otherwise,
384+
the property containing the ''var()'' function is <a>invalid at computed-value time</a>.
385+
386+
Note: Other things can also make a property <a>invalid at computed-value time</a>.
387+
</ol>
372388

373389
<div class='example'>
374390
The fallback value allows for some types of defensive coding.

0 commit comments

Comments
 (0)