forked from w3c/csswg-drafts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOverview.bs
261 lines (213 loc) · 9.64 KB
/
Overview.bs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<pre class='metadata'>
Title: CSS Linked Parameters
Shortname: css-link-params
Level: 1
Status: ED
Group: CSSWG
Work Status: exploring
ED: https://drafts.csswg.org/css-link-params/
Editor: Tab Atkins-Bittner, Google, http://xanthir.com/contact/
Editor: Daniel Holbert, Mozilla
Editor: Jonathan Watt, Mozilla
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.
Ignored Terms: css value definition syntax
</pre>
<pre class="link-defaults">
spec:selectors-4; type:selector; text::hover
spec:html; type:element
text: iframe
text: a
spec:fill-stroke-3; type:property; text:fill
</pre>
Introduction {#intro}
=====================
SVG is stylable with CSS,
and when used inline in HTML,
this capability can be very useful.
For example, an SVG icon can take on a different color based on whether the user is hovering it or not,
just by applying a '':hover'' rule to it that changes the 'fill' property.
When the SVG is referenced in a way that doesn't allow selectors or CSS inheritance from the outer page to apply to it
(such as embedding it via <{img}> or <{iframe}> in HTML),
though, this functionality is lost.
The only way to change the display of such "external" SVG images
is to produce several of them,
and change which image you're referencing.
This incurs delay on the page as a new resource is downloaded,
and disallows dynamic effects like CSS Transitions.
<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,
either by a CSS property
or thru a special fragment scheme on the URL.
This gives a limited, but powerful, subset of the customizability that "inline" SVG images have
to "external" SVG images.
Setting a Link Parameter {#setting}
===================================
An external resource can be accompanied by a map of [=link parameters=],
each entry composed of a [=custom property name=] as a key,
and an <<any-value>> as the value.
There are three ways to specify a [=link parameter=]:
* via the 'link-parameters' property,
which applies to the resource itself
(if the element represents an external resource),
and to all external resources used in CSS properties on the element
* via a special syntax in the fragment portion of the URL of an external resource
* via a ''param()'' argument in the ''url()'' syntax
If specified in multiple of these ways,
all of the [=link parameters=] are combined.
If the same key appears in multiple inputs,
the latest source in the above list wins
(that is, URL fragment beats 'link-parameters',
and ''url("..." param())'' beats URL fragment).
The influence of [=link parameters=] on the linked resource
is defined in the next section.
In CSS: the 'link-parameters' property {#link-param-prop}
--------------------------------------
<pre class=propdef>
Name: link-parameters
Value: none | <<link-param>>+
Initial: none
Inherited: no
Applies to: all elements and pseudo-elements
Computed value: as specified
Animation type: discrete
</pre>
The 'link-parameters' property is one way to set [=link parameters=]
on the element itself
(if it is an element representing an external resource,
such as an HTML <{img}> or <{iframe}>),
and on all external CSS resources specified on the element
(such as background images, etc).
Its values are:
<dl dfn-type=value dfn-for=none>
: <dfn>none</dfn>
:: No [=link parameters=] specified.
: <dfn><<link-param>>+</dfn>
::
A list of one or more [=link parameters=].
If two [=link parameters=] with the same name are specified
with the same <<custom-property-name>>,
the last one wins.
</dl>
<pre class=prod>
<dfn><link-param></dfn> = param( <<custom-property-name>> <<declaration-value>>? )
</pre>
A <<link-param>> represents a [=link parameter=],
with a key of the <<custom-property-name>>.
If the <<declaration-value>> is specified,
that's the value of the [=link parameter=].
If omitted,
the value of the [=custom property=] of the same name on the element
is the value of the [=link parameter=].
In The URL {#url-frag}
----------
A special "fragment identifier" can be used in the <a for=url>fragment</a> of a URL
used to reference an external resource.
Several examples of existing "fragment identifiers" for SVG documents can be found in <a href="http://www.w3.org/TR/SVG/linking.html#LinksIntoSVG">the SVG 1.1 specification</a>.
The syntax of an <dfn export local-lt="param()">SVG parameter fragment identifier</dfn> is:
<pre class=prod>param( <<custom-property-name>> <<declaration-value>> )</pre>
(using the <a>CSS value definition syntax</a>; TODO define an actual parser for it).
<div class="example">
For example, to set the "--text-color" <a>custom property</a> of an SVG image to ''blue'',
one can reference the image with a url like “<code>http://example.com/image.svg#param(--text-color%20blue)</code>”.
</div>
If passing multiple parameters to an image,
additional <a>param()</a> functions must be appended to the URL.
If multiple <a>param()</a> functions specify the same <<custom-property-name>>,
the <a>custom property</a> is set to the value of the last one.
<div class="example">
For example, if the image from the previous example also used a "--bg-color" <a>custom property</a>,
it could be referenced with a url like “<code>http://example.com/image.svg#param(--text-color%20blue)param(--bg-color%20white)</code>”.
</div>
Note: Spaces, and some other characters that might be valid in CSS syntax,
are not technically valid in URLs.
In some contexts,
you might need to escape those characters to form a valid URL.
In most cases, though,
such as HTML's <{a}> element or CSS's ''url()'' function,
spaces are accepted and do not need to be escaped.
Setting via the CSS ''url()'' Function {#setting-url}
-----------------------------------------------------
When referencing an external resource via CSS,
the <a>param()</a> function can be used in the ''url()'' function.
But a common use-case is passing in values of the page's own <a>custom properties</a>;
for example, a page might use a ''--primary-color'' <a>custom property</a>,
and want to make an SVG image match.
There's no way, however, to integrate the value of a <a>custom property</a> in CSS into the URL passed to the ''url()'' function.
To accommodate this,
a <<link-param>> is a valid <<url-modifier>>.
As in the other methods of specifying [=link parameters=],
if the same <<custom-property-name>> is specified in several <<link-param>>s,
the last one wins.
<div class="example">
For example,
if the site is using a ''--primary-color'' custom property to theme its elements with,
and wanted an SVG background using a ''--color'' custom property to reflect it,
it could write:
<pre class='lang-css'>
.foo {
background-image: url("http://example.com/image.svg" param(--color var(--primary-color)));
}
</pre>
</div>
Using Link Parameters {#using}
=====================
When an external resource link has one or more [=link parameters=] specified,
if the linked resource understands CSS
(such as an SVG or HTML document),
then the initial value of custom properties
with names equal to the keys of the [=link parameters=] map
is set to the corresponding values of the map.
If an ''@property'' rule is specified for one of the custom property names
in the [=link parameters=],
the [=link parameter=] value is used for the initial value,
rather than the ''@property''-specified initial value.
If the linked resource does not understand CSS
(such as PNG images),
then [=link parameters=] have no effect.
Issue: Define a way for the linked resource to specify what link parameters they allow.
For cross-origin iframes/etc,
this will default to <em>nothing</em>;
for same-origin (or cross-origin "SVG as image"),
it defaults to "everything".
If not allowed, the link parameter is ignored.
<div class="example">
For example, if an SVG image wanted to expose a ''--color'' parameter,
it could use it like:
<pre class="lang-markup">
<svg>
<g style="fill: var(--color);">
<path d="..." />
</g>
</svg>
</pre>
</div>
<div class="note">
It's usually a good idea to make your SVG image usable even if no parameters are given,
by providing "default values" for each of the custom properties.
There are several ways to do this.
1. On each ''var()'' function, provide a fallback value, like ''fill: var(--color, blue)''.
2. If the custom property is going to be used a lot,
such that providing a fallback for each individual ''var()'' is troublesome,
store the <a>custom property</a> in a different name while invoking the default,
like:
<pre class="lang-css">
:root {
--color2: var(--color, blue);
}
</pre>
In this example, if ''--color'' is provided via an <a>SVG parameter</a>,
''--color2'' will receive its value.
If not, it will recieve the default ''blue'' value.
In either case, ''--color2'' can be used in the SVG image's stylesheet unconditionally,
secure in the knowledge that it will always have a value.
3. In a future level of the Custom Properties specification [[CSS-VARIABLES]],
some "parent's value" functionality will be available to make the previous suggestion more usable:
<pre class="lang-css">
:root {
--color: var(parent --color, blue);
}
</pre>
(This is an example syntax, and is not yet final.)
By invoking the value of the --color property on the parent
(which, on the root element, refers to the initial value),
an author can avoid self-reference loops while retaining the same <a>custom property</a> name.
</div>