UNPKG

13.8 kBJavaScriptView Raw
1/**
2 * Bundle of vue-scrollbar-live
3 * Generated: 2020-05-19
4 * Version: 5.7.1
5 * License: MIT
6 * Author: 2631541504@qq.com
7 */
8
9!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).VueScrollbar=e()}(this,function(){"use strict";var t=i,e=i,n=i,o=/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series[46]0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i,r=/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series[46]0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino|android|ipad|playbook|silk/i;function i(t){var e=(t=t||{}).ua;if(e||"undefined"==typeof navigator||(e=navigator.userAgent),e&&e.headers&&"string"==typeof e.headers["user-agent"]&&(e=e.headers["user-agent"]),"string"!=typeof e)return!1;var n=t.tablet?r.test(e):o.test(e);return!n&&t.tablet&&t.featureDetect&&navigator&&1<navigator.maxTouchPoints&&-1!==e.indexOf("Macintosh")&&-1!==e.indexOf("Safari")&&(n=!0),n}function s(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function c(r){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?s(Object(i),!0).forEach(function(t){var e,n,o;e=r,o=i[n=t],n in e?Object.defineProperty(e,n,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[n]=o}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(i)):s(Object(i)).forEach(function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(i,t))})}return r}function l(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var n=[],o=!0,r=!1,i=void 0;try{for(var s,l=t[Symbol.iterator]();!(o=(s=l.next()).done)&&(n.push(s.value),!e||n.length!==e);o=!0);}catch(t){r=!0,i=t}finally{try{o||null==l.return||l.return()}finally{if(r)throw i}}return n}(t,e)||function(t,e){if(!t)return;if("string"==typeof t)return a(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return a(t,e)}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=new Array(e);n<e;n++)o[n]=t[n];return o}t.isMobile=e,t.default=n,"undefined"!=typeof window&&"undefined"!=typeof document&&("onwheel"in document.createElement("div")||window.onmousewheel);var h=e(),d="",u="addEventListener",p="removeEventListener";function f(t,e,n,o){var r=d+e;return t[u].bind(t)(r,n,o),function(){t[p].bind(t)(r,n,o)}}"undefined"!=typeof window&&"undefined"!=typeof document&&("addEventListener"in window?(u="addEventListener",p="removeEventListener"):(u="attachEvent",p="detachEvent",d="on"));var m=Object.freeze({$isMobile:h,$addListener:f}),b=h?"mobile":"pc",v={start:{pc:"mousedown",mobile:"touchstart"}[b],move:{pc:"mousemove",mobile:"touchmove"}[b],end:{pc:"mouseup",mobile:"touchend"}[b]};function g(t){var e=null;if(h)if(0<t.changedTouches.length)e=l(t.changedTouches,1)[0];else if(0<t.targetTouched.length){e=l(t.changedTouches,1)[0]}else{e=l(t.touches,1)[0]}return e||t}function y(t,e){return{deltaX:g(t).clientX-g(e).clientX,deltaY:g(t).clientY-g(e).clientY,originalEvent:t}}var w=Object.freeze({bind:function(t,i,s){var l,a;return"function"==typeof t&&(s=i,i=t,t=window),f(t,v.start,function t(e){var n={deltaX:0,deltaY:0,originalEvent:e,type:"dragMoveStart"};if(e.type===v.start){l=e;var o=f(window,v.move,t,s),r=f(window,v.end,t,s);a=function(){o(),r()}}else e.type===v.move?n=c(c({},y(e,l)),{},{type:"dragMove"}):e.type===v.end&&(n=c(c({},y(e,l)),{},{type:"dragMoveEnd"}),a&&a());i(n)},s)}});function x(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function S(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}var $={x:{posPropName:"left",parentScrollPos:"scrollLeft",deltaName:"deltaX",sizeName:"width"},y:{posPropName:"top",parentScrollPos:"scrollTop",deltaName:"deltaY",sizeName:"height"}},T={opacity:1,pointerEvents:"initial"};var O=function(t,e,n,o,r,i,s,l,a,c){"boolean"!=typeof s&&(a=l,l=s,s=!1);var h,d="function"==typeof n?n.options:n;if(t&&t.render&&(d.render=t.render,d.staticRenderFns=t.staticRenderFns,d._compiled=!0,r&&(d.functional=!0)),o&&(d._scopeId=o),i?(h=function(t){(t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),e&&e.call(this,a(t)),t&&t._registeredComponents&&t._registeredComponents.add(i)},d._ssrRegister=h):e&&(h=s?function(){e.call(this,c(this.$root.$options.shadowRoot))}:function(t){e.call(this,l(t))}),h)if(d.functional){var u=d.render;d.render=function(t,e){return h.call(e),u(t,e)}}else{var p=d.beforeCreate;d.beforeCreate=p?[].concat(p,h):[h]}return n};return O({render:function(){var n=this,t=n.$createElement,o=n._self._c||t;return o("div",{ref:"wrap",staticClass:"scrollbar-wrap",style:n.$_wrapStyle,on:{click:function(t){return n.$emit("wrapClick",t)}}},[o("div",{ref:"content",staticClass:"scrollbar-content",style:n.$_contentStyle},[n._t("default")],2),n._v(" "),!n.isMobile&&n.width.content&&n.height.content?n._l(n.scrollbars,function(t,e){return o("Bar",{key:e,attrs:{type:e,marginToWrap:n.marginToWrap,parentScroll:n.scrollPos[t.scrollPropName],clientSize:t.size.content,scrollSize:t.size.contentInner},on:{scrollTo:function(t){return n.setScroll(t,"drag")}}})}):n._e()],2)},staticRenderFns:[]},void 0,{name:"Scrollbar",components:{Bar:O({render:function(){var t=this,e=t.$createElement;return(t._self._c||e)("div",{directives:[{name:"show",rawName:"v-show",value:t.$_show,expression:"$_show"}],staticClass:"scrollbar",class:"scrollbar-"+t.type,style:t.$_barStyle,attrs:{draggable:!1}})},staticRenderFns:[]},void 0,{name:"Bar",props:{type:String,parentScroll:Number,marginToWrap:{type:Number,default:5},clientSize:Number,scrollSize:Number},data:function(){return{sPosition:0,showBar:!1,unbind:null,startPosition:0}},computed:{$_show:function(){return this.scrollSize>this.clientSize},$_scrollbarType:function(){return $[this.type]},size:function(){return this.clientSize/this.scrollSize*this.clientSize-2*this.marginToWrap},positionRange:function(){return{min:this.marginToWrap,max:this.clientSize-this.marginToWrap-this.size}},$_barStyle:function(){var t;return function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?S(n,!0).forEach(function(t){x(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):S(n).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}({},this.showBar?T:{},(x(t={},this.$_scrollbarType.posPropName,"".concat(this.sPosition,"px !important")),x(t,this.$_scrollbarType.sizeName,"".concat(this.size,"px !important")),x(t,"userSelect","none"),t))}},watch:{$_show:{handler:function(t){var e=this;this.$nextTick(function(){e.unbind&&e.unbind(),t&&"undefined"!=typeof window&&e.$el&&(e.unbind=w.bind(e.$el,e.drag))})},immediate:!0},parentScroll:{handler:function(t){this.sPosition=(this.positionRange.max-this.positionRange.min)/(this.scrollSize-this.clientSize)*t+this.positionRange.min},immediate:!0}},methods:{drag:function(t){t.originalEvent.preventDefault(),"dragMoveStart"===t.type&&(this.startPosition=this.sPosition);var e=Math.min(this.positionRange.max,Math.max(this.positionRange.min,this.startPosition+t[this.$_scrollbarType.deltaName]));this.$emit("scrollTo",x({},this.$_scrollbarType.parentScrollPos,(e-this.marginToWrap)/(this.positionRange.max-this.marginToWrap)*(this.scrollSize-this.clientSize))),this.showBar="dragMoveEnd"!==t.type}},beforeDestroy:function(){this.unbind&&this.unbind()}},void 0,!1,void 0,void 0,void 0)},props:{isMobile:Boolean,maxHeight:[Number,String],scrollTo:[Number,Object],marginToWrap:{default:5,type:Number}},data:function(){return{width:{parent:0,content:0,contentInner:0},height:{parent:0,content:0,contentInner:0},scrollPos:{scrollLeft:0,scrollTop:0},isTop:!0,isBottom:!0,isLeft:!0,isRight:!0,nativeScrollbarWidth:{x:0,y:0}}},computed:{scrollbars:function(){return{x:{scrollPropName:"scrollLeft",size:this.width},y:{scrollPropName:"scrollTop",size:this.height}}},$_maxHeight:function(){var n=this;return"number"==typeof this.maxHeight?"".concat(this.maxHeight,"px"):/%/.test(this.maxHeight)?this.maxHeight.replace(/(\d+)%/g,function(t,e){return"".concat(n.height.parent*e/100,"px")}):this.maxHeight},$_wrapStyle:function(){return{position:"relative",height:this.isMobile?"auto !important":"".concat(this.height.content,"px !important"),maxHeight:"".concat(this.$_maxHeight," !important"),padding:"0 !important",overflow:"hidden !important"}},$_contentStyle:function(){if(this.isMobile)return{maxHeight:this.$_maxHeight,overflow:"scroll"};var t=this.nativeScrollbarWidth,e=t.x,n=t.y;return{width:"calc(100% + ".concat(n,"px) !important"),maxHeight:"calc(".concat(this.$_maxHeight.replace(/(^calc\()|(\)$)/g,"")," + ").concat(e,"px) !important"),overflow:"scroll"}},maxScroll:function(){return{scrollLeft:this.width.contentInner-this.width.content,scrollTop:this.height.contentInner-this.height.content}}},watch:{scrollTo:{handler:function(t){this.$scrollTo(t)},immediate:!0},isBottom:function(t){t&&this.$emit("reachBottom")},isTop:function(t){t&&this.$emit("reachTop")},isLeft:function(t){t&&this.$emit("reachLeft")},isRight:function(t){t&&this.$emit("reachRight")}},methods:{updateScrollbarWidth:function(){this.nativeScrollbarWidth=function(t){var e=t||window,n=e===window;try{var o=n?window.nativeScrollbarWidth:null;if(!o||"number"!=typeof o.y||"number"!=typeof o.x){var r=n?document.createElement("div"):e;n&&(r.setAttribute("style","position:fixed;top:0;left:0;opacity:0;pointer-events:none;width:200px;height:200px;overflow:scroll"),document.body.appendChild(r)),o={y:r.offsetWidth-r.clientWidth,x:r.offsetHeight-r.clientHeight},n&&(window.nativeScrollbarWidth=o,document.body.removeChild(r))}return o}catch(t){return{y:17,x:17}}}(this.$refs.content)},updateHeight:function(){if(this.$refs.content&&"undefined"!=typeof window){var t=this.$refs.content,e=t.scrollHeight,n=t.clientHeight,o=t.scrollWidth,r=t.clientWidth;this.height.content=n,this.height.contentInner=e,this.height.parent=this.$refs.wrap.parentElement.clientHeight,this.width.content=r,this.width.contentInner=o,this.width.parent=this.$refs.wrap.parentElement.clientWidth}},getHeight:function(){this.updateHeight()},$scrollTo:function(e){var n=this;this.$nextTick(function(){if(null!=e){var t={scrollLeft:0,scrollTop:0};e.x||e.y?(t.scrollLeft=+e.x*n.maxScroll.scrollLeft,t.scrollTop=+e.y*n.maxScroll.scrollTop):(t.scrollLeft=+e*n.maxScroll.scrollLeft,t.scrollTop=+e*n.maxScroll.scrollTop),n.setScroll(t,"drag")}})},scroll:function(t){var e=this.$refs.content,n=e.scrollTop,o=e.scrollLeft;this.setScroll({scrollTop:n,scrollLeft:o}),this.$emit("scroll",t)},setScroll:function(t,e){var n=t.scrollTop,o=t.scrollLeft,r="scroll"!==(1<arguments.length&&void 0!==e?e:"scroll");void 0!==n&&this.setPos(n,"scrollTop",r),void 0!==o&&this.setPos(o,"scrollLeft",r),this.judgeOnBoundary()},setPos:function(t,e,n){this.scrollPos[e]=t,n&&(this.$refs.content[e]=t)},judgeOnBoundary:function(){this.isTop=0===this.scrollPos.scrollTop,this.isBottom=this.scrollPos.scrollTop===this.maxScroll.scrollTop,this.isLeft=0===this.scrollPos.scrollLeft,this.isRight=this.scrollPos.scrollLeft===this.maxScroll.scrollLeft}},created:function(){var t=this,e=!this.isMobile&&"undefined"!=typeof window;e&&function(){var t="vue-scrollbar-live-module-style";if(!document.getElementById(t)){var e=document.createElement("style");e.id=t,e.innerText=".scrollbar-wrap .scrollbar-content::-webkit-scrollbar{width:0;height:0;}.scrollbar-wrap .scrollbar-content{-ms-overflow-style:none;scrollbar-width:none;}.scrollbar-wrap .scrollbar{position:absolute;border-radius:.25em;background:#eee;box-shadow:0 0 2px rgba(0,0,0,0.1);opacity:0;pointer-events:none}.scrollbar-wrap .scrollbar-y{right:0.25em;width:.5em}.scrollbar-wrap .scrollbar-x{bottom:0.25em;height:.5em}.scrollbar-wrap:hover .scrollbar{opacity:1;pointer-events:initial}",document.head.appendChild(e)}}(),this.$once("hook:mounted",function(){e&&(t.updateScrollbarWidth(),t.$once("hook:beforeDestroy",m.$addListener(t.$refs.content,"scroll",t.scroll))),t.updateHeight(),t.$on("hook:beforeDestroy",function(o,e){if("MutationObserver"in window){var t=new MutationObserver(function(t){t.some(function(t){var e=t.target;if(o.$el.contains(e)){if(!(e instanceof Element))return!0;var n=e.className;return!/^scrollbar\s/.test(n)}return e.contains(o.$el)})&&e()});return t.observe(document.body,{attributes:!0,childList:!0,subtree:!0}),function(){t.disconnect()}}return o.$on("hook:updated",e),function(){}}(t,function(){t.$emit("domChange"),t.updateScrollbarWidth(),t.updateHeight()}))})}},void 0,!1,void 0,void 0,void 0)});