@@ -3,11 +3,11 @@ document.addEventListener('DOMContentLoaded', ready, false);
33const THEME_PREF_STORAGE_KEY = "theme-preference" ;
44const THEME_TO_ICON_CLASS = {
55 'dark' : 'feather-moon' ,
6- 'light' :'feather-sun'
6+ 'light' : 'feather-sun'
77} ;
88const THEME_TO_ICON_TEXT_CLASS = {
99 'dark' : 'Dark mode' ,
10- 'light' :'Light mode'
10+ 'light' : 'Light mode'
1111} ;
1212let toggleIcon = '' ;
1313let darkThemeCss = '' ;
@@ -24,7 +24,7 @@ function ready() {
2424 setThemeByUserPref ( ) ;
2525
2626 if ( document . querySelector ( 'main#content > .container' ) !== null &&
27- document . querySelector ( 'main#content > .container' ) . classList . contains ( 'post' ) ) {
27+ document . querySelector ( 'main#content > .container' ) . classList . contains ( 'post' ) ) {
2828 if ( document . getElementById ( 'TableOfContents' ) !== null ) {
2929 fixTocItemsIndent ( ) ;
3030 createScrollSpy ( ) ;
@@ -38,6 +38,26 @@ function ready() {
3838 // Do the injection
3939 SVGInjector ( svgsToInject ) ;
4040
41+ const observer = new MutationObserver ( ( ) => {
42+ normalizeSvgPaths ( ) ;
43+ } ) ;
44+
45+ observer . observe ( document . body , { childList : true , subtree : true } ) ;
46+
47+ function normalizeSvgPaths ( ) {
48+ document . querySelectorAll ( '.nav-link a .svg-inject' ) . forEach ( path => {
49+ const bbox = path . getBBox ( ) ;
50+ const scaleX = 20 / bbox . width ;
51+ const scaleY = 20 / bbox . height ;
52+ const scale = Math . min ( scaleX , scaleY ) ;
53+
54+ path . setAttribute ( 'transform' , `scale(${ scale } ) translate(${ - bbox . x } , ${ - bbox . y } )` ) ;
55+ path . setAttribute ( 'stroke' , 'currentColor' ) ;
56+ path . setAttribute ( 'stroke-width' , '1' ) ;
57+ path . setAttribute ( 'fill' , 'transparent' ) ;
58+ } ) ;
59+ }
60+
4161 document . getElementById ( 'hamburger-menu-toggle' ) . addEventListener ( 'click' , ( ) => {
4262 const hamburgerMenu = document . getElementsByClassName ( 'nav-hamburger-list' ) [ 0 ]
4363 const hamburgerMenuToggleTarget = document . getElementById ( "hamburger-menu-toggle-target" )
@@ -62,22 +82,22 @@ window.addEventListener('scroll', () => {
6282
6383function fixTocItemsIndent ( ) {
6484 document . querySelectorAll ( '#TableOfContents a' ) . forEach ( $tocItem => {
65- const itemId = $tocItem . getAttribute ( "href" ) . substring ( 1 )
66- $tocItem . classList . add ( HEADING_TO_TOC_CLASS [ document . getElementById ( itemId ) . tagName ] ) ;
85+ const itemId = $tocItem . getAttribute ( "href" ) . substring ( 1 )
86+ $tocItem . classList . add ( HEADING_TO_TOC_CLASS [ document . getElementById ( itemId ) . tagName ] ) ;
6787 } ) ;
6888}
6989
7090function createScrollSpy ( ) {
7191 var elements = document . querySelectorAll ( '#toc a' ) ;
72- document . addEventListener ( 'scroll' , function ( ) {
73- elements . forEach ( function ( element ) {
74- const boundingRect = document . getElementById ( element . getAttribute ( 'href' ) . substring ( 1 ) ) . getBoundingClientRect ( ) ;
75- if ( boundingRect . top <= 55 && boundingRect . bottom >= 0 ) {
76- elements . forEach ( function ( elem ) {
77- elem . classList . remove ( 'active' ) ;
78- } ) ;
79- element . classList . add ( 'active' ) ;
80- }
92+ document . addEventListener ( 'scroll' , function ( ) {
93+ elements . forEach ( function ( element ) {
94+ const boundingRect = document . getElementById ( element . getAttribute ( 'href' ) . substring ( 1 ) ) . getBoundingClientRect ( ) ;
95+ if ( boundingRect . top <= 55 && boundingRect . bottom >= 0 ) {
96+ elements . forEach ( function ( elem ) {
97+ elem . classList . remove ( 'active' ) ;
98+ } ) ;
99+ element . classList . add ( 'active' ) ;
100+ }
81101 } ) ;
82102 } ) ;
83103}
@@ -97,10 +117,10 @@ function toggleHeaderShadow(scrollY) {
97117function setThemeByUserPref ( ) {
98118 darkThemeCss = document . getElementById ( "dark-theme" ) ;
99119 const savedTheme = localStorage . getItem ( THEME_PREF_STORAGE_KEY ) ||
100- ( window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches ? 'dark' : 'light' ) ;
120+ ( window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches ? 'dark' : 'light' ) ;
101121 const darkThemeToggles = document . querySelectorAll ( '.dark-theme-toggle' ) ;
102122 setTheme ( savedTheme , darkThemeToggles ) ;
103- darkThemeToggles . forEach ( el => el . addEventListener ( 'click' , toggleTheme , { capture : true } ) )
123+ darkThemeToggles . forEach ( el => el . addEventListener ( 'click' , toggleTheme , { capture : true } ) )
104124}
105125
106126function toggleTheme ( event ) {
0 commit comments