1- const toc = document . querySelector ( "#observablehq-toc" ) ;
1+ const toc = document . querySelector < HTMLElement > ( "#observablehq-toc" ) ;
22if ( toc ) {
33 const highlight = toc . appendChild ( document . createElement ( "div" ) ) ;
44 highlight . classList . add ( "observablehq-secondary-link-highlight" ) ;
5- const headings = Array . from ( document . querySelectorAll ( toc . dataset . selector ) ) . reverse ( ) ;
6- const links = toc . querySelectorAll ( ".observablehq-secondary-link" ) ;
7- const relink = ( ) => {
5+ const headings = Array . from ( document . querySelectorAll < HTMLElement > ( toc . dataset . selector ! ) ) . reverse ( ) ;
6+ const links = toc . querySelectorAll < HTMLElement > ( ".observablehq-secondary-link" ) ;
7+ const relink = ( ) : HTMLElement | undefined => {
88 for ( const link of links ) {
99 link . classList . remove ( "observablehq-secondary-link-active" ) ;
1010 }
1111 // If there’s a location.hash, highlight that if it’s at the top of the viewport.
1212 if ( location . hash ) {
1313 for ( const heading of headings ) {
14- const hash = heading . querySelector ( "a[href]" ) ?. hash ;
14+ const hash = heading . querySelector < HTMLAnchorElement > ( "a[href]" ) ?. hash ;
1515 if ( hash === location . hash ) {
1616 const top = heading . getBoundingClientRect ( ) . top ;
1717 if ( 0 < top && top < 40 ) {
1818 for ( const link of links ) {
19- if ( link . querySelector ( "a[href]" ) ?. hash === hash ) {
19+ if ( link . querySelector < HTMLAnchorElement > ( "a[href]" ) ?. hash === hash ) {
2020 link . classList . add ( "observablehq-secondary-link-active" ) ;
2121 return link ;
2222 }
@@ -30,9 +30,9 @@ if (toc) {
3030 // Otherwise, highlight the last one that’s above the center of the viewport.
3131 for ( const heading of headings ) {
3232 if ( heading . getBoundingClientRect ( ) . top >= innerHeight * 0.5 ) continue ;
33- const hash = heading . querySelector ( "a[href]" ) ?. hash ;
33+ const hash = heading . querySelector < HTMLAnchorElement > ( "a[href]" ) ?. hash ;
3434 for ( const link of links ) {
35- if ( link . querySelector ( "a[href]" ) ?. hash === hash ) {
35+ if ( link . querySelector < HTMLAnchorElement > ( "a[href]" ) ?. hash === hash ) {
3636 link . classList . add ( "observablehq-secondary-link-active" ) ;
3737 return link ;
3838 }
@@ -42,7 +42,7 @@ if (toc) {
4242 } ;
4343 const intersected = ( ) => {
4444 const link = relink ( ) ;
45- highlight . style = link ? `top: ${ link . offsetTop } px; height: ${ link . offsetHeight } px;` : "" ;
45+ highlight . style . cssText = link ? `top: ${ link . offsetTop } px; height: ${ link . offsetHeight } px;` : "" ;
4646 } ;
4747 const observer = new IntersectionObserver ( intersected , { rootMargin : "0px 0px -50% 0px" } ) ;
4848 for ( const heading of headings ) observer . observe ( heading ) ;
0 commit comments