File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11let sheet ;
22let sparkleTemplate ;
33
4+ // https://caniuse.com/mdn-api_cssstylesheet_replacesync
5+ const supportsConstructibleStylesheets = ( "replaceSync" in CSSStyleSheet . prototype ) ;
6+
47class SparklyText extends HTMLElement {
58 #numberOfSparkles = 3 ;
69 #sparkleSvg = `<svg width="1200" height="1200" viewBox="0 0 1200 1200" aria-hidden="true">
@@ -64,15 +67,24 @@ class SparklyText extends HTMLElement {
6467 }
6568 }
6669` ;
67- sheet = new CSSStyleSheet ( ) ;
68- sheet . replaceSync ( css ) ;
70+ if ( supportsConstructibleStylesheets ) {
71+ sheet = new CSSStyleSheet ( ) ;
72+ sheet . replaceSync ( css ) ;
73+ } else {
74+ sheet = document . createElement ( "style" ) ;
75+ sheet . textContent = css ;
76+ }
77+ }
78+
79+ if ( supportsConstructibleStylesheets ) {
80+ this . shadowRoot . adoptedStyleSheets = [ sheet ] ;
81+ } else {
82+ this . shadowRoot . append ( sheet . cloneNode ( true ) ) ;
6983 }
70- this . shadowRoot . adoptedStyleSheets = [ sheet ] ;
7184 }
7285
7386 connectedCallback ( ) {
74- // https://caniuse.com/mdn-api_cssstylesheet_replacesync
75- if ( this . shadowRoot || ! ( "replaceSync" in CSSStyleSheet . prototype ) ) {
87+ if ( this . shadowRoot ) {
7688 return ;
7789 }
7890
You can’t perform that action at this time.
0 commit comments