Skip to content

Commit 0b27f7c

Browse files
authored
[css-navigation-1] Provide an initial definition of @route rules. (#13148)
This was discussed briefly in #12594 (comment) and this PR fills in a proposed definition of such a rule.
1 parent 7e4c10a commit 0b27f7c

File tree

1 file changed

+80
-7
lines changed

1 file changed

+80
-7
lines changed

css-navigation-1/Overview.bs

Lines changed: 80 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,77 @@ url: https://html.spec.whatwg.org/multipage/browsing-the-web.html#has-been-revea
3333
type: dfn; spec: html; text: has been revealed;
3434
</pre>
3535

36-
<h2 id="condional-navigation-queries">Conditional rules for navigation queries</h2>
36+
<h2 id="at-route">Declaring named URL patterns: the ''@route'' rule</h2>
37+
38+
The <dfn at-rule id="at-ruledef-route">@route</dfn> rule
39+
is an at-rule that associates a name with a [=URL pattern=].
40+
This name can be referenced in ''@navigation'' rules
41+
and in '':link-to()'' pseudo-classes.
42+
43+
The syntax of the ''@route'' rule is:
44+
45+
<pre class="prod def" nohighlight>
46+
@route <<dashed-ident>> {
47+
[ <<pattern-descriptors>> | <<init-descriptors>> ]
48+
}
49+
</pre>
50+
51+
based on the following definitions:
52+
53+
<pre class="prod def" dfn-type="type" nohighlight>
54+
<dfn><<pattern-descriptors>></dfn> = ;* <<pattern-descriptor>> ;*
55+
<dfn><<pattern-descriptor>></dfn> = pattern : <<url-pattern()>>
56+
<dfn><<init-descriptors>></dfn> = ;* <<init-descriptor>> [ ;+ <<init-descriptor>> ]* ;*
57+
<dfn><<init-descriptor>></dfn> = <<init-descriptor-name>> : <<string>>
58+
<dfn><<init-descriptor-name>></dfn> = protocol | username | password | hostname | port
59+
pathname | search | hash | baseURL
60+
</pre>
61+
62+
This associates an author-defined keyword with a URL pattern,
63+
so that any URL that matches one of the URL patterns
64+
matches the route named by the keyword.
65+
66+
The ''@route'' rule can be defined in one of two ways:
67+
68+
: with the <code>pattern</code> descriptor
69+
:: in this case the URL pattern represented is
70+
the one represented by the <<url-pattern()>> function
71+
given as the descriptor's value.
72+
: with the other descriptors named by <<init-descriptor-name>>
73+
:: In this case the URL pattern represented is the result of invoking
74+
[=URL pattern/create|create a URL pattern=] given
75+
<var>input</var> as {{URLPatternInit}}
76+
constructed from the descriptors and their values;
77+
if a <code>baseURL</code> descriptor is not given then one is created from
78+
the [=style resource base URL=] of the rule.
79+
80+
ISSUE: Should this use <<dashed-ident>>, <<custom-ident>>, or <<ident>>
81+
for the route names?
82+
83+
ISSUE: Is there value in being able to provide a list of <<url-pattern()>>
84+
rather than just one?
85+
86+
<div class="example">
87+
Either this rule:
88+
<pre highlight=css>
89+
@route --movie-list {
90+
pattern: url-pattern("/movie-list");
91+
}
92+
</pre>
93+
or this rule:
94+
<pre highlight=css>
95+
@route --movie-list {
96+
pathname: "/movie-list";
97+
}
98+
</pre>
99+
define an ''@route'' rule that associates
100+
the name <code>--movie-list</code>
101+
with the URL <code>"/movie-list"</code> resolved relative to the style sheet.
102+
</div>
103+
104+
NOTE: The bracing syntax also allows for future expansion if needed.
105+
106+
<h2 id="conditional-navigation-queries">Conditional rules for navigation queries</h2>
37107

38108
<h3 id="at-navigation">Navigation queries: the ''@navigation'' rule</h3>
39109

@@ -79,7 +149,8 @@ with <<navigation-condition>> defined as:
79149
<dfn><<navigation-in-parens>></dfn> = ( <<navigation-condition>> ) | ( <<navigation-test>> ) | <<general-enclosed>>
80150
<dfn><<navigation-test>></dfn> = <<navigation-location>> | <<navigation-keyword>> : <<navigation-location>>
81151
<dfn><<navigation-keyword>></dfn> = at | from | to
82-
<dfn><<navigation-location>></dfn> = <<url-pattern()>>
152+
<dfn><<navigation-location>></dfn> = <<route-name>> | <<url-pattern()>>
153+
<dfn><<route-name>></dfn> = <<dashed-ident>>
83154
</pre>
84155

85156
The above grammar is purposely very loose for forwards-compatibility reasons,
@@ -230,14 +301,15 @@ as follows:
230301
The <dfn>navigation location URL pattern</dfn> of a <<navigation-location>>
231302
depends on the type of <<navigation-location>>:
232303

304+
: <<route-name>>
305+
:: the URL pattern represented by the ''@route'' rule referenced by the name.
306+
233307
: <<url-pattern()>>
234308
:: The [=URL pattern=] represented by the function; see
235309
[=create a URL pattern for url-pattern()=].
236310

237-
ISSUE: There is currently only one type of <<navigation-location>>
238-
but we should consider adding another,
239-
which would be just a name that references
240-
a name defined in a routemap.
311+
ISSUE: Should it also be possible to reference
312+
a name defined in a routemap?
241313
See the
242314
<a href="https://github.com/WICG/declarative-partial-updates/blob/main/route-matching-explainer.md">route matching explainer</a>
243315
for details.
@@ -280,7 +352,8 @@ to model it after.
280352

281353
<h2 id="link-navigation-pseudo-classes">Pseudo-classes for navigation-related links</h2>
282354

283-
This specification defines a new '':link-to()'' functional pseudo-class
355+
This specification defines a new
356+
<dfn id="link-to-pseudo" selector>'':link-to()''</dfn> functional pseudo-class
284357
that matches link elements that link to a certain URL.
285358

286359
The '':link-to()'' pseudo-class takes a single argument, a <<link-condition>>,

0 commit comments

Comments
 (0)