forked from w3c/csswg-drafts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverview.bs
More file actions
307 lines (242 loc) · 11.5 KB
/
Copy pathOverview.bs
File metadata and controls
307 lines (242 loc) · 11.5 KB
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
<pre class="metadata">
Title: CSS Route Matching
Status: ED
Work Status: Exploring
Shortname: css-navigation
Level: 1
Group: csswg
ED: https://drafts.csswg.org/css-navigation-1/
!Issue Tracking: <a href="https://github.com/w3c/csswg-drafts/issues/12594">w3c/csswg-drafts#12594</a>
Editor: L. David Baron, Google https://www.google.com/, https://dbaron.org/, w3cid 15393
Editor: Noam Rosenthal, Google https://www.google.com/, w3cid 121539
Abstract: This module contains conditional CSS rules for styling conditioned on the current URL
or conditioned on the status of navigating between particular URLs.
</pre>
<pre class="link-defaults">
spec:css-values-5; type:function; text:if()
</pre>
<!-- FIXME: TEMPORARILY override non-exported definition -->
<pre class=anchors>
url: https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigationtransition-from
type: dfn; spec: html; text: from entry;
url: https://html.spec.whatwg.org/multipage/nav-history-apis.html#window-navigation-api
type: dfn; spec: html; text: navigation API;
url: https://html.spec.whatwg.org/multipage/nav-history-apis.html#ongoing-navigate-event
type: dfn; spec: html; text: ongoing navigate event;
url: https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-navigation-transition
type: dfn; spec: html; text: transition;
url: https://html.spec.whatwg.org/multipage/nav-history-apis.html#navigation-activation
type: dfn; spec: html; text: activation;
url: https://html.spec.whatwg.org/multipage/browsing-the-web.html#has-been-revealed
type: dfn; spec: html; text: has been revealed;
</pre>
<h2 id="condional-navigation-queries">Conditional rules for navigation queries</h2>
<h3 id="at-navigation">Navigation queries: the ''@navigation'' rule</h3>
The <dfn at-rule id="at-ruledef-navigation">@navigation</dfn> rule
is a conditional group rule
whose condition tests
characteristics of the current URL
or of the state of navigation between two URLs.
These queries are called <dfn export>navigation queries</dfn>.
Authors can use it to:
* write style sheets that apply to multiple pages
but behave somewhat differently between those pages,
* write style sheets that apply to
single page applications
that change their URL over time,
so that style changes when the URL changes, and
* write style sheets that declaratively start view transitions
(or make other appropriate style changes)
in response to navigations.
The syntax of the condition in the ''@navigation'' rule
is similar to that defined for
<<supports-condition>> in [[CSS-CONDITIONAL-3]].
Negation, conjunction, and disjunction are all needed
so that authors can specify the interaction of multiple styles
in ways that are most intuitive and require the simplest code.
The syntax of the ''@navigation'' rule is:
<pre class="prod def" nohighlight>
@navigation <<navigation-condition>> {
<<rule-list>>
}
</pre>
with <<navigation-condition>> defined as:
<pre class="prod def" dfn-type="type" nohighlight>
<dfn><<navigation-condition>></dfn> = not <<navigation-in-parens>>
| <<navigation-in-parens>> [ and <<navigation-in-parens>> ]*
| <<navigation-in-parens>> [ or <<navigation-in-parens>> ]*
<dfn><<navigation-in-parens>></dfn> = ( <<navigation-condition>> ) | ( <<navigation-test>> ) | <<general-enclosed>>
<dfn><<navigation-test>></dfn> = <<navigation-location>> | <<navigation-keyword>> : <<navigation-location>>
<dfn><<navigation-keyword>></dfn> = at | from | to
<dfn><<navigation-location>></dfn> = <<urlpattern()>>
</pre>
The above grammar is purposely very loose for forwards-compatibility reasons,
since the <<general-enclosed>> production
allows for substantial future extensibility.
Any ''@navigation'' rule that does not parse according to the grammar above
(that is, a rule that does not match this loose grammar
which includes the <<general-enclosed>> production)
is invalid.
Style sheets <strong>must not</strong> use such a rule and
processors <strong>must</strong> ignore such a rule (including all of its contents).
Many of these grammar terms are associated with a boolean result,
as follows:
: <<navigation-condition>>
:: : not <<navigation-in-parens>>
:: The result is the negation of the <<navigation-in-parens>> term.
: <<navigation-in-parens>> [ and <<navigation-in-parens>> ]*
::
The result is true if all of the <<navigation-in-parens>> child terms are true,
and false otherwise.
: <<navigation-in-parens>> [ or <<navigation-in-parens>> ]*
::
The result is false if all of the <<navigation-in-parens>> child terms are false,
and true otherwise.
: <<navigation-in-parens>>
:: The result is the result of the child subexpression.
: <<navigation-test>>
:: : <<navigation-location>>
: at: <<navigation-location>>
:: The result is true if
the document's [=Document/URL=] [=URL pattern/match|matches=]
the [=navigation location URL pattern=] of <<navigation-location>>.
: from: <<navigation-location>>
:: The result is true if
the [=document's navigation API=] of the document
is non-null, and either:
* its [=transition=] is non-null,
its [=from entry=]'s {{NavigationHistoryEntry/url}}
is non-null and
[=URL pattern/match|matches=]
the [=navigation location URL pattern=] of <<navigation-location>>.
* its [=activation=] is non-null,
the document's [=has been revealed=] is false or
was false at the start of the current [=task=],
and the activation's {{NavigationActivation/from}}'s
{{NavigationHistoryEntry/url}}'s
is non-null and
[=URL pattern/match|matches=]
the [=navigation location URL pattern=] of <<navigation-location>>.
: to: <<navigation-location>>
:: The result is true if
the [=document's navigation API=] of the document
is non-null, and either:
* its [=ongoing navigate event=] is non-null,
and its {{NavigateEvent/destination}}'s
{{NavigationDestination/url}}
[=URL pattern/match|matches=]
the [=navigation location URL pattern=] of <<navigation-location>>.
ISSUE: This assumes that the [=ongoing navigate event=]
and the [=transition=] have the same lifetime,
but this isn't really
true if the event is intercepted.
After
<a href="https://github.com/whatwg/html/issues/11690">whatwg/html#11690</a> /
<a href="https://github.com/whatwg/html/pull/11692">whatwg/html#11692</a>.
we could probably define this more like "from" above.
But which lifetime is the one we want?
* its [=activation=] is non-null,
the document's [=has been revealed=] is false or
was false at the start of the current [=task=],
and the activation's {{NavigationActivation/entry}}'s
{{NavigationHistoryEntry/url}}'s
is non-null and
[=URL pattern/match|matches=]
the [=navigation location URL pattern=] of <<navigation-location>>.
TODO: Update this definition to handle redirects better.
In particular, we'd like the ''to:'' URL to change
at only a single time,
from the original URL of the navigation to the final one.
There is already a well-defined definition and processing model
that we can depend on.
ISSUE: The above definitions of from and to apparently don't work right
if you start a same-document navigation (e.g., with {{History/pushState}})
in the middle of a cross-document navigation.
ISSUE: Improve integration with [=has been revealed=] rather than monkeypatching it.
: <<general-enclosed>>
::
The result is false.
Authors must not use <<general-enclosed>> in their stylesheets.
<span class='note'>It exists only for future-compatibility,
so that new syntax additions do not invalidate too much of a <<navigation-condition>> in older user agents.</span>
The <dfn>navigation location URL pattern</dfn> of a <<navigation-location>>
depends on the type of <<navigation-location>>:
: <<urlpattern()>>
:: The [=URL pattern=] represented by the function; see
[=create a URL pattern for urlpattern()=].
ISSUE: There is currently only one type of <<navigation-location>>
but we should consider adding another,
which would be just a name that references
a name defined in a routemap.
See the
<a href="https://github.com/WICG/declarative-partial-updates/blob/main/route-matching-explainer.md">route matching explainer</a>
for details.
A <dfn>document's navigation API</dfn> is
the result of the following steps on <var>document</var>:
1. Let <var>window</var> be the {{Window}} whose [=associated Document=] is <var>document</var>, or null if there is no such {{Window}}.
1. If <var>window</var> is null, return null.
1. Return <var>window</var>'s [=navigation API=].
The condition of the ''@navigation'' rule
is the result of the <<navigation-condition>> in its prelude.
<h3 id="navigation-when-function">The ''@when/navigation()'' function for ''@when''</h3>
This specification defines an additional function for the ''@when'' rule:
<pre class="prod">
<dfn for="@when" function>navigation()</dfn> = navigation( <<navigation-condition>> )
</pre>
The ''@when/navigation()'' function is associated with the boolean result that
its contained condition is associated with.
<h3 id="navigation-if-function">The ''if()/navigation()'' function for ''if()''</h3>
This specification defines an additional function for the ''if()'' function's
<<if-test>> production:
<pre class="prod">
<dfn for="if()" function>navigation()</dfn> = navigation( <<navigation-condition>> )
</pre>
ISSUE: This should probably have a more formal definition of the function,
but I can't find the formal definitions of the existing ''if()'' functions
to model it after.
<h2 id="link-navigation-pseudo-classes">Pseudo-classes for navigation-related links</h2>
TODO: To be written.
<h2 id="urlpattern-function">The ''urlpattern()'' function</h2>
<!--
NOTE: We may eventually want to move this to css-values.
If we do, the definition of "style resource base URL" probably doesn't need to be
exported any more, since it was exported for this definition.
-->
The <dfn export function>urlpattern()</dfn> function represents a [=URL pattern=],
which can be used to match URLs.
<pre class="prod def">
<<urlpattern()>> = urlpattern( <<string>> )
</pre>
This function represents a [=URL pattern=] that can be created
using the steps of the <dfn>create a URL pattern for urlpattern()</dfn> algorithm:
1. Let <var>arg</var> be the <<string>> argument to the ''urlpattern()'' function.
1. Let <var>baseURL</var> be the [=style resource base URL=] of
the rule or declaration block containing the ''urlpattern()'' function.
<div class="issue">
Do we want this to be the base URL all the time?
For use of ''urlpattern()'' in ''@navigation'',
it's likely more useful for the base URL
to be the document URL rather than the style sheet URL.
However, it would be very awkward for ''urlpattern()''
to be inconsistent with ''url()''.
Should we allow the base URL of ''urlpattern()''
to be defined by the consumer?
Should we introduce <code>document-urlpattern()</code>?
Should we do something similar to
[[css-images-3#ambiguous-urls]]
(see <w3c/csswg-drafts#383>)?
Also see other proposed uses of {{URLPattern}} in CSS
in <w3c/csswg-drafts#10975>,
for '':local-link''.
</div>
1. Return the result of [=URL pattern/create|create a URL pattern=] given
<var>arg</var>, <var>baseURL</var>, and an empty [=map=].
NOTE: This function requires that its argument is quoted.
This differs from the ''url()'' function,
which allows its argument to be quoted or unquoted.
To <dfn export>serialize a ''urlpattern()'' function</dfn> <var>f</var>,
[=serialize a function=] <var>f</var>,
using [=serialize a string=] on the single argument
to serialize <var>f</var>'s contents.
NOTE: This is defined this way because {{URLPattern}}
intentionally does not provide a serialization.