@@ -27,9 +27,8 @@ const animationKeywords = new Set([
27
27
] ) ;
28
28
29
29
/**
30
- * The following class is a port of shadowCSS from webcomponents.js to TypeScript.
31
- *
32
- * Please make sure to keep to edits in sync with the source file.
30
+ * The following class has its origin from a port of shadowCSS from webcomponents.js to TypeScript.
31
+ * It has since diverge in many ways to tailor Angular's needs.
33
32
*
34
33
* Source:
35
34
* https://github.com/webcomponents/webcomponentsjs/blob/4efecd7e0e/src/ShadowCSS/ShadowCSS.js
@@ -70,28 +69,8 @@ const animationKeywords = new Set([
70
69
}
71
70
72
71
* encapsulation: Styles defined within ShadowDOM, apply only to
73
- dom inside the ShadowDOM. Polymer uses one of two techniques to implement
74
- this feature.
75
-
76
- By default, rules are prefixed with the host element tag name
77
- as a descendant selector. This ensures styling does not leak out of the 'top'
78
- of the element's ShadowDOM. For example,
79
-
80
- div {
81
- font-weight: bold;
82
- }
83
-
84
- becomes:
85
-
86
- x-foo div {
87
- font-weight: bold;
88
- }
89
-
90
- becomes:
91
-
92
-
93
- Alternatively, if WebComponents.ShadowCSS.strictStyling is set to true then
94
- selectors are scoped by adding an attribute selector suffix to each
72
+ dom inside the ShadowDOM.
73
+ The selectors are scoped by adding an attribute selector suffix to each
95
74
simple selector that contains the host element tag name. Each element
96
75
in the element's ShadowDOM template is also given the scope attribute.
97
76
Thus, these rules match only elements that have the scope attribute.
@@ -152,16 +131,11 @@ const animationKeywords = new Set([
152
131
in comments in lieu of the next selector when running under polyfill.
153
132
*/
154
133
export class ShadowCss {
155
- // TODO: Is never re-assigned, could be removed.
156
- strictStyling : boolean = true ;
157
-
158
134
/*
159
- * Shim some cssText with the given selector. Returns cssText that can
160
- * be included in the document via WebComponents.ShadowCSS.addCssToDocument(css).
135
+ * Shim some cssText with the given selector. Returns cssText that can be included in the document
161
136
*
162
- * When strictStyling is true:
163
- * - selector is the attribute added to all elements inside the host,
164
- * - hostSelector is the attribute added to the host itself.
137
+ * The selector is the attribute added to all elements inside the host,
138
+ * The hostSelector is the attribute added to the host itself.
165
139
*/
166
140
shimCssText ( cssText : string , selector : string , hostSelector : string = '' ) : string {
167
141
const commentsWithHash = extractCommentsWithHash ( cssText ) ;
@@ -373,7 +347,6 @@ export class ShadowCss {
373
347
*
374
348
**/
375
349
private _insertPolyfillDirectivesInCssText ( cssText : string ) : string {
376
- // Difference with webcomponents.js: does not handle comments
377
350
return cssText . replace ( _cssContentNextSelectorRe , function ( ...m : string [ ] ) {
378
351
return m [ 2 ] + '{' ;
379
352
} ) ;
@@ -395,7 +368,6 @@ export class ShadowCss {
395
368
*
396
369
**/
397
370
private _insertPolyfillRulesInCssText ( cssText : string ) : string {
398
- // Difference with webcomponents.js: does not handle comments
399
371
return cssText . replace ( _cssContentRuleRe , ( ...m : string [ ] ) => {
400
372
const rule = m [ 0 ] . replace ( m [ 1 ] , '' ) . replace ( m [ 2 ] , '' ) ;
401
373
return m [ 4 ] + rule ;
@@ -441,7 +413,6 @@ export class ShadowCss {
441
413
*
442
414
**/
443
415
private _extractUnscopedRulesFromCssText ( cssText : string ) : string {
444
- // Difference with webcomponents.js: does not handle comments
445
416
let r = '' ;
446
417
let m : RegExpExecArray | null ;
447
418
_cssContentUnscopedRuleRe . lastIndex = 0 ;
@@ -568,8 +539,7 @@ export class ShadowCss {
568
539
let selector = rule . selector ;
569
540
let content = rule . content ;
570
541
if ( rule . selector [ 0 ] !== '@' ) {
571
- selector =
572
- this . _scopeSelector ( rule . selector , scopeSelector , hostSelector , this . strictStyling ) ;
542
+ selector = this . _scopeSelector ( rule . selector , scopeSelector , hostSelector ) ;
573
543
} else if (
574
544
rule . selector . startsWith ( '@media' ) || rule . selector . startsWith ( '@supports' ) ||
575
545
rule . selector . startsWith ( '@document' ) || rule . selector . startsWith ( '@layer' ) ||
@@ -611,17 +581,14 @@ export class ShadowCss {
611
581
} ) ;
612
582
}
613
583
614
- private _scopeSelector (
615
- selector : string , scopeSelector : string , hostSelector : string , strict : boolean ) : string {
584
+ private _scopeSelector ( selector : string , scopeSelector : string , hostSelector : string ) : string {
616
585
return selector . split ( ',' )
617
586
. map ( part => part . trim ( ) . split ( _shadowDeepSelectors ) )
618
587
. map (( deepParts ) => {
619
588
const [ shallowPart , ...otherParts ] = deepParts ;
620
589
const applyScope = ( shallowPart : string ) => {
621
590
if ( this . _selectorNeedsScoping ( shallowPart , scopeSelector ) ) {
622
- return strict ?
623
- this . _applyStrictSelectorScope ( shallowPart , scopeSelector , hostSelector ) :
624
- this . _applySelectorScope ( shallowPart , scopeSelector , hostSelector ) ;
591
+ return this . _applySelectorScope ( shallowPart , scopeSelector , hostSelector ) ;
625
592
} else {
626
593
return shallowPart ;
627
594
}
@@ -643,19 +610,13 @@ export class ShadowCss {
643
610
return new RegExp ( '^(' + scopeSelector + ')' + _selectorReSuffix , 'm' ) ;
644
611
}
645
612
646
- private _applySelectorScope ( selector : string , scopeSelector : string , hostSelector : string ) :
647
- string {
648
- // Difference from webcomponents.js: scopeSelector could not be an array
649
- return this . _applySimpleSelectorScope ( selector , scopeSelector , hostSelector ) ;
650
- }
651
-
652
613
// scope via name and [is=name]
653
614
private _applySimpleSelectorScope ( selector : string , scopeSelector : string , hostSelector : string ) :
654
615
string {
655
616
// In Android browser, the lastIndex is not reset when the regex is used in String.replace()
656
617
_polyfillHostRe . lastIndex = 0 ;
657
618
if ( _polyfillHostRe . test ( selector ) ) {
658
- const replaceBy = this . strictStyling ? `[${ hostSelector } ]` : scopeSelector ;
619
+ const replaceBy = `[${ hostSelector } ]` ;
659
620
return selector
660
621
. replace (
661
622
_polyfillHostNoCombinatorRe ,
@@ -674,7 +635,7 @@ export class ShadowCss {
674
635
675
636
// return a selector with [name] suffix on each simple selector
676
637
// e.g. .foo.bar > .zot becomes .foo[name].bar[name] > .zot[name] /** @internal */
677
- private _applyStrictSelectorScope ( selector : string , scopeSelector : string , hostSelector : string ) :
638
+ private _applySelectorScope ( selector : string , scopeSelector : string , hostSelector : string ) :
678
639
string {
679
640
const isRe = / \[ i s = ( [ ^ \] ] * ) \] / g;
680
641
scopeSelector = scopeSelector . replace ( isRe , ( _ : string , ...parts : string [ ] ) => parts [ 0 ] ) ;
0 commit comments