UNPKG

primevue

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/primevue.svg)](https://badge.fury.io/js/primevue) [![Discord Chat](https://img.shields.io/discord/55794023

2 lines (1 loc) 12.2 kB
class e{static innerWidth(e){let t=e.offsetWidth,i=getComputedStyle(e);return t+=parseFloat(i.paddingLeft)+parseFloat(i.paddingRight),t}static width(e){let t=e.offsetWidth,i=getComputedStyle(e);return t-=parseFloat(i.paddingLeft)+parseFloat(i.paddingRight),t}static getWindowScrollTop(){let e=document.documentElement;return(window.pageYOffset||e.scrollTop)-(e.clientTop||0)}static getWindowScrollLeft(){let e=document.documentElement;return(window.pageXOffset||e.scrollLeft)-(e.clientLeft||0)}static getOuterWidth(e,t){if(e){let i=e.offsetWidth;if(t){let t=getComputedStyle(e);i+=parseFloat(t.marginLeft)+parseFloat(t.marginRight)}return i}return 0}static getOuterHeight(e,t){if(e){let i=e.offsetHeight;if(t){let t=getComputedStyle(e);i+=parseFloat(t.marginTop)+parseFloat(t.marginBottom)}return i}return 0}static getClientHeight(e,t){if(e){let i=e.clientHeight;if(t){let t=getComputedStyle(e);i+=parseFloat(t.marginTop)+parseFloat(t.marginBottom)}return i}return 0}static getViewport(){let e=window,t=document,i=t.documentElement,l=t.getElementsByTagName("body")[0];return{width:e.innerWidth||i.clientWidth||l.clientWidth,height:e.innerHeight||i.clientHeight||l.clientHeight}}static getOffset(e){var t=e.getBoundingClientRect();return{top:t.top+(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0),left:t.left+(window.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft||0)}}static index(e){let t=e.parentNode.childNodes,i=0;for(var l=0;l<t.length;l++){if(t[l]===e)return i;1===t[l].nodeType&&i++}return-1}static addMultipleClasses(e,t){if(e.classList){let i=t.split(" ");for(let t=0;t<i.length;t++)e.classList.add(i[t])}else{let i=t.split(" ");for(let t=0;t<i.length;t++)e.className+=" "+i[t]}}static addClass(e,t){e.classList?e.classList.add(t):e.className+=" "+t}static removeClass(e,t){e.classList?e.classList.remove(t):e.className=e.className.replace(new RegExp("(^|\\b)"+t.split(" ").join("|")+"(\\b|$)","gi")," ")}static hasClass(e,t){return!!e&&(e.classList?e.classList.contains(t):new RegExp("(^| )"+t+"( |$)","gi").test(e.className))}static find(e,t){return e.querySelectorAll(t)}static findSingle(e,t){return e.querySelector(t)}static getHeight(e){let t=e.offsetHeight,i=getComputedStyle(e);return t-=parseFloat(i.paddingTop)+parseFloat(i.paddingBottom)+parseFloat(i.borderTopWidth)+parseFloat(i.borderBottomWidth),t}static getWidth(e){let t=e.offsetWidth,i=getComputedStyle(e);return t-=parseFloat(i.paddingLeft)+parseFloat(i.paddingRight)+parseFloat(i.borderLeftWidth)+parseFloat(i.borderRightWidth),t}static absolutePosition(e,t){let i,l,n=e.offsetParent?{width:e.offsetWidth,height:e.offsetHeight}:this.getHiddenElementDimensions(e),s=n.height,r=n.width,o=t.offsetHeight,a=t.offsetWidth,d=t.getBoundingClientRect(),c=this.getWindowScrollTop(),p=this.getWindowScrollLeft(),g=this.getViewport();d.top+o+s>g.height?(i=d.top+c-s,e.style.transformOrigin="bottom",i<0&&(i=c)):(i=o+d.top+c,e.style.transformOrigin="top"),l=d.left+r>g.width?Math.max(0,d.left+p+a-r):d.left+p,e.style.top=i+"px",e.style.left=l+"px"}static relativePosition(e,t){let i=e.offsetParent?{width:e.offsetWidth,height:e.offsetHeight}:this.getHiddenElementDimensions(e);const l=t.offsetHeight,n=t.getBoundingClientRect(),s=this.getViewport();let r,o;n.top+l+i.height>s.height?(r=-1*i.height,e.style.transformOrigin="bottom",n.top+r<0&&(r=-1*n.top)):(r=l,e.style.transformOrigin="top"),o=i.width>s.width?-1*n.left:n.left+i.width>s.width?-1*(n.left+i.width-s.width):0,e.style.top=r+"px",e.style.left=o+"px"}static getParents(e,t=[]){return null===e.parentNode?t:this.getParents(e.parentNode,t.concat([e.parentNode]))}static getScrollableParents(e){let t=[];if(e){let i=this.getParents(e);const l=/(auto|scroll)/,n=e=>{let t=window.getComputedStyle(e,null);return l.test(t.getPropertyValue("overflow"))||l.test(t.getPropertyValue("overflowX"))||l.test(t.getPropertyValue("overflowY"))};for(let e of i){let i=1===e.nodeType&&e.dataset.scrollselectors;if(i){let l=i.split(",");for(let i of l){let l=this.findSingle(e,i);l&&n(l)&&t.push(l)}}9!==e.nodeType&&n(e)&&t.push(e)}}return t}static getHiddenElementOuterHeight(e){e.style.visibility="hidden",e.style.display="block";let t=e.offsetHeight;return e.style.display="none",e.style.visibility="visible",t}static getHiddenElementOuterWidth(e){e.style.visibility="hidden",e.style.display="block";let t=e.offsetWidth;return e.style.display="none",e.style.visibility="visible",t}static getHiddenElementDimensions(e){var t={};return e.style.visibility="hidden",e.style.display="block",t.width=e.offsetWidth,t.height=e.offsetHeight,e.style.display="none",e.style.visibility="visible",t}static fadeIn(e,t){e.style.opacity=0;var i=+new Date,l=0,n=function(){l=+e.style.opacity+((new Date).getTime()-i)/t,e.style.opacity=l,i=+new Date,+l<1&&(window.requestAnimationFrame&&requestAnimationFrame(n)||setTimeout(n,16))};n()}static fadeOut(e,t){var i=1,l=50/t;let n=setInterval((()=>{(i-=l)<=0&&(i=0,clearInterval(n)),e.style.opacity=i}),50)}static getUserAgent(){return navigator.userAgent}static appendChild(e,t){if(this.isElement(t))t.appendChild(e);else{if(!t.el||!t.elElement)throw new Error("Cannot append "+t+" to "+e);t.elElement.appendChild(e)}}static scrollInView(e,t){let i=getComputedStyle(e).getPropertyValue("borderTopWidth"),l=i?parseFloat(i):0,n=getComputedStyle(e).getPropertyValue("paddingTop"),s=n?parseFloat(n):0,r=e.getBoundingClientRect(),o=t.getBoundingClientRect().top+document.body.scrollTop-(r.top+document.body.scrollTop)-l-s,a=e.scrollTop,d=e.clientHeight,c=this.getOuterHeight(t);o<0?e.scrollTop=a+o:o+c>d&&(e.scrollTop=a+o-d+c)}static clearSelection(){if(window.getSelection)window.getSelection().empty?window.getSelection().empty():window.getSelection().removeAllRanges&&window.getSelection().rangeCount>0&&window.getSelection().getRangeAt(0).getClientRects().length>0&&window.getSelection().removeAllRanges();else if(document.selection&&document.selection.empty)try{document.selection.empty()}catch(e){}}static calculateScrollbarWidth(){if(null!=this.calculatedScrollbarWidth)return this.calculatedScrollbarWidth;let e=document.createElement("div");e.className="p-scrollbar-measure",document.body.appendChild(e);let t=e.offsetWidth-e.clientWidth;return document.body.removeChild(e),this.calculatedScrollbarWidth=t,t}static getBrowser(){if(!this.browser){let e=this.resolveUserAgent();this.browser={},e.browser&&(this.browser[e.browser]=!0,this.browser.version=e.version),this.browser.chrome?this.browser.webkit=!0:this.browser.webkit&&(this.browser.safari=!0)}return this.browser}static resolveUserAgent(){let e=navigator.userAgent.toLowerCase(),t=/(chrome)[ ]([\w.]+)/.exec(e)||/(webkit)[ ]([\w.]+)/.exec(e)||/(opera)(?:.*version|)[ ]([\w.]+)/.exec(e)||/(msie) ([\w.]+)/.exec(e)||e.indexOf("compatible")<0&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(e)||[];return{browser:t[1]||"",version:t[2]||"0"}}static isVisible(e){return null!=e.offsetParent}static invokeElementMethod(e,t,i){e[t].apply(e,i)}static getFocusableElements(t){let i=e.find(t,'button:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden]),\n [href][clientHeight][clientWidth]:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden]),\n input:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden]), select:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden]),\n textarea:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden]), [tabIndex]:not([tabIndex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden]),\n [contenteditable]:not([tabIndex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden])'),l=[];for(let e of i)"none"!=getComputedStyle(e).display&&"hidden"!=getComputedStyle(e).visibility&&l.push(e);return l}static isClickable(e){const t=e.nodeName,i=e.parentElement&&e.parentElement.nodeName;return"INPUT"==t||"BUTTON"==t||"A"==t||"INPUT"==i||"BUTTON"==i||"A"==i||this.hasClass(e,"p-button")||this.hasClass(e.parentElement,"p-button")||this.hasClass(e.parentElement,"p-checkbox")||this.hasClass(e.parentElement,"p-radiobutton")}static applyStyle(e,t){if("string"==typeof t)e.style.cssText=this.style;else for(let i in this.style)e.style[i]=t[i]}static isIOS(){return/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream}static isAndroid(){return/(android)/i.test(navigator.userAgent)}}class t{constructor(e,t=(()=>{})){this.element=e,this.listener=t}bindScrollListener(){this.scrollableParents=e.getScrollableParents(this.element);for(let e=0;e<this.scrollableParents.length;e++)this.scrollableParents[e].addEventListener("scroll",this.listener)}unbindScrollListener(){if(this.scrollableParents)for(let e=0;e<this.scrollableParents.length;e++)this.scrollableParents[e].removeEventListener("scroll",this.listener)}destroy(){this.unbindScrollListener(),this.element=null,this.listener=null,this.scrollableParents=null}}class i{static equals(e,t,i){return i?this.resolveFieldData(e,i)===this.resolveFieldData(t,i):this.deepEquals(e,t)}static deepEquals(e,t){if(e===t)return!0;if(e&&t&&"object"==typeof e&&"object"==typeof t){var i,l,n,s=Array.isArray(e),r=Array.isArray(t);if(s&&r){if((l=e.length)!=t.length)return!1;for(i=l;0!=i--;)if(!this.deepEquals(e[i],t[i]))return!1;return!0}if(s!=r)return!1;var o=e instanceof Date,a=t instanceof Date;if(o!=a)return!1;if(o&&a)return e.getTime()==t.getTime();var d=e instanceof RegExp,c=t instanceof RegExp;if(d!=c)return!1;if(d&&c)return e.toString()==t.toString();var p=Object.keys(e);if((l=p.length)!==Object.keys(t).length)return!1;for(i=l;0!=i--;)if(!Object.prototype.hasOwnProperty.call(t,p[i]))return!1;for(i=l;0!=i--;)if(n=p[i],!this.deepEquals(e[n],t[n]))return!1;return!0}return e!=e&&t!=t}static resolveFieldData(e,t){if(e&&Object.keys(e).length&&t){if(this.isFunction(t))return t(e);if(-1===t.indexOf("."))return e[t];{let n=t.split("."),s=e;for(var i=0,l=n.length;i<l;++i){if(null==s)return null;s=s[n[i]]}return s}}return null}static isFunction(e){return!!(e&&e.constructor&&e.call&&e.apply)}static filter(e,t,i){var l=[];if(e)for(let n of e)for(let e of t)if(String(this.resolveFieldData(n,e)).toLowerCase().indexOf(i.toLowerCase())>-1){l.push(n);break}return l}static reorderArray(e,t,i){let l;if(e&&t!==i){if(i>=e.length)for(l=i-e.length;1+l--;)e.push(void 0);e.splice(i,0,e.splice(t,1)[0])}}static findIndexInList(e,t){let i=-1;if(t)for(let l=0;l<t.length;l++)if(t[l]===e){i=l;break}return i}static contains(e,t){if(null!=e&&t&&t.length)for(let i of t)if(this.equals(e,i))return!0;return!1}static insertIntoOrderedArray(e,t,i,l){if(i.length>0){let n=!1;for(let s=0;s<i.length;s++){if(this.findIndexInList(i[s],l)>t){i.splice(s,0,e),n=!0;break}}n||i.push(e)}else i.push(e)}static removeAccents(e){return e&&e.search(/[\xC0-\xFF]/g)>-1&&(e=e.replace(/[\xC0-\xC5]/g,"A").replace(/[\xC6]/g,"AE").replace(/[\xC7]/g,"C").replace(/[\xC8-\xCB]/g,"E").replace(/[\xCC-\xCF]/g,"I").replace(/[\xD0]/g,"D").replace(/[\xD1]/g,"N").replace(/[\xD2-\xD6\xD8]/g,"O").replace(/[\xD9-\xDC]/g,"U").replace(/[\xDD]/g,"Y").replace(/[\xDE]/g,"P").replace(/[\xE0-\xE5]/g,"a").replace(/[\xE6]/g,"ae").replace(/[\xE7]/g,"c").replace(/[\xE8-\xEB]/g,"e").replace(/[\xEC-\xEF]/g,"i").replace(/[\xF1]/g,"n").replace(/[\xF2-\xF6\xF8]/g,"o").replace(/[\xF9-\xFC]/g,"u").replace(/[\xFE]/g,"p").replace(/[\xFD\xFF]/g,"y")),e}}var l=function(){let e=[];const t=e=>e&&parseInt(e.style.zIndex,10)||0;return{get:t,set:(t,i,l)=>{i&&(i.style.zIndex=String(((t,i)=>{let l=e.length>0?e[e.length-1]:{key:t,value:i},n=l.value+(l.key===t?0:i)+1;return e.push({key:t,value:n}),n})(t,l)))},clear:i=>{var l;i&&(l=t(i),e=e.filter((e=>e.value!==l)),i.style.zIndex="")},getCurrent:()=>e.length>0?e[e.length-1].value:0}}(),n=0;function s(e="pv_id_"){return`${e}${++n}`}function r(){const e=new Map;return{on(t,i){let l=e.get(t);l?l.push(i):l=[i],e.set(t,l)},off(t,i){let l=e.get(t);l&&l.splice(l.indexOf(i)>>>0,1)},emit(t,i){let l=e.get(t);l&&l.slice().map((e=>{e(i)}))}}}export{t as ConnectedOverlayScrollHandler,e as DomHandler,r as EventBus,i as ObjectUtils,s as UniqueComponentId,l as ZIndexUtils};