Skip to content

Commit 634d784

Browse files
committed
[css-cascade-6] Refactor @scope section
1 parent 98917aa commit 634d784

File tree

1 file changed

+63
-61
lines changed

1 file changed

+63
-61
lines changed

css-cascade-6/Overview.bs

Lines changed: 63 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,12 @@ Layer Ordering</h4>
230230
██████ ██████ ███████ ██ ████ ██ ██ ██████
231231
-->
232232

233-
<h3 id='scoped-styles'>
234-
Scoped Styles</h3>
233+
<h3 id='scoped-styles' oldids="scope-atrule">
234+
Scoping Styles: the ''@scope'' rule</h3>
235235

236236
A <dfn>scope</dfn> is a subtree or fragment of a document,
237237
which can be used by selectors for more targeted matching.
238-
239-
A [=scope=] can be formed by determining:
238+
A [=scope=] is formed by determining:
240239

241240
* The [=scoping root=] [=node=],
242241
which acts as the upper bound of the scope,
@@ -245,17 +244,19 @@ Scoped Styles</h3>
245244
which act as the lower bounds.
246245

247246
An element is <dfn>in scope</dfn> if:
248-
249247
* It is an [=inclusive descendant=] of the [=scoping root=], and
250248
* It is not an [=inclusive descendant=] of a [=scoping limit=].
251249

