@@ -25,13 +25,13 @@ template.innerHTML = templateContent
2525
2626const PLACEMENT = [ 'top-right' , 'top-left' , 'bottom-right' , 'bottom-left' ]
2727
28- const DEFAULT_SIZE = '5rem'
2928const DEFAULT_BANNER_COLOR = 'black'
3029const DEFAULT_OCTOCAT_COLOR = 'white'
3130const DEFAULT_DURATION = '0.5s'
3231
3332class GithubCorner extends HTMLElement {
3433 #shadowRoot: ShadowRoot
34+ #styleSheet: CSSStyleSheet
3535
3636 #anchor: HTMLAnchorElement
3737 #svgContainer: SVGElement
@@ -46,14 +46,15 @@ class GithubCorner extends HTMLElement {
4646 constructor ( ) {
4747 super ( )
4848
49+ this . #styleSheet = new CSSStyleSheet ( )
50+ this . #styleSheet. replaceSync ( cssContent )
51+
4952 // Create a shadow root
5053 this . #shadowRoot = this . attachShadow ( { mode : 'open' } )
51-
52- const style = document . createElement ( 'style' )
53- style . textContent = cssContent
54+ this . #shadowRoot. adoptedStyleSheets = [ this . #styleSheet]
5455
5556 // attach the created elements to the shadow DOM
56- this . #shadowRoot. append ( style , template . content . cloneNode ( true ) )
57+ this . #shadowRoot. append ( template . content . cloneNode ( true ) )
5758 this . #anchor = this . #shadowRoot. querySelector ( 'a.link' ) as HTMLAnchorElement
5859
5960 this . #svgContainer = this . #shadowRoot. querySelector (
@@ -91,9 +92,6 @@ class GithubCorner extends HTMLElement {
9192 }
9293
9394 #init( ) {
94- const size = this . getAttribute ( 'size' )
95- this . #setSize( size ? size : DEFAULT_SIZE )
96-
9795 if ( ! this . #banner. getAttribute ( 'fill' ) ) {
9896 this . #banner. setAttribute ( 'fill' , DEFAULT_BANNER_COLOR )
9997 }
@@ -110,11 +108,6 @@ class GithubCorner extends HTMLElement {
110108 }
111109 }
112110
113- #setSize( size : string ) {
114- this . style . width = size
115- this . style . height = size
116- }
117-
118111 connectedCallback ( ) {
119112 if ( this . #status === 'init' ) {
120113 this . #init( )
@@ -137,7 +130,11 @@ class GithubCorner extends HTMLElement {
137130 ) {
138131 switch ( attributeName ) {
139132 case 'size' :
140- this . #setSize( newValue )
133+ // replace size custom property
134+ this . #styleSheet. deleteRule ( 0 )
135+ this . #styleSheet. insertRule (
136+ `:host { --github-corner-size: ${ newValue } ; }`
137+ )
141138 break
142139
143140 case 'href' :
0 commit comments