forked from w3c/csswg-drafts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
709 lines (695 loc) · 50.3 KB
/
index.html
File metadata and controls
709 lines (695 loc) · 50.3 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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
<!doctype html><html lang="en">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>CSS Shadow Parts</title>
<meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
<meta content="exploring" name="csswg-work-status">
<meta content="UD" name="w3c-status">
<meta content="This specification defines the ''::part()'' and ''::theme()'' pseudo-elements on <a>shadow hosts</a>, allowing <a>shadow hosts</a> to selectively expose chosen elements from their <a>shadow tree</a> to the outside page for styling purposes." name="abstract">
<link href="../default.css" rel="stylesheet" type="text/css">
<link href="../csslogo.ico" rel="shortcut icon" type="image/x-icon">
<link href="https://www.w3.org/StyleSheets/TR/2016/W3C-UD" rel="stylesheet" type="text/css">
<meta content="Bikeshed version 9c1249d37b3e5652ab96972094dc9dd58b208f69" name="generator">
<style>/* style-md-lists */
/* This is a weird hack for me not yet following the commonmark spec
regarding paragraph and lists. */
[data-md] > :first-child {
margin-top: 0;
}
[data-md] > :last-child {
margin-bottom: 0;
}</style>
<style>/* style-counters */
body {
counter-reset: example figure issue;
}
.issue {
counter-increment: issue;
}
.issue:not(.no-marker)::before {
content: "Issue " counter(issue);
}
.example {
counter-increment: example;
}
.example:not(.no-marker)::before {
content: "Example " counter(example);
}
.invalid.example:not(.no-marker)::before,
.illegal.example:not(.no-marker)::before {
content: "Invalid Example" counter(example);
}
figcaption {
counter-increment: figure;
}
figcaption:not(.no-marker)::before {
content: "Figure " counter(figure) " ";
}</style>
<style>/* style-dfn-panel */
.dfn-panel {
position: absolute;
z-index: 35;
height: auto;
width: -webkit-fit-content;
width: fit-content;
max-width: 300px;
max-height: 500px;
overflow: auto;
padding: 0.5em 0.75em;
font: small Helvetica Neue, sans-serif, Droid Sans Fallback;
background: #DDDDDD;
color: black;
border: outset 0.2em;
}
.dfn-panel:not(.on) { display: none; }
.dfn-panel * { margin: 0; padding: 0; text-indent: 0; }
.dfn-panel > b { display: block; }
.dfn-panel a { color: black; }
.dfn-panel a:not(:hover) { text-decoration: none !important; border-bottom: none !important; }
.dfn-panel > b + b { margin-top: 0.25em; }
.dfn-panel ul { padding: 0; }
.dfn-panel li { list-style: inside; }
.dfn-panel.activated {
display: inline-block;
position: fixed;
left: .5em;
bottom: 2em;
margin: 0 auto;
max-width: calc(100vw - 1.5em - .4em - .5em);
max-height: 30vh;
}
.dfn-paneled { cursor: pointer; }
</style>
<style>/* style-selflinks */
.heading, .issue, .note, .example, li, dt {
position: relative;
}
a.self-link {
position: absolute;
top: 0;
left: calc(-1 * (3.5rem - 26px));
width: calc(3.5rem - 26px);
height: 2em;
text-align: center;
border: none;
transition: opacity .2s;
opacity: .5;
}
a.self-link:hover {
opacity: 1;
}
.heading > a.self-link {
font-size: 83%;
}
li > a.self-link {
left: calc(-1 * (3.5rem - 26px) - 2em);
}
dfn > a.self-link {
top: auto;
left: auto;
opacity: 0;
width: 1.5em;
height: 1.5em;
background: gray;
color: white;
font-style: normal;
transition: opacity .2s, background-color .2s, color .2s;
}
dfn:hover > a.self-link {
opacity: 1;
}
dfn > a.self-link:hover {
color: black;
}
a.self-link::before { content: "¶"; }
.heading > a.self-link::before { content: "§"; }
dfn > a.self-link::before { content: "#"; }</style>
<style>/* style-autolinks */
.css.css, .property.property, .descriptor.descriptor {
color: #005a9c;
font-size: inherit;
font-family: inherit;
}
.css::before, .property::before, .descriptor::before {
content: "‘";
}
.css::after, .property::after, .descriptor::after {
content: "’";
}
.property, .descriptor {
/* Don't wrap property and descriptor names */
white-space: nowrap;
}
.type { /* CSS value <type> */
font-style: italic;
}
pre .property::before, pre .property::after {
content: "";
}
[data-link-type="property"]::before,
[data-link-type="propdesc"]::before,
[data-link-type="descriptor"]::before,
[data-link-type="value"]::before,
[data-link-type="function"]::before,
[data-link-type="at-rule"]::before,
[data-link-type="selector"]::before,
[data-link-type="maybe"]::before {
content: "‘";
}
[data-link-type="property"]::after,
[data-link-type="propdesc"]::after,
[data-link-type="descriptor"]::after,
[data-link-type="value"]::after,
[data-link-type="function"]::after,
[data-link-type="at-rule"]::after,
[data-link-type="selector"]::after,
[data-link-type="maybe"]::after {
content: "’";
}
[data-link-type].production::before,
[data-link-type].production::after,
.prod [data-link-type]::before,
.prod [data-link-type]::after {
content: "";
}
[data-link-type=element],
[data-link-type=element-attr] {
font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace;
font-size: .9em;
}
[data-link-type=element]::before { content: "<" }
[data-link-type=element]::after { content: ">" }
[data-link-type=biblio] {
white-space: pre;
}</style>
<body class="h-entry">
<div class="head">
<p data-fill-with="logo"><a class="logo" href="http://www.w3.org/"> <img alt="W3C" height="48" src="https://www.w3.org/StyleSheets/TR/2016/logos/W3C" width="72"> </a> </p>
<h1 class="p-name no-ref" id="title">CSS Shadow Parts</h1>
<h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Unofficial Proposal Draft, <time class="dt-updated" datetime="2017-01-20">20 January 2017</time></span></h2>
<div data-fill-with="spec-metadata">
<dl>
<dt>This version:
<dd><a class="u-url" href="http://tabatkins.github.io/specs/css-shadow-parts/">http://tabatkins.github.io/specs/css-shadow-parts/</a>
<dt>Issue Tracking:
<dd><a href="#issues-index">Inline In Spec</a>
<dd><span><a href="https://github.com/w3c/csswg-drafts/labels/css-shadow-parts-1">GitHub Issues</a></span>
<dt class="editor">Editor:
<dd class="editor p-author h-card vcard"><a class="p-name fn u-url url" href="http://xanthir.com/contact/">Tab Atkins-Bittner</a> (<span class="p-org org">Google</span>)
</dl>
</div>
<div data-fill-with="warning">
<details class="annoying-warning" open="">
<summary>Not Ready For Implementation</summary>
<p> This spec is not yet ready for implementation.
It exists in this repository to record the ideas and promote discussion. </p>
<p> Before attempting to implement this spec,
please contact the CSSWG at www-style@w3.org. </p>
</details>
</div>
<p class="copyright" data-fill-with="copyright"><a href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> © 2017 <a href="http://www.w3.org/"><abbr title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a href="http://www.csail.mit.edu/"><abbr title="Massachusetts Institute of Technology">MIT</abbr></a>, <a href="http://www.ercim.eu/"><abbr title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>, <a href="http://www.keio.ac.jp/">Keio</a>, <a href="http://ev.buaa.edu.cn/">Beihang</a>). W3C <a href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>, <a href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and <a href="http://www.w3.org/Consortium/Legal/copyright-documents">document use</a> rules apply. </p>
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc no-ref heading settled" id="abstract"><span class="content">Abstract</span></h2>
<div class="p-summary" data-fill-with="abstract">
<p>This specification defines the <a class="css" data-link-type="maybe" href="#selectordef-part">::part()</a> and <a class="css" data-link-type="maybe" href="#selectordef-theme">::theme()</a> pseudo-elements on <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#element-shadow-host">shadow hosts</a>, allowing <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#element-shadow-host">shadow hosts</a> to selectively expose chosen elements from their <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#concept-shadow-tree">shadow tree</a> to the outside page for styling purposes.</p>
<a href="http://www.w3.org/TR/CSS/">CSS</a> is a language for describing the rendering of structured documents
(such as HTML and XML)
on screen, on paper, in speech, etc.
</div>
<h2 class="no-num no-toc no-ref heading settled" id="status"><span class="content">Status of this document</span></h2>
<div data-fill-with="status">
<p></p>
</div>
<div data-fill-with="at-risk"></div>
<nav data-fill-with="table-of-contents" id="toc">
<h2 class="no-num no-toc no-ref" id="contents">Table of Contents</h2>
<ol class="toc" role="directory">
<li>
<a href="#intro"><span class="secno">1</span> <span class="content">Introduction</span></a>
<ol class="toc">
<li><a href="#motivation"><span class="secno">1.1</span> <span class="content">Motivation</span></a>
</ol>
<li><a href="#part-attr"><span class="secno">2</span> <span class="content">Exposing a Shadow Element: the <code><span>part</span></code> attribute</span></a>
<li><a href="#part-theme"><span class="secno">3</span> <span class="content">Selecting a Shadow Element: the <span class="css">::part()</span> and <span class="css">::theme()</span> pseudo-elements</span></a>
<li>
<a href="#conformance"><span class="secno"></span> <span class="content"> Conformance</span></a>
<ol class="toc">
<li><a href="#document-conventions"><span class="secno"></span> <span class="content"> Document conventions</span></a>
<li><a href="#conform-classes"><span class="secno"></span> <span class="content"> Conformance classes</span></a>
<li>
<a href="#conform-responsible"><span class="secno"></span> <span class="content"> Requirements for Responsible Implementation of CSS</span></a>
<ol class="toc">
<li><a href="#conform-partial"><span class="secno"></span> <span class="content"> Partial Implementations</span></a>
<li><a href="#conform-future-proofing"><span class="secno"></span> <span class="content"> Implementations of Unstable and Proprietary Features</span></a>
<li><a href="#conform-testing"><span class="secno"></span> <span class="content"> Implementations of CR-level Features</span></a>
</ol>
</ol>
<li>
<a href="#index"><span class="secno"></span> <span class="content">Index</span></a>
<ol class="toc">
<li><a href="#index-defined-here"><span class="secno"></span> <span class="content">Terms defined by this specification</span></a>
<li><a href="#index-defined-elsewhere"><span class="secno"></span> <span class="content">Terms defined by reference</span></a>
</ol>
<li>
<a href="#references"><span class="secno"></span> <span class="content">References</span></a>
<ol class="toc">
<li><a href="#normative"><span class="secno"></span> <span class="content">Normative References</span></a>
</ol>
<li><a href="#issues-index"><span class="secno"></span> <span class="content">Issues Index</span></a>
</ol>
</nav>
<main>
<h2 class="heading settled" data-level="1" id="intro"><span class="secno">1. </span><span class="content">Introduction</span><a class="self-link" href="#intro"></a></h2>
<p class="issue" id="issue-0b399633"><a class="self-link" href="#issue-0b399633"></a> This spec is intentionally a rough sketch at the moment.
It should contain all the details necessary to evaluate the proposal,
but is intentionally avoiding precise algorithms at the moment,
to aid in easy comprehension
and to, hopefully, discourage implementation from this sketch.</p>
<p>Shadow DOM allows authors to separate their page into "components",
subtrees of markup whose details are only relevant to the component itself,
not the outside page.
This reduces the chance of a style meant for one part of the page
accidentally over-applying and making a different part of the page look wrong.
However, this styling barrier also makes it harder for a page to interact with its components
when it actually <em>wants</em> to do so.</p>
<p>This specification defines the <a class="css" data-link-type="maybe" href="#selectordef-part" id="ref-for-selectordef-part-1">::part()</a> and <a class="css" data-link-type="maybe" href="#selectordef-theme" id="ref-for-selectordef-theme-1">::theme()</a> pseudo-elements,
which allow an author to style specific, purposely exposed elements in a <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#concept-shadow-tree">shadow tree</a> from the outside page’s context.
In combination with <a data-link-type="dfn" href="https://drafts.csswg.org/css-variables-1/#custom-property">custom properties</a>,
which let the outside page pass particular values
(such as theme colors)
into the component for it to do with as it will,
these pseudo-elements allow components and the outside page
to interact in safe, powerful ways,
maintaining encapsulation
without surrending all control.</p>
<h3 class="heading settled" data-level="1.1" id="motivation"><span class="secno">1.1. </span><span class="content">Motivation</span><a class="self-link" href="#motivation"></a></h3>
<p>For obvious reasons,
it’s valuable to let the outside page style the internals of a shadow tree,
at least in some limited ways.
(The ubiquity of UA-specific pseudo-elements for the various input elements shows this.)</p>
<p>The previous proposed method for doing so,
the >>> combinator,
turned out to be <em>too powerful</em> for its own good;
it exposed too much of a component’s internal structure to scrutiny,
defeating some of the encapsulation benefits that using Shadow DOM brings.
For this,
and other performance-related reasons,
the >>> combinator was eventually removed from the <a data-link-type="dfn" href="https://drafts.csswg.org/selectors-4/#dynamic-profile">dynamic profile</a>.</p>
<p>This left us with using <a data-link-type="dfn" href="https://drafts.csswg.org/css-variables-1/#custom-property">custom properties</a> as the only way to style into a shadow tree:
the component would advertise that it uses certain <a data-link-type="dfn" href="https://drafts.csswg.org/css-variables-1/#custom-property">custom properties</a> to style its internals,
and the outer page could then set those properties as it wished on the <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#element-shadow-host">shadow host</a>,
letting inheritance push the values down to where they were needed.
This works very well for many simple theming use-cases.</p>
<p>However, there are some cases where this falls down.
If a component wishes to allow arbitrary styling of something in its shadow tree,
the only way to do so is to define hundreds of <a data-link-type="dfn" href="https://drafts.csswg.org/css-variables-1/#custom-property">custom properties</a> (one per CSS property they wish to allow control of),
which is obviously ridiculous
for both usability and performance reasons.
The situation is compounded if authors wish to style the component differently
based on pseudo-classes like <a class="css" data-link-type="maybe" href="https://drafts.csswg.org/selectors-4/#hover-pseudo">:hover</a>;
the component needs to duplicate the <a data-link-type="dfn" href="https://drafts.csswg.org/css-variables-1/#custom-property">custom properties</a> used
for each pseudo-class
(and each combination,
like <span class="css">:hover:focus</span>,
resulting in a combinatorial explosion).
This makes the usability and performance problems even worse.</p>
<p>We introduce <a class="css" data-link-type="maybe" href="#selectordef-part" id="ref-for-selectordef-part-2">::part()</a> to handle this case much more elegantly and performantly.
Rather than bundling everything into <a data-link-type="dfn" href="https://drafts.csswg.org/css-variables-1/#custom-property">custom property</a> names,
the functionality lives in selectors and style rule syntax,
like it’s meant to.
This is far more usable for both component authors
and component users,
should have much better performance,
and allows for better encapsulation/API surface.</p>
<p>Another interesting facet of using <a data-link-type="dfn" href="https://drafts.csswg.org/css-variables-1/#custom-property">custom properties</a>,
however,
is that inheritance doesn’t stop at the first shadow tree.
Unless explicitly blocked,
a <a data-link-type="dfn" href="https://drafts.csswg.org/css-variables-1/#custom-property">custom property</a> inherits down thru nested trees,
allowing authors to style deeply nested components
as easily as they style directly-visible ones.
The same considerations apply to this case,
so we introduce <a class="css" data-link-type="maybe" href="#selectordef-theme" id="ref-for-selectordef-theme-2">::theme()</a> to handle this.</p>
<p>It’s important to note that <a class="css" data-link-type="maybe" href="#selectordef-part" id="ref-for-selectordef-part-3">::part()</a> and <a class="css" data-link-type="maybe" href="#selectordef-theme" id="ref-for-selectordef-theme-3">::theme()</a> offer <em>absolutely zero new theoretical power</em>.
They are not a rehash of the <a class="css" data-link-type="maybe" href="https://drafts.csswg.org/css-scoping-1/#selectordef-shadow-piercing-descendant-combinator">>>></a> combinator,
they’re simply a more convenient and consistent syntax
for something authors can already do with <a data-link-type="dfn" href="https://drafts.csswg.org/css-variables-1/#custom-property">custom properties</a>.
By separating out the explicitly "published" parts of an element
(the <a data-link-type="dfn" href="#shadow-root-shadow-part-map" id="ref-for-shadow-root-shadow-part-map-1">shadow part map</a> from the sub-parts that it merely happens to contain
(the <a data-link-type="dfn" href="#shadow-root-shadow-theme-map" id="ref-for-shadow-root-shadow-theme-map-1">shadow theme map</a>,
it also helps with encapsulation,
as authors can use <a class="css" data-link-type="maybe" href="#selectordef-part" id="ref-for-selectordef-part-4">::part()</a> without fear of accidental over-styling.</p>
<h2 class="heading settled" data-level="2" id="part-attr"><span class="secno">2. </span><span class="content">Exposing a Shadow Element: the <code><a data-link-type="element-sub" href="#element-attrdef-html-global-part" id="ref-for-element-attrdef-html-global-part-1">part</a></code> attribute</span><a class="self-link" href="#part-attr"></a></h2>
<p>Any element in a shadow tree can have a <dfn class="dfn-paneled" data-dfn-for="html-global" data-dfn-type="element-attr" data-export="" id="element-attrdef-html-global-part">part</dfn> attribute.
This is used to expose the element outside the <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#concept-shadow-tree">shadow tree</a>,
and to "forward" sub-parts of the element
(if it has its own <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#concept-shadow-tree">shadow tree</a>)
to outside the <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#concept-shadow-tree">shadow tree</a>.</p>
<p>The part attribute is parsed as a comma-separated list of part mappings.
Each part mapping is one of:</p>
<dl class="switch">
<dt data-md="">
<p><code>ident</code></p>
<dd data-md="">
<p>Adds «[ ident → el ]» to the <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#concept-shadow-root">shadow root’s</a> <a data-link-type="dfn" href="#shadow-root-shadow-part-map" id="ref-for-shadow-root-shadow-part-map-2">shadow part map</a>.</p>
<dt data-md="">
<p><code>ident1 => ident2</code></p>
<dd data-md="">
<p>If el is a <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#element-shadow-host">shadow host</a>,
and it’s <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#concept-shadow-root">shadow root’s</a> <a data-link-type="dfn" href="#shadow-root-shadow-part-map" id="ref-for-shadow-root-shadow-part-map-3">shadow part map</a> <var>partMap</var> <a data-link-type="dfn" href="https://infra.spec.whatwg.org/#map-exists">contains</a> ident1,
then this adds «[ ident2 → <var>partMap</var>[ident1] ]» to the <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#concept-shadow-root">shadow root’s</a> <a data-link-type="dfn" href="#shadow-root-shadow-part-map" id="ref-for-shadow-root-shadow-part-map-4">shadow part map</a>.</p>
<dt data-md="">
<p><code>* => prefix*</code></p>
<dd data-md="">
<p>If el is a <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#element-shadow-host">shadow host</a>,
then <a data-link-type="dfn" href="https://infra.spec.whatwg.org/#map-iterate">for each</a> <var>ident</var> → <var>subEl</var> in el’s <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#concept-shadow-root">shadow root’s</a> <a data-link-type="dfn" href="#shadow-root-shadow-part-map" id="ref-for-shadow-root-shadow-part-map-5">shadow part map</a>,
«[ prefix + <var>ident</var> → <var>subEl</var> ]» is added to the <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#concept-shadow-root">shadow root’s</a> <a data-link-type="dfn" href="#shadow-root-shadow-part-map" id="ref-for-shadow-root-shadow-part-map-6">shadow part map</a>.</p>
<dt data-md="">
<p>anything else</p>
<dd data-md="">
<p>Ignored for error-recovery / future compat.</p>
</dl>
<p class="note" role="note">Note: It’s okay to give a part multiple names,
or map a sub-part to several names.
The "part name" should be considered similar to a class,
not an id or tagname.</p>
<p>Each <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#concept-shadow-root">shadow root</a> has a <dfn class="dfn-paneled" data-dfn-for="shadow root" data-dfn-type="dfn" data-export="" id="shadow-root-shadow-part-map">shadow part map</dfn> and a <dfn class="dfn-paneled" data-dfn-for="shadow root" data-dfn-type="dfn" data-export="" id="shadow-root-shadow-theme-map">shadow theme map</dfn>,
both of which are <a data-link-type="dfn" href="https://infra.spec.whatwg.org/#ordered-map">ordered maps</a>.</p>
<p>The <a data-link-type="dfn" href="#shadow-root-shadow-part-map" id="ref-for-shadow-root-shadow-part-map-7">shadow part map</a> contains all the entries described by the elements in its <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#concept-shadow-tree">shadow tree</a>,
as described above.</p>
<p>If the <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#concept-shadow-root">shadow root</a>’s <code class="idl"><a data-link-type="idl" href="https://dom.spec.whatwg.org/#dom-shadowroot-mode">mode</a></code> is <code class="idl"><a data-link-type="idl" href="https://dom.spec.whatwg.org/#dom-shadowrootmode-closed">"closed"</a></code>,
the <a data-link-type="dfn" href="#shadow-root-shadow-theme-map" id="ref-for-shadow-root-shadow-theme-map-2">shadow theme map</a> is identical to the <a data-link-type="dfn" href="#shadow-root-shadow-part-map" id="ref-for-shadow-root-shadow-part-map-8">shadow part map</a>.
Otherwise,
it’s the concatenation of the <a data-link-type="dfn" href="#shadow-root-shadow-part-map" id="ref-for-shadow-root-shadow-part-map-9">shadow part map</a> with the <a data-link-type="dfn" href="#shadow-root-shadow-theme-map" id="ref-for-shadow-root-shadow-theme-map-3">shadow theme maps</a> of every <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#element-shadow-host">shadow host</a>’s <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#concept-shadow-root">shadow root</a> in its <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#concept-shadow-tree">shadow tree</a>.</p>
<p class="issue" id="issue-4303394f"><a class="self-link" href="#issue-4303394f"></a> TODO: Define a syntax or new attribute
to prevent an element from adding things to its <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#concept-shadow-root">shadow root’s</a> <a data-link-type="dfn" href="#shadow-root-shadow-theme-map" id="ref-for-shadow-root-shadow-theme-map-4">shadow theme map</a>.</p>
<h2 class="heading settled" data-level="3" id="part-theme"><span class="secno">3. </span><span class="content">Selecting a Shadow Element: the <a class="css" data-link-type="maybe" href="#selectordef-part" id="ref-for-selectordef-part-5">::part()</a> and <a class="css" data-link-type="maybe" href="#selectordef-theme" id="ref-for-selectordef-theme-4">::theme()</a> pseudo-elements</span><a class="self-link" href="#part-theme"></a></h2>
<p>The <dfn class="dfn-paneled css" data-dfn-type="selector" data-export="" id="selectordef-part">::part()</dfn> and <dfn class="dfn-paneled css" data-dfn-type="selector" data-export="" id="selectordef-theme">::theme()</dfn> pseudo-elements
(collectively, the <dfn class="dfn-paneled" data-dfn-type="dfn" data-export="" id="shadow-part-pseudo-elements">shadow-part pseudo-elements</dfn>)
allow you to select elements that have been exposed via a <code><a data-link-type="element-sub" href="#element-attrdef-html-global-part" id="ref-for-element-attrdef-html-global-part-2">part</a></code> attribute.
The syntaxes of them are:</p>
<pre class="prod">::part() = ::part( <a class="production" data-link-type="type" href="https://drafts.csswg.org/css-values-4/#typedef-ident"><ident></a> )
::theme() = ::theme( <a class="production" data-link-type="type" href="https://drafts.csswg.org/css-values-4/#typedef-ident"><ident></a> )
</pre>
<p>The <a class="css" data-link-type="maybe" href="#selectordef-part" id="ref-for-selectordef-part-6">::part()</a> pseudo-element only matches anything
when the <a data-link-type="dfn" href="https://drafts.csswg.org/selectors-4/#originating-element">originating element</a> is a <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#element-shadow-host">shadow host</a>.
If the <a data-link-type="dfn" href="https://drafts.csswg.org/selectors-4/#originating-element">originating element’s</a> <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#concept-shadow-root">shadow root’s</a> <a data-link-type="dfn" href="#shadow-root-shadow-part-map" id="ref-for-shadow-root-shadow-part-map-10">shadow part map</a> <a data-link-type="dfn" href="https://infra.spec.whatwg.org/#map-exists">contains</a> the specified <a class="production css" data-link-type="type" href="https://drafts.csswg.org/css-values-4/#typedef-ident"><ident></a>, <a class="css" data-link-type="maybe" href="#selectordef-part" id="ref-for-selectordef-part-7">::part()</a> matches the element or elements keyed to that <a class="production css" data-link-type="type" href="https://drafts.csswg.org/css-values-4/#typedef-ident"><ident></a>.
Otherwise, it matches nothing.</p>
<div class="example" id="example-d833c64c"><a class="self-link" href="#example-d833c64c"></a> For example,
if you have a custom button
that contains a "label" element that is exposed for styling
(via <code>part="label"</code>),
you can select it with <span class="css">#the-button::part(label)</span>. </div>
<p>The <a class="css" data-link-type="maybe" href="#selectordef-theme" id="ref-for-selectordef-theme-5">::theme()</a> pseudo-element is similar,
except it can match regardless of whether the <a data-link-type="dfn" href="https://drafts.csswg.org/selectors-4/#originating-element">originating element</a> is a <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#element-shadow-host">shadow host</a> or not.
It matches the elements keyed to the specified <a class="production css" data-link-type="type" href="https://drafts.csswg.org/css-values-4/#typedef-ident"><ident></a> in the <a data-link-type="dfn" href="#shadow-root-shadow-theme-map" id="ref-for-shadow-root-shadow-theme-map-5">shadow theme map</a> of the <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#concept-shadow-tree">shadow trees</a> of the <a data-link-type="dfn" href="https://drafts.csswg.org/selectors-4/#originating-element">originating element</a> or any descendants.</p>
<div class="example" id="example-860e4f35"><a class="self-link" href="#example-860e4f35"></a> For example, <span class="css">:root::theme(label)</span> matches any element with <code>part="label"</code> anywhere in the entire document,
no matter how deeply nested into shadow trees they are. </div>
<p>The <a data-link-type="dfn" href="#shadow-part-pseudo-elements" id="ref-for-shadow-part-pseudo-elements-1">shadow-part pseudo-elements</a> can take additional pseudo-classes after them,
such as <span class="css">x-button::part(label):hover</span>,
but never match the <a data-link-type="dfn" href="https://drafts.csswg.org/selectors-4/#structural-pseudo-classes">structural pseudo-classes</a> or any other pseudo-classes that match based on tree information
rather than local element information.</p>
<p>The <a data-link-type="dfn" href="#shadow-part-pseudo-elements" id="ref-for-shadow-part-pseudo-elements-2">shadow-part pseudo-elements</a> also can take additional pseudo-elements after them,
such as <span class="css">x-button::part(label)::before</span>,
but never match additional <a data-link-type="dfn" href="#shadow-part-pseudo-elements" id="ref-for-shadow-part-pseudo-elements-3">shadow-part pseudo-elements</a>.</p>
<div class="example" id="example-13b4219d">
<a class="self-link" href="#example-13b4219d"></a> For example, <span class="css">x-panel::part(confirm-button)::part(label)</span> never matches anything.
This is because doing so would expose more structural information
than is intended.
<p>One can still target the nested label with a selector like <span class="css">x-panel::theme(label)</span>.
However, this will also select the labels of any other buttons in the panel.</p>
<p>If the <code><x-panel></code>’s internal confirm button had used something like <code>part="confirm-button, * => confirm-*"</code> to forward the button’s internal parts up into the panel’s own <a data-link-type="dfn" href="#shadow-root-shadow-part-map" id="ref-for-shadow-root-shadow-part-map-11">shadow part map</a>,
then a selector like <span class="css">x-panel::part(confirm-label)</span> would select just the one button’s label,
ignoring any other labels.</p>
</div>
</main>
<h2 class="no-ref no-num heading settled" id="conformance"><span class="content"> Conformance</span><a class="self-link" href="#conformance"></a></h2>
<h3 class="heading settled" id="document-conventions"><span class="content"> Document conventions</span><a class="self-link" href="#document-conventions"></a></h3>
<p>Conformance requirements are expressed with a combination of
descriptive assertions and RFC 2119 terminology. The key words “MUST”,
“MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”,
“RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this
document are to be interpreted as described in RFC 2119.
However, for readability, these words do not appear in all uppercase
letters in this specification. </p>
<p>All of the text of this specification is normative except sections
explicitly marked as non-normative, examples, and notes. <a data-link-type="biblio" href="#biblio-rfc2119">[RFC2119]</a> </p>
<p>Examples in this specification are introduced with the words “for example”
or are set apart from the normative text with <code>class="example"</code>,
like this: </p>
<div class="example" id="example-52448c84">
<a class="self-link" href="#example-52448c84"></a>
<p>This is an example of an informative example. </p>
</div>
<p>Informative notes begin with the word “Note” and are set apart from the
normative text with <code>class="note"</code>, like this: </p>
<p class="note" role="note">Note, this is an informative note. </p>
<p>Advisements are normative sections styled to evoke special attention and are
set apart from other normative text with <code><strong class="advisement"></code>, like
this: <strong class="advisement"> UAs MUST provide an accessible alternative. </strong> </p>
<h3 class="heading settled" id="conform-classes"><span class="content"> Conformance classes</span><a class="self-link" href="#conform-classes"></a></h3>
<p>Conformance to this specification
is defined for three conformance classes: </p>
<dl>
<dt>style sheet
<dd>A <a href="http://www.w3.org/TR/CSS2/conform.html#style-sheet">CSS
style sheet</a>.
<dt>renderer
<dd>A <a href="http://www.w3.org/TR/CSS2/conform.html#user-agent">UA</a> that interprets the semantics of a style sheet and renders
documents that use them.
<dt>authoring tool
<dd>A <a href="http://www.w3.org/TR/CSS2/conform.html#user-agent">UA</a> that writes a style sheet.
</dl>
<p>A style sheet is conformant to this specification
if all of its statements that use syntax defined in this module are valid
according to the generic CSS grammar and the individual grammars of each
feature defined in this module. </p>
<p>A renderer is conformant to this specification
if, in addition to interpreting the style sheet as defined by the
appropriate specifications, it supports all the features defined
by this specification by parsing them correctly
and rendering the document accordingly. However, the inability of a
UA to correctly render a document due to limitations of the device
does not make the UA non-conformant. (For example, a UA is not
required to render color on a monochrome monitor.) </p>
<p>An authoring tool is conformant to this specification
if it writes style sheets that are syntactically correct according to the
generic CSS grammar and the individual grammars of each feature in
this module, and meet all other conformance requirements of style sheets
as described in this module. </p>
<h3 class="heading settled" id="conform-responsible"><span class="content"> Requirements for Responsible Implementation of CSS</span><a class="self-link" href="#conform-responsible"></a></h3>
<p>The following sections define several conformance requirements
for implementing CSS responsibly,
in a way that promotes interoperability in the present and future. </p>
<h4 class="heading settled" id="conform-partial"><span class="content"> Partial Implementations</span><a class="self-link" href="#conform-partial"></a></h4>
<p>So that authors can exploit the forward-compatible parsing rules to assign fallback values, <strong>CSS renderers <em>must</em> treat as invalid
(and <a href="http://www.w3.org/TR/CSS2/conform.html#ignore">ignore as appropriate</a>)
any at-rules, properties, property values, keywords, and other syntactic constructs
for which they have no usable level of support</strong>.
In particular, user agents <em>must not</em> selectively ignore
unsupported property values and honor supported values in a single multi-value property declaration:
if any value is considered invalid (as unsupported values must be),
CSS requires that the entire declaration be ignored. </p>
<h4 class="heading settled" id="conform-future-proofing"><span class="content"> Implementations of Unstable and Proprietary Features</span><a class="self-link" href="#conform-future-proofing"></a></h4>
<p>To avoid clashes with future stable CSS features,
the CSSWG recommends <a href="http://www.w3.org/TR/CSS/#future-proofing">following best practices</a> for the implementation of <a href="http://www.w3.org/TR/CSS/#unstable">unstable</a> features and <a href="http://www.w3.org/TR/CSS/#proprietary-extension">proprietary extensions</a> to CSS. </p>
<h4 class="heading settled" id="conform-testing"><span class="content"> Implementations of CR-level Features</span><a class="self-link" href="#conform-testing"></a></h4>
<p>Once a specification reaches the Candidate Recommendation stage,
implementers should release an <a data-link-type="dfn" href="http://www.w3.org/TR/CSS/#vendor-prefix">unprefixed</a> implementation
of any CR-level feature they can demonstrate
to be correctly implemented according to spec,
and should avoid exposing a prefixed variant of that feature. </p>
<p>To establish and maintain the interoperability of CSS across
implementations, the CSS Working Group requests that non-experimental
CSS renderers submit an implementation report (and, if necessary, the
testcases used for that implementation report) to the W3C before
releasing an unprefixed implementation of any CSS features. Testcases
submitted to W3C are subject to review and correction by the CSS
Working Group. </p>
<p>
Further information on submitting testcases and implementation reports
can be found from on the CSS Working Group’s website at <a href="http://www.w3.org/Style/CSS/Test/">http://www.w3.org/Style/CSS/Test/</a>.
Questions should be directed to the <a href="http://lists.w3.org/Archives/Public/public-css-testsuite">public-css-testsuite@w3.org</a> mailing list.
<script src="https://www.w3.org/scripts/TR/2016/fixup.js"></script>
</p>
<h2 class="no-num no-ref heading settled" id="index"><span class="content">Index</span><a class="self-link" href="#index"></a></h2>
<h3 class="no-num no-ref heading settled" id="index-defined-here"><span class="content">Terms defined by this specification</span><a class="self-link" href="#index-defined-here"></a></h3>
<ul class="index">
<li><a href="#selectordef-part">::part()</a><span>, in §3</span>
<li><a href="#element-attrdef-html-global-part">part</a><span>, in §2</span>
<li><a href="#shadow-root-shadow-part-map">shadow part map</a><span>, in §2</span>
<li><a href="#shadow-part-pseudo-elements">shadow-part pseudo-elements</a><span>, in §3</span>
<li><a href="#shadow-root-shadow-theme-map">shadow theme map</a><span>, in §2</span>
<li><a href="#selectordef-theme">::theme()</a><span>, in §3</span>
</ul>
<h3 class="no-num no-ref heading settled" id="index-defined-elsewhere"><span class="content">Terms defined by reference</span><a class="self-link" href="#index-defined-elsewhere"></a></h3>
<ul class="index">
<li>
<a data-link-type="biblio">[css-scoping-1]</a> defines the following terms:
<ul>
<li><a href="https://drafts.csswg.org/css-scoping-1/#selectordef-shadow-piercing-descendant-combinator">>>></a>
</ul>
<li>
<a data-link-type="biblio">[css-values-3]</a> defines the following terms:
<ul>
<li><a href="https://drafts.csswg.org/css-values-4/#typedef-ident"><ident></a>
</ul>
<li>
<a data-link-type="biblio">[css-variables-1]</a> defines the following terms:
<ul>
<li><a href="https://drafts.csswg.org/css-variables-1/#custom-property">custom property</a>
</ul>
<li>
<a data-link-type="biblio">[WHATWG-DOM]</a> defines the following terms:
<ul>
<li><a href="https://dom.spec.whatwg.org/#dom-shadowrootmode-closed">"closed"</a>
<li><a href="https://dom.spec.whatwg.org/#dom-shadowroot-mode">mode</a>
<li><a href="https://dom.spec.whatwg.org/#element-shadow-host">shadow host</a>
<li><a href="https://dom.spec.whatwg.org/#concept-shadow-root">shadow root</a>
<li><a href="https://dom.spec.whatwg.org/#concept-shadow-tree">shadow tree</a>
</ul>
<li>
<a data-link-type="biblio">[INFRA]</a> defines the following terms:
<ul>
<li><a href="https://infra.spec.whatwg.org/#map-exists">contains</a>
<li><a href="https://infra.spec.whatwg.org/#map-iterate">for each</a>
<li><a href="https://infra.spec.whatwg.org/#ordered-map">ordered map</a>
</ul>
<li>
<a data-link-type="biblio">[selectors-4]</a> defines the following terms:
<ul>
<li><a href="https://drafts.csswg.org/selectors-4/#hover-pseudo">:hover</a>
<li><a href="https://drafts.csswg.org/selectors-4/#dynamic-profile">dynamic profile</a>
<li><a href="https://drafts.csswg.org/selectors-4/#originating-element">originating element</a>
<li><a href="https://drafts.csswg.org/selectors-4/#structural-pseudo-classes">structural pseudo-classes</a>
</ul>
</ul>
<h2 class="no-num no-ref heading settled" id="references"><span class="content">References</span><a class="self-link" href="#references"></a></h2>
<h3 class="no-num no-ref heading settled" id="normative"><span class="content">Normative References</span><a class="self-link" href="#normative"></a></h3>
<dl>
<dt id="biblio-css-scoping-1">[CSS-SCOPING-1]
<dd>Tab Atkins Jr.; Elika Etemad. <a href="http://dev.w3.org/csswg/css-scoping/">CSS Scoping Module Level 1</a>. URL: <a href="http://dev.w3.org/csswg/css-scoping/">http://dev.w3.org/csswg/css-scoping/</a>
<dt id="biblio-css-values-3">[CSS-VALUES-3]
<dd>Tab Atkins Jr.; Elika Etemad. <a href="https://drafts.csswg.org/css-values/">CSS Values and Units Module Level 3</a>. URL: <a href="https://drafts.csswg.org/css-values/">https://drafts.csswg.org/css-values/</a>
<dt id="biblio-css-variables-1">[CSS-VARIABLES-1]
<dd>Tab Atkins Jr.. <a href="http://dev.w3.org/csswg/css-variables/">CSS Custom Properties for Cascading Variables Module Level 1</a>. URL: <a href="http://dev.w3.org/csswg/css-variables/">http://dev.w3.org/csswg/css-variables/</a>
<dt id="biblio-infra">[INFRA]
<dd>Anne van Kesteren; Domenic Denicola. <a href="https://infra.spec.whatwg.org/">Infra Standard</a>. Living Standard. URL: <a href="https://infra.spec.whatwg.org/">https://infra.spec.whatwg.org/</a>
<dt id="biblio-rfc2119">[RFC2119]
<dd>S. Bradner. <a href="https://tools.ietf.org/html/rfc2119">Key words for use in RFCs to Indicate Requirement Levels</a>. March 1997. Best Current Practice. URL: <a href="https://tools.ietf.org/html/rfc2119">https://tools.ietf.org/html/rfc2119</a>
<dt id="biblio-selectors-4">[SELECTORS-4]
<dd>Selectors Level 4 URL: <a href="https://drafts.csswg.org/selectors-4/">https://drafts.csswg.org/selectors-4/</a>
<dt id="biblio-whatwg-dom">[WHATWG-DOM]
<dd>Anne van Kesteren. <a href="https://dom.spec.whatwg.org/">DOM Standard</a>. Living Standard. URL: <a href="https://dom.spec.whatwg.org/">https://dom.spec.whatwg.org/</a>
</dl>
<h2 class="no-num no-ref heading settled" id="issues-index"><span class="content">Issues Index</span><a class="self-link" href="#issues-index"></a></h2>
<div style="counter-reset:issue">
<div class="issue"> This spec is intentionally a rough sketch at the moment.
It should contain all the details necessary to evaluate the proposal,
but is intentionally avoiding precise algorithms at the moment,
to aid in easy comprehension
and to, hopefully, discourage implementation from this sketch.<a href="#issue-0b399633"> ↵ </a></div>
<div class="issue"> TODO: Define a syntax or new attribute
to prevent an element from adding things to its <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#concept-shadow-root">shadow root’s</a> <a data-link-type="dfn" href="#shadow-root-shadow-theme-map">shadow theme map</a>.<a href="#issue-4303394f"> ↵ </a></div>
</div>
<aside class="dfn-panel" data-for="element-attrdef-html-global-part">
<b><a href="#element-attrdef-html-global-part">#element-attrdef-html-global-part</a></b><b>Referenced in:</b>
<ul>
<li><a href="#ref-for-element-attrdef-html-global-part-1">2. Exposing a Shadow Element: the part attribute</a>
<li><a href="#ref-for-element-attrdef-html-global-part-2">3. Selecting a Shadow Element: the ::part() and ::theme() pseudo-elements</a>
</ul>
</aside>
<aside class="dfn-panel" data-for="shadow-root-shadow-part-map">
<b><a href="#shadow-root-shadow-part-map">#shadow-root-shadow-part-map</a></b><b>Referenced in:</b>
<ul>
<li><a href="#ref-for-shadow-root-shadow-part-map-1">1.1. Motivation</a>
<li><a href="#ref-for-shadow-root-shadow-part-map-2">2. Exposing a Shadow Element: the part attribute</a> <a href="#ref-for-shadow-root-shadow-part-map-3">(2)</a> <a href="#ref-for-shadow-root-shadow-part-map-4">(3)</a> <a href="#ref-for-shadow-root-shadow-part-map-5">(4)</a> <a href="#ref-for-shadow-root-shadow-part-map-6">(5)</a> <a href="#ref-for-shadow-root-shadow-part-map-7">(6)</a> <a href="#ref-for-shadow-root-shadow-part-map-8">(7)</a> <a href="#ref-for-shadow-root-shadow-part-map-9">(8)</a>
<li><a href="#ref-for-shadow-root-shadow-part-map-10">3. Selecting a Shadow Element: the ::part() and ::theme() pseudo-elements</a> <a href="#ref-for-shadow-root-shadow-part-map-11">(2)</a>
</ul>
</aside>
<aside class="dfn-panel" data-for="shadow-root-shadow-theme-map">
<b><a href="#shadow-root-shadow-theme-map">#shadow-root-shadow-theme-map</a></b><b>Referenced in:</b>
<ul>
<li><a href="#ref-for-shadow-root-shadow-theme-map-1">1.1. Motivation</a>
<li><a href="#ref-for-shadow-root-shadow-theme-map-2">2. Exposing a Shadow Element: the part attribute</a> <a href="#ref-for-shadow-root-shadow-theme-map-3">(2)</a> <a href="#ref-for-shadow-root-shadow-theme-map-4">(3)</a>
<li><a href="#ref-for-shadow-root-shadow-theme-map-5">3. Selecting a Shadow Element: the ::part() and ::theme() pseudo-elements</a>
</ul>
</aside>
<aside class="dfn-panel" data-for="selectordef-part">
<b><a href="#selectordef-part">#selectordef-part</a></b><b>Referenced in:</b>
<ul>
<li><a href="#ref-for-selectordef-part-1">1. Introduction</a>
<li><a href="#ref-for-selectordef-part-2">1.1. Motivation</a> <a href="#ref-for-selectordef-part-3">(2)</a> <a href="#ref-for-selectordef-part-4">(3)</a>
<li><a href="#ref-for-selectordef-part-5">3. Selecting a Shadow Element: the ::part() and ::theme() pseudo-elements</a> <a href="#ref-for-selectordef-part-6">(2)</a> <a href="#ref-for-selectordef-part-7">(3)</a>
</ul>
</aside>
<aside class="dfn-panel" data-for="selectordef-theme">
<b><a href="#selectordef-theme">#selectordef-theme</a></b><b>Referenced in:</b>
<ul>
<li><a href="#ref-for-selectordef-theme-1">1. Introduction</a>
<li><a href="#ref-for-selectordef-theme-2">1.1. Motivation</a> <a href="#ref-for-selectordef-theme-3">(2)</a>
<li><a href="#ref-for-selectordef-theme-4">3. Selecting a Shadow Element: the ::part() and ::theme() pseudo-elements</a> <a href="#ref-for-selectordef-theme-5">(2)</a>
</ul>
</aside>
<aside class="dfn-panel" data-for="shadow-part-pseudo-elements">
<b><a href="#shadow-part-pseudo-elements">#shadow-part-pseudo-elements</a></b><b>Referenced in:</b>
<ul>
<li><a href="#ref-for-shadow-part-pseudo-elements-1">3. Selecting a Shadow Element: the ::part() and ::theme() pseudo-elements</a> <a href="#ref-for-shadow-part-pseudo-elements-2">(2)</a> <a href="#ref-for-shadow-part-pseudo-elements-3">(3)</a>
</ul>
</aside>
<script>/* script-dfn-panel */
document.body.addEventListener("click", function(e) {
var queryAll = function(sel) { return [].slice.call(document.querySelectorAll(sel)); }
// Find the dfn element or panel, if any, that was clicked on.
var el = e.target;
var target;
var hitALink = false;
while(el.parentElement) {
if(el.tagName == "A") {
// Clicking on a link in a <dfn> shouldn't summon the panel
hitALink = true;
}
if(el.classList.contains("dfn-paneled")) {
target = "dfn";
break;
}
if(el.classList.contains("dfn-panel")) {
target = "dfn-panel";
break;
}
el = el.parentElement;
}
if(target != "dfn-panel") {
// Turn off any currently "on" or "activated" panels.
queryAll(".dfn-panel.on, .dfn-panel.activated").forEach(function(el){
el.classList.remove("on");
el.classList.remove("activated");
});
}
if(target == "dfn" && !hitALink) {
// open the panel
var dfnPanel = document.querySelector(".dfn-panel[data-for='" + el.id + "']");
if(dfnPanel) {
console.log(dfnPanel);
dfnPanel.classList.add("on");
var rect = el.getBoundingClientRect();
dfnPanel.style.left = window.scrollX + rect.right + 5 + "px";
dfnPanel.style.top = window.scrollY + rect.top + "px";
var panelRect = dfnPanel.getBoundingClientRect();
var panelWidth = panelRect.right - panelRect.left;
if(panelRect.right > document.body.scrollWidth && (rect.left - (panelWidth + 5)) > 0) {
// Reposition, because the panel is overflowing
dfnPanel.style.left = window.scrollX + rect.left - (panelWidth + 5) + "px";
}
} else {
console.log("Couldn't find .dfn-panel[data-for='" + el.id + "']");
}
} else if(target == "dfn-panel") {
// Switch it to "activated" state, which pins it.
el.classList.add("activated");
el.style.left = null;
el.style.top = null;
}
});
</script>