UNPKG

@dialpad/dialtone-vue

Version:

Vue component library for Dialpad's design system Dialtone

3 lines (2 loc) 1.38 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a={methods:{scrollElementIntoViewIfNeeded(e,l,t,o){e.scrollIntoViewIfNeeded?this.scrollIntoViewIfNeeded(e,l,t,o):this.scrollIntoView(e,"bottom",!1,t,o)},scrollElementIntoView(e,l,t,o){if(l==="center"){this.scrollIntoView(e,"center",!1,t,o);return}l===!1?this.scrollIntoView(e,"bottom",!1,t,o):this.scrollIntoView(e,"top",!1,t,o)},scrollIntoViewIfNeeded(e,l,t,o){const n=l?"center":void 0;this.scrollIntoView(e,n,!0,t,o)},scrollIntoView(e,l,t,o,n){if(!e||!e.parentElement)return;const s=e.offsetTop,r=n||e.parentElement,c=this._getScrollBounds(r),h=c.bottom-c.top,d=this._getElementHeight(e),g=s+d;let i=-1;switch(l){case"top":i=s;break;case"center":i=s+(d-h)/2;break;case"bottom":i=i=g-h;break;default:s-c.top<=h/2?i=s:i=g-h;break}this._setScrollTop(r,i,c,s,g,t,o)},_setScrollTop(e,l,t,o,n,s,r){t=t||this._getScrollBounds(e);const c=t.bottom-t.top;if(s&&this._inScrollBounds(o,n,t))if(o<t.top)l=o;else if(n>t.bottom)l=n-c;else return;r?e.scrollTo({top:l,behavior:r}):e.scrollTop=l},_getElementHeight(e){return e.getBoundingClientRect().height},_getScrollBounds(e){const l=this._getElementHeight(e),t=e.scrollTop;return{top:t,bottom:t+l}},_inScrollBounds(e,l,t){const o=l-e;return l<=t.bottom+3*o/4&&e>=t.top-o/4}}};exports.default=a; //# sourceMappingURL=dom.cjs.map