@@ -9,7 +9,7 @@ ED: https://drafts.csswg.org/css-link-params/
99Editor : Tab Atkins-Bittner, Google, http://xanthir.com/contact/
1010Editor : Daniel Holbert, Mozilla
1111Editor : Jonathan Watt, Mozilla
12- Abstract : This spec introduces a way to pass CSS values into linked resources, such as SVG images, so that they can be used as CSS [=custom property=] values in the destination resource. This allows easy reuse of "templated" SVG images, which can be adapted to a site's theme color, etc. easily, without having to modify the source SVG.
12+ Abstract : This spec introduces a way to pass CSS values into linked resources, such as SVG images, so that they can be used as CSS [=custom environment variables=] in the destination resource. This allows easy reuse of "templated" SVG images, which can be adapted to a site's theme color, etc. easily, without having to modify the source SVG.
1313Ignored Terms : css value definition syntax
1414</pre>
1515
@@ -39,18 +39,55 @@ and change which image you're referencing.
3939This incurs delay on the page as a new resource is downloaded,
4040and disallows dynamic effects like CSS Transitions.
4141
42- <dfn export lt="CSS link parameter" local-lt="link parameter">CSS link parameters</dfn> are a way to set CSS <a>custom properties</a> on an "external" resource,
42+ <dfn export lt="CSS link parameter" local-lt="link parameter">CSS link parameters</dfn>
43+ are a way to set CSS <a>custom environment variables</a> on an "external" resource,
4344either by a CSS property
4445or thru a special fragment scheme on the URL.
4546This gives a limited, but powerful, subset of the customizability that "inline" SVG images have
4647to "external" SVG images.
4748
49+ A [=link parameter=] is a pair of a <<dashed-ident>> name,
50+ and an arbitrary (possibly empty) <<declaration-value>> value.
51+
52+ <div class=example>
53+ For example, an SVG image can be written to use [=link parameters=] ,
54+ allowing it to have its colors changed on the fly,
55+ like:
56+
57+ <xmp highlight=html>
58+ <svg>
59+ <path fill="env(--color, black)" d="..." />
60+ </svg>
61+ </xmp>
62+
63+ By default, it will fill its shape with black,
64+ as that's the fallback color specified.
65+ But [=link parameters=] can customize the color
66+ in several ways:
67+
68+ <xmp highlight=html>
69+ <img src="image.svg#param(--color,green)">
70+ </xmp>
71+
72+ <pre highlight=css>
73+ img {
74+ link-parameters: param(color, green);
75+ }
76+ </pre>
77+
78+ <pre highlight=css>
79+ .foo {
80+ background-image: url("image.svg", param(--color, green));
81+ }
82+ </pre>
83+ </div>
84+
4885Setting a Link Parameter {#setting}
4986===================================
5087
51- An external resource can be accompanied by a map of [=link parameters=] ,
52- each entry composed of a [=custom property name=] as a key,
53- and an <<any -value>> as the value.
88+ An external resource can be accompanied by a list of [=link parameters=] ,
89+ each entry composed of a <<dashed-ident>> as a key,
90+ and a (possibly empty) <<declaration -value>> as the value.
5491
5592There are three ways to specify a [=link parameter=] :
5693
@@ -62,22 +99,28 @@ There are three ways to specify a [=link parameter=]:
6299* via a ''param()'' argument in the ''url()'' syntax
63100
64101If specified in multiple of these ways,
65- all of the [=link parameters=] are combined.
66- If the same key appears in multiple inputs,
67- the latest source in the above list wins
68- (that is, URL fragment beats 'link-parameters' ,
69- and ''url("..." param())'' beats URL fragment).
102+ all of the [=link parameters=] are appended into a single list
103+ for the external resource,
104+ in the order:
105+
106+ 1. the 'link-parameters' property on the element, if relevant
107+ 2. the [=param()=] URL fragment identifiers
108+ 3. the ''param()'' <<url-modifier>> s in ''url()''
70109
71- The influence of [=link parameters=] on the linked resource
72- is defined in the next section.
110+ If multiple [=link parameters=] exist with the same name,
111+ the last one in the list is used.
112+
113+ How to access [=link parameters=] in the linked resource
114+ is defined in the next section,
115+ [[#using]] .
73116
74117
75118In CSS: the 'link-parameters' property {#link-param-prop}
76119--------------------------------------
77120
78121<pre class=propdef>
79122Name : link-parameters
80- Value : none | <<link- param>>+
123+ Value : none | <<param()>>#
81124Initial : none
82125Inherited : no
83126Applies to : all elements and pseudo-elements
@@ -95,27 +138,23 @@ Its values are:
95138
96139<dl dfn-type=value dfn-for=none>
97140 : <dfn>none</dfn>
98- :: No [=link parameters=] specified.
99-
100- : <dfn><<link-param>>+</dfn>
101- ::
102- A list of one or more [=link parameters=] .
103- If two [=link parameters=] with the same name are specified
104- with the same <<custom-property-name>> ,
105- the last one wins.
141+ :: No [=link parameters=] are specified.
142+
143+ : <dfn><<param()>>#</dfn>
144+ :: A list of one or more [=link parameters=] .
106145</dl>
107146
147+ The <dfn>param()</dfn> function specifies a [=link parameter=] ,
148+ with a key of the <<dashed-ident>> ,
149+ and a value of the <css> <<declaration-value>> ?</css> .
150+ (If the <<declaration-value>> is omitted,
151+ it represents an empty value.)
152+ It has the syntax:
153+
108154<pre class=prod>
109- <dfn> <link- param></dfn> = param( <<custom-property-name>> <<declaration-value>> ? )
155+ <param()> = param( <<dashed-ident>> , <<declaration-value>> ? )
110156</pre>
111157
112- A <<link-param>> represents a [=link parameter=] ,
113- with a key of the <<custom-property-name>> .
114- If the <<declaration-value>> is specified,
115- that's the value of the [=link parameter=] .
116- If omitted,
117- the value of the [=custom property=] of the same name on the element
118- is the value of the [=link parameter=] .
119158
120159In The URL {#url-frag}
121160----------
@@ -126,23 +165,25 @@ Several examples of existing "fragment identifiers" for SVG documents can be fou
126165
127166The syntax of an <dfn export local-lt="param()">SVG parameter fragment identifier</dfn> is:
128167
129- <pre class=prod>param( <<custom-property-name >> <<declaration-value>> )</pre>
168+ <pre class=prod>param( <<dashed-ident >> , <<declaration-value>> ? )</pre>
130169
131170(using the <a>CSS value definition syntax</a> ; TODO define an actual parser for it).
132171
133172<div class="example">
134- For example, to set the "--text-color" <a>custom property</a> of an SVG image to ''blue'' ,
135- one can reference the image with a url like “<code> http://example.com/image.svg#param(--text-color%20blue)</code> ”.
173+ For example, to set the ''env(--text-color)'' [=custom environment variable=]
174+ of an SVG image to ''blue'' ,
175+ one can reference the image with a url like
176+ “<code> http://example.com/image.svg#param(--text-color,blue)</code> ”.
136177</div>
137178
138- If passing multiple parameters to an image,
139- additional <a>param()</a> functions must be appended to the URL.
140- If multiple <a>param()</a> functions specify the same <<custom-property-name>> ,
141- the <a>custom property</a> is set to the value of the last one.
179+ Multiple [=link parameters=] can be passed to an image
180+ by appending multiple [=param()=] fragment identifiers to the URL.
142181
143182<div class="example">
144- For example, if the image from the previous example also used a "--bg-color" <a>custom property</a> ,
145- it could be referenced with a url like “<code> http://example.com/image.svg#param(--text-color%20blue)param(--bg-color%20white)</code> ”.
183+ For example, if the image from the previous example also used ''env(--bg-color)'' ,
184+ it could be referenced with a url like
185+ “<code> http://example.com/image.svg#param(--text-color,blue)param(--bg-color,white)</code> ”
186+ to set both ''env(--text-color)'' and ''env(--bg-color)'' .
146187</div>
147188
148189Note: Spaces, and some other characters that might be valid in CSS syntax,
@@ -164,21 +205,23 @@ and want to make an SVG image match.
164205There's no way, however, to integrate the value of a <a>custom property</a> in CSS into the URL passed to the ''url()'' function.
165206
166207To accommodate this,
167- a <<link-param>> is a valid <<url-modifier>> .
168-
169- As in the other methods of specifying [=link parameters=] ,
170- if the same <<custom-property-name>> is specified in several <<link-param>> s,
171- the last one wins.
208+ ''param()'' is a valid <<url-modifier>> .
209+ All the ''param()'' s specified as a <<url-modifier>>
210+ define [=link parameters=] ,
211+ as for 'link-parameters' .
172212
173213<div class="example">
174214 For example,
175215 if the site is using a ''--primary-color'' custom property to theme its elements with,
176- and wanted an SVG background using a '' --color'' custom property to reflect it,
216+ and wanted an SVG background using ''env( --color)'' to reflect it,
177217 it could write:
178218
179- <pre class='lang- css' >
219+ <pre highlight= css>
180220 .foo {
181- background-image: url("http://example.com/image.svg" param(--color var(--primary-color)));
221+ background-image: url(
222+ "http://example.com/image.svg"
223+ param(--color, var(--primary-color))
224+ );
182225 }
183226 </pre>
184227</div>
@@ -189,73 +232,53 @@ Using Link Parameters {#using}
189232When an external resource link has one or more [=link parameters=] specified,
190233if the linked resource understands CSS
191234(such as an SVG or HTML document),
192- then the initial value of custom properties
193- with names equal to the keys of the [=link parameters=] map
194- is set to the corresponding values of the map.
195-
196- If an ''@property'' rule is specified for one of the custom property names
197- in the [=link parameters=] ,
198- the [=link parameter=] value is used for the initial value,
199- rather than the ''@property'' -specified initial value.
200-
201- If the linked resource does not understand CSS
202- (such as PNG images),
203- then [=link parameters=] have no effect.
204-
205- Issue: Define a way for the linked resource to specify what link parameters they allow.
206- For cross-origin iframes/etc,
207- this will default to <em> nothing</em> ;
208- for same-origin (or cross-origin "SVG as image"),
209- it defaults to "everything".
210- If not allowed, the link parameter is ignored.
235+ then those [=link parameters=]
236+ establish global [=custom environment variables=] for the resource
237+ with their name and value,
238+ accessible with the ''env()'' function in stylesheets.
211239
212240<div class="example">
213241 For example, if an SVG image wanted to expose a ''--color'' parameter,
214242 it could use it like:
215243
216- <pre class="lang-markup" >
217- < svg>
218- < g style="fill: var (--color);">
219- < path d="..." />
220- < /g>
221- < /svg>
222- </pre >
244+ <xmp highlight=html >
245+ < svg>
246+ < g style="fill: env (--color);">
247+ < path d="..." />
248+ < /g>
249+ < /svg>
250+ </xmp >
223251</div>
224252
225253<div class="note">
226254 It's usually a good idea to make your SVG image usable even if no parameters are given,
227255 by providing "default values" for each of the custom properties.
228256 There are several ways to do this.
229257
230- 1. On each ''var()'' function, provide a fallback value, like ''fill: var(--color, blue)'' .
231- 2. If the custom property is going to be used a lot,
232- such that providing a fallback for each individual ''var()'' is troublesome,
233- store the <a>custom property</a> in a different name while invoking the default,
258+ 1. On each ''env()'' function, provide a fallback value, like ''fill: env(--color, blue)'' .
259+ 2. If the ''env()'' is going to be used a lot,
260+ such that providing a fallback for each individual ''env()'' is troublesome,
261+ store the [=custom environment variable=] in a [=scoped environment variable=]
262+ of a different name,
263+ with the default specified,
234264 like:
235265
236266 <pre class="lang-css">
237- :root {
238- --color2: var(--color, blue);
239- }
240- </pre>
241-
242- In this example, if ''--color'' is provided via an <a>SVG parameter</a> ,
243- ''--color2'' will receive its value.
244- If not, it will recieve the default ''blue'' value.
245- In either case, ''--color2'' can be used in the SVG image's stylesheet unconditionally,
246- secure in the knowledge that it will always have a value.
247- 3. In a future level of the Custom Properties specification [[CSS-VARIABLES]] ,
248- some "parent's value" functionality will be available to make the previous suggestion more usable:
267+ @env --color2: env(--color, blue);
249268
250- <pre class="lang-css">
269+ /* Alternately, store it in a custom property: */
251270 :root {
252- --color: var(parent --color, blue);
271+ --color: env( --color, blue);
253272 }
254273 </pre>
255274
256- (This is an example syntax, and is not yet final.)
257-
258- By invoking the value of the --color property on the parent
259- (which, on the root element, refers to the initial value) ,
260- an author can avoid self-reference loops while retaining the same <a>custom property</a> name .
275+ In this example, if ''--color'' is provided via a [=linked parameter=] ,
276+ ''env(--color2)'' will contain its value.
277+ If not, it will contain the default ''blue'' value.
278+ In either case, ''env(--color2)'' can be used in the stylesheet unconditionally ,
279+ secure in the knowledge that it will always have a value .
261280</div>
281+
282+ Note: When we define ''env(parent --color)'' to jump up a scope level,
283+ you won't need to do the rename;
284+ ''@env --color: env(parent --color);'' will work just fine.
0 commit comments