UNPKG

preline

Version:

Preline UI is an open-source set of prebuilt UI components based on the utility-first Tailwind CSS framework.

16 lines 8.61 kB
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var o=e();for(var l in o)("object"==typeof exports?exports:t)[l]=o[l]}}(self,(()=>(()=>{"use strict";var t={292:function(t,e){ /* * @version: 3.2.3 * @author: Preline Labs Ltd. * @license: Licensed under MIT and Preline UI Fair Use License (https://preline.co/docs/license.html) * Copyright 2024 Preline Labs Ltd. */ Object.defineProperty(e,"__esModule",{value:!0}),e.stringToBoolean=e.menuSearchHistory=e.isScrollable=e.isParentOrElementHidden=e.isJson=e.isIpadOS=e.isIOS=e.isFormElement=e.isFocused=e.isEnoughSpace=e.isDirectChild=e.htmlToElement=e.getZIndex=e.getHighestZIndex=e.getClassPropertyAlt=e.getClassProperty=e.dispatch=e.debounce=e.classToClassList=e.afterTransition=void 0;e.stringToBoolean=t=>"true"===t;e.getClassProperty=(t,e,o="")=>(window.getComputedStyle(t).getPropertyValue(e)||o).replace(" ","");e.getClassPropertyAlt=(t,e,o="")=>{let l="";return t.classList.forEach((t=>{t.includes(e)&&(l=t)})),l.match(/:(.*)]/)?l.match(/:(.*)]/)[1]:o};const o=t=>window.getComputedStyle(t).getPropertyValue("z-index");e.getZIndex=o;e.getHighestZIndex=t=>{let e=Number.NEGATIVE_INFINITY;return t.forEach((t=>{let l=o(t);"auto"!==l&&(l=parseInt(l,10),l>e&&(e=l))})),e};e.isDirectChild=(t,e)=>{const o=t.children;for(let t=0;t<o.length;t++)if(o[t]===e)return!0;return!1};e.isEnoughSpace=(t,e,o="auto",l=10,s=null)=>{const i=e.getBoundingClientRect(),r=s?s.getBoundingClientRect():null,n=window.innerHeight,c=r?i.top-r.top:i.top,a=(s?r.bottom:n)-i.bottom,h=t.clientHeight+l;return"bottom"===o?a>=h:"top"===o?c>=h:c>=h||a>=h};e.isFocused=t=>document.activeElement===t;e.isFormElement=t=>t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement;e.isIOS=()=>!!/iPad|iPhone|iPod/.test(navigator.platform)||navigator.maxTouchPoints&&navigator.maxTouchPoints>2&&/MacIntel/.test(navigator.platform);e.isIpadOS=()=>navigator.maxTouchPoints&&navigator.maxTouchPoints>2&&/MacIntel/.test(navigator.platform);e.isJson=t=>{if("string"!=typeof t)return!1;const e=t.trim()[0],o=t.trim().slice(-1);if("{"===e&&"}"===o||"["===e&&"]"===o)try{return JSON.parse(t),!0}catch(t){return!1}return!1};const l=t=>{if(!t)return!1;return"none"===window.getComputedStyle(t).display||l(t.parentElement)};e.isParentOrElementHidden=l;e.isScrollable=t=>{const e=window.getComputedStyle(t),o=e.overflowY,l=e.overflowX,s=("scroll"===o||"auto"===o)&&t.scrollHeight>t.clientHeight,i=("scroll"===l||"auto"===l)&&t.scrollWidth>t.clientWidth;return s||i};e.debounce=(t,e=200)=>{let o;return(...l)=>{clearTimeout(o),o=setTimeout((()=>{t.apply(this,l)}),e)}};e.dispatch=(t,e,o=null)=>{const l=new CustomEvent(t,{detail:{payload:o},bubbles:!0,cancelable:!0,composed:!1});e.dispatchEvent(l)};e.afterTransition=(t,e)=>{const o=()=>{e(),t.removeEventListener("transitionend",o,!0)},l=window.getComputedStyle(t),s=l.getPropertyValue("transition-duration");"none"!==l.getPropertyValue("transition-property")&&parseFloat(s)>0?t.addEventListener("transitionend",o,!0):e()};e.htmlToElement=t=>{const e=document.createElement("template");return t=t.trim(),e.innerHTML=t,e.content.firstChild};e.classToClassList=(t,e,o=" ",l="add")=>{t.split(o).forEach((t=>{t.trim()&&("add"===l?e.classList.add(t):e.classList.remove(t))}))};const s={historyIndex:-1,addHistory(t){this.historyIndex=t},existsInHistory(t){return t>this.historyIndex},clearHistory(){this.historyIndex=-1}};e.menuSearchHistory=s},751:function(t,e,o){ /* * HSScrollspy * @version: 3.2.3 * @author: Preline Labs Ltd. * @license: Licensed under MIT and Preline UI Fair Use License (https://preline.co/docs/license.html) * Copyright 2024 Preline Labs Ltd. */ var l=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const s=o(292),i=l(o(961));class r extends i.default{constructor(t,e={}){super(t,e),this.isScrollingDown=!1,this.lastScrollTop=0;const o=t.getAttribute("data-hs-scrollspy-options"),l=o?JSON.parse(o):{},s=Object.assign(Object.assign({},l),e);this.ignoreScrollUp=void 0!==s.ignoreScrollUp&&s.ignoreScrollUp,this.links=this.el.querySelectorAll("[href]"),this.sections=[],this.scrollableId=this.el.getAttribute("data-hs-scrollspy-scrollable-parent"),this.scrollable=this.scrollableId?document.querySelector(this.scrollableId):document,this.onLinkClickListener=[],this.init()}scrollableScroll(t){const e=this.scrollable instanceof HTMLElement?this.scrollable.scrollTop:window.scrollY;this.isScrollingDown=e>this.lastScrollTop,this.lastScrollTop=e<=0?0:e,Array.from(this.sections).forEach((e=>{if(!e.getAttribute("id"))return!1;this.update(t,e)}))}init(){this.createCollection(window.$hsScrollspyCollection,this),this.links.forEach((t=>{this.sections.push(this.scrollable.querySelector(t.getAttribute("href")))})),this.onScrollableScrollListener=t=>this.scrollableScroll(t),this.scrollable.addEventListener("scroll",this.onScrollableScrollListener),this.links.forEach((t=>{this.onLinkClickListener.push({el:t,fn:e=>this.linkClick(e,t)}),t.addEventListener("click",this.onLinkClickListener.find((e=>e.el===t)).fn)}))}determineScrollDirection(t){const e=this.el.querySelector("a.active");if(!e)return!0;const o=Array.from(this.links).indexOf(e),l=Array.from(this.links).indexOf(t);return-1===l||l>o}linkClick(t,e){t.preventDefault();const o=e.getAttribute("href");if(!o||"javascript:;"===o)return;(o?document.querySelector(o):null)&&(this.isScrollingDown=this.determineScrollDirection(e),this.scrollTo(e))}update(t,e){const o=parseInt((0,s.getClassProperty)(this.el,"--scrollspy-offset","0")),l=parseInt((0,s.getClassProperty)(e,"--scrollspy-offset"))||o,i=t.target===document?0:parseInt(String(t.target.getBoundingClientRect().top)),r=parseInt(String(e.getBoundingClientRect().top))-l-i,n=e.offsetHeight;if(this.ignoreScrollUp||this.isScrollingDown?r<=0&&r+n>0:r<=0&&r<n){this.links.forEach((t=>t.classList.remove("active")));const t=this.el.querySelector(`[href="#${e.getAttribute("id")}"]`);if(t){t.classList.add("active");const e=t.closest("[data-hs-scrollspy-group]");if(e){const t=e.querySelector("[href]");t&&t.classList.add("active")}}this.fireEvent("afterScroll",t),(0,s.dispatch)("afterScroll.hs.scrollspy",t,this.el)}}scrollTo(t){const e=t.getAttribute("href"),o=document.querySelector(e),l=parseInt((0,s.getClassProperty)(this.el,"--scrollspy-offset","0")),i=parseInt((0,s.getClassProperty)(o,"--scrollspy-offset"))||l,r=this.scrollable===document?0:this.scrollable.offsetTop,n=o.offsetTop-i-r,c=this.scrollable===document?window:this.scrollable,a=()=>{window.history.replaceState(null,null,t.getAttribute("href")),"scrollTo"in c&&c.scrollTo({top:n,left:0,behavior:"smooth"})},h=this.fireEvent("beforeScroll",this.el);(0,s.dispatch)("beforeScroll.hs.scrollspy",this.el,this.el),h instanceof Promise?h.then((()=>a())):a()}destroy(){this.el.querySelector("[href].active").classList.remove("active"),this.scrollable.removeEventListener("scroll",this.onScrollableScrollListener),this.onLinkClickListener.length&&this.onLinkClickListener.forEach((({el:t,fn:e})=>{t.removeEventListener("click",e)})),window.$hsScrollspyCollection=window.$hsScrollspyCollection.filter((({element:t})=>t.el!==this.el))}static getInstance(t,e=!1){const o=window.$hsScrollspyCollection.find((e=>e.element.el===("string"==typeof t?document.querySelector(t):t)));return o?e?o:o.element.el:null}static autoInit(){window.$hsScrollspyCollection||(window.$hsScrollspyCollection=[]),window.$hsScrollspyCollection&&(window.$hsScrollspyCollection=window.$hsScrollspyCollection.filter((({element:t})=>document.contains(t.el)))),document.querySelectorAll("[data-hs-scrollspy]:not(.--prevent-on-load-init)").forEach((t=>{window.$hsScrollspyCollection.find((e=>{var o;return(null===(o=null==e?void 0:e.element)||void 0===o?void 0:o.el)===t}))||new r(t)}))}}window.addEventListener("load",(()=>{r.autoInit()})),"undefined"!=typeof window&&(window.HSScrollspy=r),e.default=r},961:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0});e.default=class{constructor(t,e,o){this.el=t,this.options=e,this.events=o,this.el=t,this.options=e,this.events={}}createCollection(t,e){var o;t.push({id:(null===(o=null==e?void 0:e.el)||void 0===o?void 0:o.id)||t.length+1,element:e})}fireEvent(t,e=null){if(this.events.hasOwnProperty(t))return this.events[t](e)}on(t,e){this.events[t]=e}}}},e={};var o=function o(l){var s=e[l];if(void 0!==s)return s.exports;var i=e[l]={exports:{}};return t[l].call(i.exports,i,i.exports,o),i.exports}(751);return o})()));