252-
[=Scopes=] are described in CSS using the ''@scope'' rule.
253-
254250
Note: In contrast to [[CSS-SCOPING-1#shadow-dom|Shadow Encapsulation]],
255251
which describes a persistent one-to-one relationship in the DOM
256252
between a [=shadow host=] and its nested [=shadow tree=],
257253
multiple overlapping [=scopes=] can be defined in relation to the same elements.
258254

255+
Scoped styles are described in CSS using
256+
the <dfn>@scope</dfn> [=block at-rule=],
257+
which declares a [=scoping root=] and optional [=scoping limits=]
258+
associated with a set of [=style rules=].
259+
259260
<div class=example>
260261
For example,
261262
an author might have wide-reaching color-scheme scopes,
@@ -317,24 +318,22 @@ Scoped Styles</h3>
317318
</pre>
318319
</div>
319320

320-
<!--
321-
███████ ██████ ██████ ███████ ████████ ████████
322-
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
323-
██ ███ ██ ██ ██ ██ ██ ██ ██ ██
324-
██ ███ ██ ██████ ██ ██ ██ ████████ ██████
325-
██ █████ ██ ██ ██ ██ ██ ██
326-
██ ██ ██ ██ ██ ██ ██ ██ ██
327-
███████ ██████ ██████ ███████ ██ ████████
328-
-->
321+
<h4 id="scope-effects">
322+
Effects of ''@scope''</h4>
329323

330-
<h4 id='scope-atrule'>
331-
Scoping Styles: the ''@scope'' rule</h4>
332324

333-
The <dfn>@scope</dfn> [=block at-rule=]
334-
allows authors to scope style rules in CSS,
335-
with the application of [=weak scoping proximity=]
336-
between the [=scoping root=] and the [=subject=] of each style rule.
337-
<!-- This causes declarations [insert appropriate sentence from issue below]. -->
325+
The ''@scope'' [=at-rule=] has three primary effects
326+
on the [=style rules=] it contains:
327+
328+
* The [=style rules=] in an ''@scope'' <<stylesheet>>
329+
are [=scoped style rules=].
330+
331+
* The [=cascade=] prioritizes declarations
332+
with a [=scope proximity|more proximate=] [=scoping root=],
333+
regardless of specificity or source order
334+
by applying [=weak scoping proximity=]
335+
between the [=scoping root=] and the [=subject=] of each [=scoped style rule=].
336+
<!-- This causes declarations [insert appropriate sentence from issue below]. -->
338337

339338
Issue(6790): Should ''@scope'' use strong or weak scoping proximity?
340339
[=Strong scoping proximity=] causes declarations to be weighted more strongly
@@ -346,6 +345,13 @@ Scoping Styles: the ''@scope'' rule</h4>
346345
The Working Group currently leans towards weak proximity,
347346
and recommends that as a starting point for prototypes.
348347

348+
Note: Unlike <a href="https://www.w3.org/TR/css-nesting/">Nesting</a>,
349+
selectors within an ''@scope'' rule
350+
do not acquire the specificity of any parent selector(s) in the ''@scope'' prelude.
351+
352+
<h4 id="scope-syntax">
353+
Syntax of ''@scope''</h4>
354+
349355
The syntax of the ''@scope'' rule is:
350356

351357
<pre class="prod def">
@@ -356,51 +362,44 @@ Scoping Styles: the ''@scope'' rule</h4>
356362

357363
where:
358364

359-
<pre class="prod def">
360-
<dfn><<scope-start>></dfn> = <<forgiving-selector-list>>
361-
<dfn><<scope-end>></dfn> = <<forgiving-selector-list>>
362-
</pre>
363-
364-
A ''@scope'' rule which specifies a <<scope-start>>
365-
produces a number of <dfn>explicit scopes</dfn> as follows:
366-
367-
* For each element matched by <<scope-start>>,
368-
create a [=scope=] using that element as the [=scoping root=].
369-
* For each [=scope=] created by the above:
370-
* Collect all elements that are [=in scope=]
371-
and that match <<scope-end>>,
372-
using the [=scoping root=] as the '':scope'' element, then
373-
* Set those elements as the [=scoping limits=].
365+
* <dfn><<scope-start>></dfn> is a <<forgiving-selector-list>> [=selector=]
366+
used to identify the [=scoping root=](s).
367+
* <dfn><<scope-end>></dfn> is a <<forgiving-selector-list>> [=selector=]
368+
used to identify any [=scoping limits=].
369+
* the <<stylesheet>> represents the [=scoped style rules=].
374370

375371
[=Pseudo-elements=] cannot be [=scoping roots=] or [=scoping limits=];
376372
they are invalid both within <<scope-start>> and <<scope-end>>.
377373

378-
A ''@scope'' rule which does not specify a <<scope-start>>
379-
produces a single <dfn>implicit scope</dfn> as follows:
374+
<h4 id="scoped-rules">
375+
Scoped Style Rules</h4>
380376

381-
* The [=scoping root=] is the [=parent element=] of the [=owner node=]
382-
of the stylesheet where the ''@scope'' rule is defined.
383-
If no such element exist,
384-
then the [=scoping root=] is the [=root=] of the containing [=node tree=].
385-
* Collect all elements that are [=in scope=]
386-
and that match <<scope-end>>,
387-
using the [=scoping root=] as the '':scope'' element, then
388-
* Set those elements as the [=scoping limits=].
377+
<dfn>Scoped style rules</dfn> differ from non-scoped rules
378+
in the following ways:
389379

390-
The ''@scope'' [=at-rule=] has three primary effects
391-
on the [=style rules=] in its <<stylesheet>>:
380+
* Their selectors can only match elements that are [=in scope=].
381+
(This only applies to the [=subject=];
382+
the rest of the selector can match unrestricted.)
392383

393-
* Selectors can only match elements that are [=in scope=].
394-
This only applies to the [=subject=];
395-
the rest of the selector can match unrestricted.
384+
<h4 id="scope-limits">
385+
Identifying Scoping Roots and Limits</h4>
396386

397-
* The [=cascade=] prioritizes declarations
398-
with a [=scope proximity|more proximate=] [=scoping root=],
399-
regardless of specificity or source order.
387+
A ''@scope'' rule produces one or more [=scopes=] as follows:
388+
389+
: Finding the [=scoping root=](s)
390+
:: For each element matched by <<scope-start>>,
391+
create a [=scope=] using that element as the [=scoping root=].
392+
If no <<scope-start>> is specified,
393+
the [=scoping root=] is the [=parent element=] of the [=owner node=]
394+
of the stylesheet where the ''@scope'' rule is defined.
395+
(If no such element exists,
396+
then the [=scoping root=] is the [=root=] of the containing [=node tree=].)
400397

401-
Note: Unlike <a href="https://www.w3.org/TR/css-nesting/">Nesting</a>,
402-
selectors within an ''@scope'' rule
403-
do not acquire the specificity of any parent selector(s) in the ''@scope'' prelude.
398+
: Finding any [=scoping limits=]
399+
:: For each [=scope=] created by a [=scoping root=],
400+
its [=scoping limits=] are set to all elements
401+
that are [=in scope=] and that match <<scope-end>>,
402+
using the [=scoping root=] as the '':scope'' element.
404403

405404
<div class=example>
406405
The following selectors have the same specificity (0,0,1):
@@ -503,14 +502,17 @@ do not acquire the specificity of any parent selector(s) in the ''@scope'' prelu
503502
</pre>
504503
</div>
505504

505+
<h4 id="scope-scope">
506+
Scope Nesting</h4>
507+
506508
''@scope'' rules can be nested.
507509
In this case, just as with the nested style rules,
508510
the selectors of the inner ''@scope''
509511
(including those defining its [=scope=])
510512
are [=scoped selectors|scoped by=]
511513
the selectors of the outer one.
512514

513-
Global, name-defining [=at-rules=]
515+
Global name-defining [=at-rules=]
514516
such as ''@keyframes'' or ''@font-face'' or ''@layer''
515517
that are defined inside ''@scope'' are valid,
516518
but are not scoped or otherwise affected
@@ -643,7 +645,7 @@ Changes since the 21 December 2021 First Public Working Draft</h3>
643645

644646
* Added the {{CSSScopeRule}} interface.
645647

646-
* Added [=implicit scopes=].
648+
* Added implicit scopes by making ''<<scope-start>>'' optional.
647649
(<a href="https://github.com/w3c/csswg-drafts/issues/6606">Issue 6606</a>)
648650

649651
* Disallowed [=pseudo-elements=] in the ''@scope'' prelude.

0 commit comments

Comments
 (0)