UNPKG

@rero/rero-ils-ui

Version:

User interface for RERO integrated library system (RERO ILS).

16 lines (15 loc) 16.5 kB
import{B as E,C as v,h as m,z as S}from"./chunk-FRI676LD.js";var W=(()=>{class b{static zindex=1e3;static calculatedScrollbarWidth=null;static calculatedScrollbarHeight=null;static browser;static addClass(t,e){t&&e&&(t.classList?t.classList.add(e):t.className+=" "+e)}static addMultipleClasses(t,e){if(t&&e)if(t.classList){let i=e.trim().split(" ");for(let n=0;n<i.length;n++)t.classList.add(i[n])}else{let i=e.split(" ");for(let n=0;n<i.length;n++)t.className+=" "+i[n]}}static removeClass(t,e){t&&e&&(t.classList?t.classList.remove(e):t.className=t.className.replace(new RegExp("(^|\\b)"+e.split(" ").join("|")+"(\\b|$)","gi")," "))}static removeMultipleClasses(t,e){t&&e&&[e].flat().filter(Boolean).forEach(i=>i.split(" ").forEach(n=>this.removeClass(t,n)))}static hasClass(t,e){return t&&e?t.classList?t.classList.contains(e):new RegExp("(^| )"+e+"( |$)","gi").test(t.className):!1}static siblings(t){return Array.prototype.filter.call(t.parentNode.children,function(e){return e!==t})}static find(t,e){return Array.from(t.querySelectorAll(e))}static findSingle(t,e){return this.isElement(t)?t.querySelector(e):null}static index(t){let e=t.parentNode.childNodes,i=0;for(var n=0;n<e.length;n++){if(e[n]==t)return i;e[n].nodeType==1&&i++}return-1}static indexWithinGroup(t,e){let i=t.parentNode?t.parentNode.childNodes:[],n=0;for(var o=0;o<i.length;o++){if(i[o]==t)return n;i[o].attributes&&i[o].attributes[e]&&i[o].nodeType==1&&n++}return-1}static appendOverlay(t,e,i="self"){i!=="self"&&t&&e&&this.appendChild(t,e)}static alignOverlay(t,e,i="self",n=!0){t&&e&&(n&&(t.style.minWidth=`${b.getOuterWidth(e)}px`),i==="self"?this.relativePosition(t,e):this.absolutePosition(t,e))}static relativePosition(t,e,i=!0){let n=g=>{if(g)return getComputedStyle(g).getPropertyValue("position")==="relative"?g:n(g.parentElement)},o=t.offsetParent?{width:t.offsetWidth,height:t.offsetHeight}:this.getHiddenElementDimensions(t),s=e.offsetHeight,l=e.getBoundingClientRect(),c=this.getWindowScrollTop(),r=this.getWindowScrollLeft(),a=this.getViewport(),d=n(t)?.getBoundingClientRect()||{top:-1*c,left:-1*r},h,p,y="top";l.top+s+o.height>a.height?(h=l.top-d.top-o.height,y="bottom",l.top+h<0&&(h=-1*l.top)):(h=s+l.top-d.top,y="top");let w=l.left+o.width-a.width,C=l.left-d.left;if(o.width>a.width?p=(l.left-d.left)*-1:w>0?p=C-w:p=l.left-d.left,t.style.top=h+"px",t.style.left=p+"px",t.style.transformOrigin=y,i){let g=v(/-anchor-gutter$/)?.value;t.style.marginTop=y==="bottom"?`calc(${g??"2px"} * -1)`:g??""}}static absolutePosition(t,e,i=!0){let n=t.offsetParent?{width:t.offsetWidth,height:t.offsetHeight}:this.getHiddenElementDimensions(t),o=n.height,s=n.width,l=e.offsetHeight,c=e.offsetWidth,r=e.getBoundingClientRect(),a=this.getWindowScrollTop(),u=this.getWindowScrollLeft(),d=this.getViewport(),h,p;r.top+l+o>d.height?(h=r.top+a-o,t.style.transformOrigin="bottom",h<0&&(h=a)):(h=l+r.top+a,t.style.transformOrigin="top"),r.left+s>d.width?p=Math.max(0,r.left+u+c-s):p=r.left+u,t.style.top=h+"px",t.style.left=p+"px",i&&(t.style.marginTop=origin==="bottom"?"calc(var(--p-anchor-gutter) * -1)":"calc(var(--p-anchor-gutter))")}static getParents(t,e=[]){return t.parentNode===null?e:this.getParents(t.parentNode,e.concat([t.parentNode]))}static getScrollableParents(t){let e=[];if(t){let i=this.getParents(t),n=/(auto|scroll)/,o=s=>{let l=window.getComputedStyle(s,null);return n.test(l.getPropertyValue("overflow"))||n.test(l.getPropertyValue("overflowX"))||n.test(l.getPropertyValue("overflowY"))};for(let s of i){let l=s.nodeType===1&&s.dataset.scrollselectors;if(l){let c=l.split(",");for(let r of c){let a=this.findSingle(s,r);a&&o(a)&&e.push(a)}}s.nodeType!==9&&o(s)&&e.push(s)}}return e}static getHiddenElementOuterHeight(t){t.style.visibility="hidden",t.style.display="block";let e=t.offsetHeight;return t.style.display="none",t.style.visibility="visible",e}static getHiddenElementOuterWidth(t){t.style.visibility="hidden",t.style.display="block";let e=t.offsetWidth;return t.style.display="none",t.style.visibility="visible",e}static getHiddenElementDimensions(t){let e={};return t.style.visibility="hidden",t.style.display="block",e.width=t.offsetWidth,e.height=t.offsetHeight,t.style.display="none",t.style.visibility="visible",e}static scrollInView(t,e){let i=getComputedStyle(t).getPropertyValue("borderTopWidth"),n=i?parseFloat(i):0,o=getComputedStyle(t).getPropertyValue("paddingTop"),s=o?parseFloat(o):0,l=t.getBoundingClientRect(),r=e.getBoundingClientRect().top+document.body.scrollTop-(l.top+document.body.scrollTop)-n-s,a=t.scrollTop,u=t.clientHeight,d=this.getOuterHeight(e);r<0?t.scrollTop=a+r:r+d>u&&(t.scrollTop=a+r-u+d)}static fadeIn(t,e){t.style.opacity=0;let i=+new Date,n=0,o=function(){n=+t.style.opacity.replace(",",".")+(new Date().getTime()-i)/e,t.style.opacity=n,i=+new Date,+n<1&&(window.requestAnimationFrame?window.requestAnimationFrame(o):setTimeout(o,16))};o()}static fadeOut(t,e){var i=1,n=50,o=e,s=n/o;let l=setInterval(()=>{i=i-s,i<=0&&(i=0,clearInterval(l)),t.style.opacity=i},n)}static getWindowScrollTop(){let t=document.documentElement;return(window.pageYOffset||t.scrollTop)-(t.clientTop||0)}static getWindowScrollLeft(){let t=document.documentElement;return(window.pageXOffset||t.scrollLeft)-(t.clientLeft||0)}static matches(t,e){var i=Element.prototype,n=i.matches||i.webkitMatchesSelector||i.mozMatchesSelector||i.msMatchesSelector||function(o){return[].indexOf.call(document.querySelectorAll(o),this)!==-1};return n.call(t,e)}static getOuterWidth(t,e){let i=t.offsetWidth;if(e){let n=getComputedStyle(t);i+=parseFloat(n.marginLeft)+parseFloat(n.marginRight)}return i}static getHorizontalPadding(t){let e=getComputedStyle(t);return parseFloat(e.paddingLeft)+parseFloat(e.paddingRight)}static getHorizontalMargin(t){let e=getComputedStyle(t);return parseFloat(e.marginLeft)+parseFloat(e.marginRight)}static innerWidth(t){let e=t.offsetWidth,i=getComputedStyle(t);return e+=parseFloat(i.paddingLeft)+parseFloat(i.paddingRight),e}static width(t){let e=t.offsetWidth,i=getComputedStyle(t);return e-=parseFloat(i.paddingLeft)+parseFloat(i.paddingRight),e}static getInnerHeight(t){let e=t.offsetHeight,i=getComputedStyle(t);return e+=parseFloat(i.paddingTop)+parseFloat(i.paddingBottom),e}static getOuterHeight(t,e){let i=t.offsetHeight;if(e){let n=getComputedStyle(t);i+=parseFloat(n.marginTop)+parseFloat(n.marginBottom)}return i}static getHeight(t){let e=t.offsetHeight,i=getComputedStyle(t);return e-=parseFloat(i.paddingTop)+parseFloat(i.paddingBottom)+parseFloat(i.borderTopWidth)+parseFloat(i.borderBottomWidth),e}static getWidth(t){let e=t.offsetWidth,i=getComputedStyle(t);return e-=parseFloat(i.paddingLeft)+parseFloat(i.paddingRight)+parseFloat(i.borderLeftWidth)+parseFloat(i.borderRightWidth),e}static getViewport(){let t=window,e=document,i=e.documentElement,n=e.getElementsByTagName("body")[0],o=t.innerWidth||i.clientWidth||n.clientWidth,s=t.innerHeight||i.clientHeight||n.clientHeight;return{width:o,height:s}}static getOffset(t){var e=t.getBoundingClientRect();return{top:e.top+(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0),left:e.left+(window.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft||0)}}static replaceElementWith(t,e){let i=t.parentNode;if(!i)throw"Can't replace element";return i.replaceChild(e,t)}static getUserAgent(){if(navigator&&this.isClient())return navigator.userAgent}static isIE(){var t=window.navigator.userAgent,e=t.indexOf("MSIE ");if(e>0)return!0;var i=t.indexOf("Trident/");if(i>0){var n=t.indexOf("rv:");return!0}var o=t.indexOf("Edge/");return o>0}static isIOS(){return/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream}static isAndroid(){return/(android)/i.test(navigator.userAgent)}static isTouchDevice(){return"ontouchstart"in window||navigator.maxTouchPoints>0}static appendChild(t,e){if(this.isElement(e))e.appendChild(t);else if(e&&e.el&&e.el.nativeElement)e.el.nativeElement.appendChild(t);else throw"Cannot append "+e+" to "+t}static removeChild(t,e){if(this.isElement(e))e.removeChild(t);else if(e.el&&e.el.nativeElement)e.el.nativeElement.removeChild(t);else throw"Cannot remove "+t+" from "+e}static removeElement(t){"remove"in Element.prototype?t.remove():t.parentNode?.removeChild(t)}static isElement(t){return typeof HTMLElement=="object"?t instanceof HTMLElement:t&&typeof t=="object"&&t!==null&&t.nodeType===1&&typeof t.nodeName=="string"}static calculateScrollbarWidth(t){if(t){let e=getComputedStyle(t);return t.offsetWidth-t.clientWidth-parseFloat(e.borderLeftWidth)-parseFloat(e.borderRightWidth)}else{if(this.calculatedScrollbarWidth!==null)return this.calculatedScrollbarWidth;let e=document.createElement("div");e.className="p-scrollbar-measure",document.body.appendChild(e);let i=e.offsetWidth-e.clientWidth;return document.body.removeChild(e),this.calculatedScrollbarWidth=i,i}}static calculateScrollbarHeight(){if(this.calculatedScrollbarHeight!==null)return this.calculatedScrollbarHeight;let t=document.createElement("div");t.className="p-scrollbar-measure",document.body.appendChild(t);let e=t.offsetHeight-t.clientHeight;return document.body.removeChild(t),this.calculatedScrollbarWidth=e,e}static invokeElementMethod(t,e,i){t[e].apply(t,i)}static clearSelection(){if(window.getSelection&&window.getSelection())window.getSelection()?.empty?window.getSelection()?.empty():window.getSelection()?.removeAllRanges&&(window.getSelection()?.rangeCount||0)>0&&(window.getSelection()?.getRangeAt(0)?.getClientRects()?.length||0)>0&&window.getSelection()?.removeAllRanges();else if(document.selection&&document.selection.empty)try{document.selection.empty()}catch{}}static getBrowser(){if(!this.browser){let t=this.resolveUserAgent();this.browser={},t.browser&&(this.browser[t.browser]=!0,this.browser.version=t.version),this.browser.chrome?this.browser.webkit=!0:this.browser.webkit&&(this.browser.safari=!0)}return this.browser}static resolveUserAgent(){let t=navigator.userAgent.toLowerCase(),e=/(chrome)[ \/]([\w.]+)/.exec(t)||/(webkit)[ \/]([\w.]+)/.exec(t)||/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(t)||/(msie) ([\w.]+)/.exec(t)||t.indexOf("compatible")<0&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(t)||[];return{browser:e[1]||"",version:e[2]||"0"}}static isInteger(t){return Number.isInteger?Number.isInteger(t):typeof t=="number"&&isFinite(t)&&Math.floor(t)===t}static isHidden(t){return!t||t.offsetParent===null}static isVisible(t){return t&&t.offsetParent!=null}static isExist(t){return t!==null&&typeof t<"u"&&t.nodeName&&t.parentNode}static focus(t,e){t&&document.activeElement!==t&&t.focus(e)}static getFocusableSelectorString(t=""){return`button:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden])${t}, [href][clientHeight][clientWidth]:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden])${t}, input:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden])${t}, select:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden])${t}, textarea:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden])${t}, [tabIndex]:not([tabIndex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden])${t}, [contenteditable]:not([tabIndex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden])${t}, .p-inputtext:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden])${t}, .p-button:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden])${t}`}static getFocusableElements(t,e=""){let i=this.find(t,this.getFocusableSelectorString(e)),n=[];for(let o of i){let s=getComputedStyle(o);this.isVisible(o)&&s.display!="none"&&s.visibility!="hidden"&&n.push(o)}return n}static getFocusableElement(t,e=""){let i=this.findSingle(t,this.getFocusableSelectorString(e));if(i){let n=getComputedStyle(i);if(this.isVisible(i)&&n.display!="none"&&n.visibility!="hidden")return i}return null}static getFirstFocusableElement(t,e=""){let i=this.getFocusableElements(t,e);return i.length>0?i[0]:null}static getLastFocusableElement(t,e){let i=this.getFocusableElements(t,e);return i.length>0?i[i.length-1]:null}static getNextFocusableElement(t,e=!1){let i=b.getFocusableElements(t),n=0;if(i&&i.length>0){let o=i.indexOf(i[0].ownerDocument.activeElement);e?o==-1||o===0?n=i.length-1:n=o-1:o!=-1&&o!==i.length-1&&(n=o+1)}return i[n]}static generateZIndex(){return this.zindex=this.zindex||999,++this.zindex}static getSelection(){return window.getSelection?window.getSelection()?.toString():document.getSelection?document.getSelection()?.toString():document.selection?document.selection.createRange().text:null}static getTargetElement(t,e){if(!t)return null;switch(t){case"document":return document;case"window":return window;case"@next":return e?.nextElementSibling;case"@prev":return e?.previousElementSibling;case"@parent":return e?.parentElement;case"@grandparent":return e?.parentElement?.parentElement;default:let i=typeof t;if(i==="string")return document.querySelector(t);if(i==="object"&&t.hasOwnProperty("nativeElement"))return this.isExist(t.nativeElement)?t.nativeElement:void 0;let o=(s=>!!(s&&s.constructor&&s.call&&s.apply))(t)?t():t;return o&&o.nodeType===9||this.isExist(o)?o:null}}static isClient(){return!!(typeof window<"u"&&window.document&&window.document.createElement)}static getAttribute(t,e){if(t){let i=t.getAttribute(e);return isNaN(i)?i==="true"||i==="false"?i==="true":i:+i}}static calculateBodyScrollbarWidth(){return window.innerWidth-document.documentElement.offsetWidth}static blockBodyScroll(t="p-overflow-hidden"){document.body.style.setProperty("--scrollbar-width",this.calculateBodyScrollbarWidth()+"px"),this.addClass(document.body,t)}static unblockBodyScroll(t="p-overflow-hidden"){document.body.style.removeProperty("--scrollbar-width"),this.removeClass(document.body,t)}static createElement(t,e={},...i){if(t){let n=document.createElement(t);return this.setAttributes(n,e),n.append(...i),n}}static setAttribute(t,e="",i){this.isElement(t)&&i!==null&&i!==void 0&&t.setAttribute(e,i)}static setAttributes(t,e={}){if(this.isElement(t)){let i=(n,o)=>{let s=t?.$attrs?.[n]?[t?.$attrs?.[n]]:[];return[o].flat().reduce((l,c)=>{if(c!=null){let r=typeof c;if(r==="string"||r==="number")l.push(c);else if(r==="object"){let a=Array.isArray(c)?i(n,c):Object.entries(c).map(([u,d])=>n==="style"&&(d||d===0)?`${u.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}:${d}`:d?u:void 0);l=a.length?l.concat(a.filter(u=>!!u)):l}}return l},s)};Object.entries(e).forEach(([n,o])=>{if(o!=null){let s=n.match(/^on(.+)/);s?t.addEventListener(s[1].toLowerCase(),o):n==="pBind"?this.setAttributes(t,o):(o=n==="class"?[...new Set(i("class",o))].join(" ").trim():n==="style"?i("style",o).join(";").trim():o,(t.$attrs=t.$attrs||{})&&(t.$attrs[n]=o),t.setAttribute(n,o))}})}}static isFocusableElement(t,e=""){return this.isElement(t)?t.matches(`button:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden])${e}, [href][clientHeight][clientWidth]:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden])${e}, input:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden])${e}, select:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden])${e}, textarea:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden])${e}, [tabIndex]:not([tabIndex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden])${e}, [contenteditable]:not([tabIndex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden])${e}`):!1}}return b})();function L(){S({variableName:m("scrollbar.width").name})}function O(){E({variableName:m("scrollbar.width").name})}var x=class{element;listener;scrollableParents;constructor(f,t=()=>{}){this.element=f,this.listener=t}bindScrollListener(){this.scrollableParents=W.getScrollableParents(this.element);for(let f=0;f<this.scrollableParents.length;f++)this.scrollableParents[f].addEventListener("scroll",this.listener)}unbindScrollListener(){if(this.scrollableParents)for(let f=0;f<this.scrollableParents.length;f++)this.scrollableParents[f].removeEventListener("scroll",this.listener)}destroy(){this.unbindScrollListener(),this.element=null,this.listener=null,this.scrollableParents=null}};export{W as a,L as b,O as c,x as d};