11const html = String . raw
22const styles = new CSSStyleSheet ( )
33styles . replaceSync ( `
4- :host(:not(:--loading)) {
5- display: grid;
6- max-inline-size: 36em;
7- padding: 0.5em;
8- gap: 0.5em;
9- border: 0.0625em solid grey;
10- border-radius: 0.5em;
11- grid-template:
12- "avatar author-link author-link" max-content
13- "content content content" max-content
14- "backlink backlink backlink" max-content
15- / min-content auto auto;
4+ @supports selector(:--loading) {
5+ :host(:not(:--loading)) {
6+ display: grid;
7+ max-inline-size: 36em;
8+ padding: 0.5em;
9+ gap: 0.5em;
10+ border: 0.0625em solid grey;
11+ border-radius: 0.5em;
12+ grid-template:
13+ "avatar author-link author-link" max-content
14+ "content content content" max-content
15+ "backlink backlink backlink" max-content
16+ / min-content auto auto;
17+ }
18+ }
19+
20+ @supports not selector(:--loading) {
21+ :host(:not([internals-loading])) {
22+ display: grid;
23+ max-inline-size: 36em;
24+ padding: 0.5em;
25+ gap: 0.5em;
26+ border: 0.0625em solid grey;
27+ border-radius: 0.5em;
28+ grid-template:
29+ "avatar author-link author-link" max-content
30+ "content content content" max-content
31+ "backlink backlink backlink" max-content
32+ / min-content auto auto;
33+ }
1634}
1735
1836[part="avatar"] {
@@ -94,7 +112,7 @@ class TootEmbedElement extends HTMLElement {
94112 connectedCallback ( ) : void {
95113 this . #internals = this . attachInternals ( )
96114 this . #internals. role = 'article'
97- this . #renderRoot = this . attachShadow ( { mode : 'open' } )
115+ this . #renderRoot = this . attachShadow ( { mode : 'open' } )
98116 this . #renderRoot. adoptedStyleSheets . push ( styles )
99117 if ( this . querySelector ( 'script[type="application/json"]' ) ) {
100118 return this . #render( JSON . parse ( this . querySelector ( 'script[type="application/json"]' ) . textContent ) )
@@ -111,7 +129,7 @@ class TootEmbedElement extends HTMLElement {
111129
112130 async load ( ) {
113131 this . #internals. states . add ( '--loading' )
114- const { tootId } = this . #useParams( ) ;
132+ const { tootId} = this . #useParams( )
115133 const apiURL = new URL ( `/api/v1/statuses/${ tootId } ` , this . src )
116134 const response = await fetch ( apiURL )
117135 console . log ( response )
@@ -121,19 +139,17 @@ class TootEmbedElement extends HTMLElement {
121139 }
122140
123141 #render( json ) {
124- const { account, url, content } = json
142+ const { account, url, content} = json
125143 console . log ( json )
126144 const handleURL = new URL ( account . url )
127145 const { handle} = this . #useParams( )
128146 this . #renderRoot. innerHTML = html `
129- < img part ="avatar " src ="${ account . avatar } " alt ="">
147+ < img part ="avatar " src ="${ account . avatar } " alt ="" / >
130148 < a part ="author-link " href ="${ handleURL . href } ">
131149 < span part ="author-name "> ${ account . display_name } </ span >
132150 < span part ="author-handle "> @${ handle } @${ handleURL . hostname } </ span >
133151 </ a >
134- < div part ="content ">
135- ${ content }
136- </ div >
152+ < div part ="content "> ${ content } </ div >
137153 < a part ="backlink " href ="${ url } " rel ="bookmark "> Original Toot</ a >
138154 `
139155 this . #internals. states . add ( '--ready' )
@@ -143,16 +159,16 @@ class TootEmbedElement extends HTMLElement {
143159 // URLPattern only works in Chromium right now.
144160 // Could refactor this to use RegExp for compatibility
145161 /* @ts -ignore */
146- #shortPattern = new URLPattern ( { pathname : '/@:handle/:tootId(\\d+)' } )
162+ #shortPattern = new URLPattern ( { pathname : '/@:handle/:tootId(\\d+)' } )
147163 /* @ts -ignore */
148- #longPattern = new URLPattern ( { pathname : '/users/:handle/statuses/:tootId(\\d+)' } )
164+ #longPattern = new URLPattern ( { pathname : '/users/:handle/statuses/:tootId(\\d+)' } )
149165 // Toot URLs can have two different formats:
150166 // 1. https://indieweb.social/@keithamus/109524390152251545
151167 // 2. https://indieweb.social/users/keithamus/statuses/109524390152251545
152- #useParams( ) : { [ key : string ] : string } {
153- const groups = ( this . #shortPattern. exec ( this . src ) ?? this . #longPattern. exec ( this . src ) ) ?. pathname . groups ;
154- if ( groups ) return groups ;
155- throw `This doesn’t seem to be a toot URL: ${ this . src } ` ;
168+ #useParams( ) : { [ key : string ] : string } {
169+ const groups = ( this . #shortPattern. exec ( this . src ) ?? this . #longPattern. exec ( this . src ) ) ?. pathname . groups
170+ if ( groups ) return groups
171+ throw `This doesn’t seem to be a toot URL: ${ this . src } `
156172 }
157173}
158174
0 commit comments