/**
 * Theme: theme-Serenity
 * Author: Serenity
 * Build: 2026-04-12 21:46:28
 * Fingerprint: 3d12f6e686831ac7
 * Copyright © 2026 Serenity. All rights reserved.
 * Unauthorized copying or distribution is prohibited.
 */
(function(){'use strict';var _stickyScrollHandlers=[];function initStickySidebar(){const sidebars=document.querySelectorAll('.post-sidebar,.archive-sidebar,.tags-stats-card');if(!sidebars.length)return;const header=document.querySelector('.header');const headerHeight=header?header.offsetHeight:64;const topOffset=headerHeight+16;sidebars.forEach(function(sidebar){if(sidebar.dataset.stickyInit==='true')return;sidebar.dataset.stickyInit='true';const parent=sidebar.closest('.post-layout,.archive-layout,.tags-layout');if(!parent)return;parent.style.position='relative';const originalWidth=sidebar.offsetWidth;const sidebarRect=sidebar.getBoundingClientRect();const originalLeft=sidebarRect.left;const originalTop=sidebarRect.top+window.pageYOffset;let isFixed=false;function updateSidebar(){const scrollY=window.pageYOffset||document.documentElement.scrollTop;const parentRect=parent.getBoundingClientRect();const parentTop=parentRect.top+scrollY;const parentBottom=parentRect.bottom+scrollY;const sidebarHeight=sidebar.offsetHeight;const startFixed=originalTop-topOffset;const stopFixed=parentBottom-sidebarHeight;if(scrollY>startFixed&&scrollY<stopFixed-topOffset){if(!isFixed){sidebar.style.position='fixed';sidebar.style.top=topOffset+'px';sidebar.style.left=originalLeft+'px';sidebar.style.width=originalWidth+'px';sidebar.style.zIndex='100';isFixed=true;}}else if(scrollY>=stopFixed-topOffset){sidebar.style.position='absolute';sidebar.style.top=(stopFixed-parentTop)+'px';sidebar.style.left='';sidebar.style.right='0';sidebar.style.width=originalWidth+'px';sidebar.style.zIndex='100';isFixed=false;}else{if(isFixed||sidebar.style.position==='absolute'){sidebar.style.position='';sidebar.style.top='';sidebar.style.left='';sidebar.style.right='';sidebar.style.width='';sidebar.style.zIndex='';isFixed=false;}}}let ticking=false;function onScroll(){if(!ticking){requestAnimationFrame(function(){updateSidebar();ticking=false;});ticking=true;}}window.addEventListener('scroll',onScroll,{passive:true});_stickyScrollHandlers.push(onScroll);setTimeout(updateSidebar,100);});}function resetSidebars(){_stickyScrollHandlers.forEach(function(fn){window.removeEventListener('scroll',fn);});_stickyScrollHandlers=[];const sidebars=document.querySelectorAll('.post-sidebar,.archive-sidebar,.tags-stats-card');sidebars.forEach(function(sidebar){sidebar.style.position='';sidebar.style.top='';sidebar.style.left='';sidebar.style.right='';sidebar.style.width='';sidebar.style.zIndex='';sidebar.dataset.stickyInit='';});}if(document.readyState==='loading'){document.addEventListener('DOMContentLoaded',function(){setTimeout(initStickySidebar,200);});}else{setTimeout(initStickySidebar,200);}let resizeTimer;window.addEventListener('resize',function(){clearTimeout(resizeTimer);resizeTimer=setTimeout(function(){resetSidebars();initStickySidebar();},250);});window.addEventListener('pageshow',function(event){if(event.persisted){resetSidebars();setTimeout(initStickySidebar,200);}});document.addEventListener('visibilitychange',function(){if(document.visibilityState==='visible'){resetSidebars();setTimeout(initStickySidebar,200);}});window.initSidebarSticky=function(){resetSidebars();setTimeout(initStickySidebar,200);};})();