import{E as EventHandler,S as SelectorEngine,d as defineJQueryPlugin,B as BaseComponent,h as getElement,j as isDisabled,i as isVisible}from"./dom.min.js?5.2.3";const NAME="scrollspy",DATA_KEY="bs.scrollspy",EVENT_KEY=`.${DATA_KEY}`,DATA_API_KEY=".data-api",EVENT_ACTIVATE=`activate${EVENT_KEY}`,EVENT_CLICK=`click${EVENT_KEY}`,EVENT_LOAD_DATA_API=`load${EVENT_KEY}.data-api`,CLASS_NAME_DROPDOWN_ITEM="dropdown-item",CLASS_NAME_ACTIVE="active",SELECTOR_DATA_SPY='[data-bs-spy="scroll"]',SELECTOR_TARGET_LINKS="[href]",SELECTOR_NAV_LIST_GROUP=".nav, .list-group",SELECTOR_NAV_LINKS=".nav-link",SELECTOR_NAV_ITEMS=".nav-item",SELECTOR_LIST_ITEMS=".list-group-item",SELECTOR_LINK_ITEMS=".nav-link, .nav-item > .nav-link, .list-group-item",SELECTOR_DROPDOWN=".dropdown",SELECTOR_DROPDOWN_TOGGLE=".dropdown-toggle",Default={offset:null,rootMargin:"0px 0px -25%",smoothScroll:!1,target:null,threshold:[.1,.5,1]},DefaultType={offset:"(number|null)",rootMargin:"string",smoothScroll:"boolean",target:"element",threshold:"array"};class ScrollSpy extends BaseComponent{constructor(t,e){super(t,e),this._targetLinks=new Map,this._observableSections=new Map,this._rootElement="visible"===getComputedStyle(this._element).overflowY?null:this._element,this._activeTarget=null,this._observer=null,this._previousScrollData={visibleEntryTop:0,parentScrollTop:0},this.refresh()}static get Default(){return Default}static get DefaultType(){return DefaultType}static get NAME(){return NAME}refresh(){this._initializeTargetsAndObservables(),this._maybeEnableSmoothScroll(),this._observer?this._observer.disconnect():this._observer=this._getNewObserver();for(const t of this._observableSections.values())this._observer.observe(t)}dispose(){this._observer.disconnect(),super.dispose()}_configAfterMerge(t){return t.target=getElement(t.target)||document.body,t.rootMargin=t.offset?`${t.offset}px 0px -30%`:t.rootMargin,"string"==typeof t.threshold&&(t.threshold=t.threshold.split(",").map((t=>Number.parseFloat(t)))),t}_maybeEnableSmoothScroll(){this._config.smoothScroll&&(EventHandler.off(this._config.target,EVENT_CLICK),EventHandler.on(this._config.target,EVENT_CLICK,"[href]",(t=>{const e=this._observableSections.get(t.target.hash);if(e){t.preventDefault();const o=this._rootElement||window,s=e.offsetTop-this._element.offsetTop;if(o.scrollTo)return void o.scrollTo({top:s,behavior:"smooth"});o.scrollTop=s}})))}_getNewObserver(){const t={root:this._rootElement,threshold:this._config.threshold,rootMargin:this._config.rootMargin};return new IntersectionObserver((t=>this._observerCallback(t)),t)}_observerCallback(t){const e=t=>this._targetLinks.get(`#${t.target.id}`),o=t=>{this._previousScrollData.visibleEntryTop=t.target.offsetTop,this._process(e(t))},s=(this._rootElement||document.documentElement).scrollTop,r=s>=this._previousScrollData.parentScrollTop;this._previousScrollData.parentScrollTop=s;for(const i of t){if(!i.isIntersecting){this._activeTarget=null,this._clearActiveClass(e(i));continue}const t=i.target.offsetTop>=this._previousScrollData.visibleEntryTop;if(r&&t){if(o(i),!s)return}else r||t||o(i)}}_initializeTargetsAndObservables(){this._targetLinks=new Map,this._observableSections=new Map;const t=SelectorEngine.find("[href]",this._config.target);for(const e of t){if(!e.hash||isDisabled(e))continue;const t=SelectorEngine.findOne(e.hash,this._element);isVisible(t)&&(this._targetLinks.set(e.hash,e),this._observableSections.set(e.hash,t))}}_process(t){this._activeTarget!==t&&(this._clearActiveClass(this._config.target),this._activeTarget=t,t.classList.add("active"),this._activateParents(t),EventHandler.trigger(this._element,EVENT_ACTIVATE,{relatedTarget:t}))}_activateParents(t){if(t.classList.contains("dropdown-item"))SelectorEngine.findOne(".dropdown-toggle",t.closest(".dropdown")).classList.add("active");else for(const e of SelectorEngine.parents(t,".nav, .list-group"))for(const t of SelectorEngine.prev(e,SELECTOR_LINK_ITEMS))t.classList.add("active")}_clearActiveClass(t){t.classList.remove("active");const e=SelectorEngine.find("[href].active",t);for(const t of e)t.classList.remove("active")}static jQueryInterface(t){return this.each((function(){const e=ScrollSpy.getOrCreateInstance(this,t);if("string"==typeof t){if(void 0===e[t]||t.startsWith("_")||"constructor"===t)throw new TypeError(`No method named "${t}"`);e[t]()}}))}}if(EventHandler.on(window,EVENT_LOAD_DATA_API,(()=>{for(const t of SelectorEngine.find(SELECTOR_DATA_SPY))ScrollSpy.getOrCreateInstance(t)})),defineJQueryPlugin(ScrollSpy),window.bootstrap=window.bootstrap||{},window.bootstrap.Scrollspy=ScrollSpy,Joomla&&Joomla.getOptions){const t=Joomla.getOptions("bootstrap.scrollspy");"object"==typeof t&&null!==t&&Object.keys(t).forEach((e=>{const o=t[e],s={offset:o.offset?o.offset:10,method:o.method?o.method:"auto"};o.target&&(s.target=o.target);const r=Array.from(document.querySelectorAll(e));r.length&&r.map((t=>new window.bootstrap.Scrollspy(t,s)))}))}export{ScrollSpy as S};