Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@better-scroll/scroll-bar

Package Overview
Dependencies
Maintainers
3
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@better-scroll/scroll-bar - npm Package Compare versions

Comparing version 2.4.2 to 2.5.0

15

dist/scroll-bar.esm.js
/*!
* better-scroll / scroll-bar
* (c) 2016-2021 ustbhuangyi
* (c) 2016-2022 ustbhuangyi
* Released under the MIT License.

@@ -169,2 +169,7 @@ */

}
function maybePrevent(e) {
if (e.cancelable) {
e.preventDefault();
}
}
vendor && vendor !== 'standard' ? '-' + vendor.toLowerCase() + '-' : '';

@@ -380,3 +385,3 @@ var transform = prefixStyle('transform');

var point = (e.touches ? e.touches[0] : e);
e.preventDefault();
maybePrevent(e);
e.stopPropagation();

@@ -393,3 +398,3 @@ this.initiated = true;

var pointPos = point[this.indicator.keysMap.point];
e.preventDefault();
maybePrevent(e);
e.stopPropagation();

@@ -405,3 +410,3 @@ var delta = pointPos - this.lastPoint;

this.initiated = false;
e.preventDefault();
maybePrevent(e);
e.stopPropagation();

@@ -813,2 +818,2 @@ this.hooks.trigger(this.hooks.eventTypes.touchEnd);

export default ScrollBar;
export { ScrollBar as default };
/*!
* better-scroll / scroll-bar
* (c) 2016-2021 ustbhuangyi
* (c) 2016-2022 ustbhuangyi
* Released under the MIT License.

@@ -10,3 +10,3 @@ */

(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.ScrollBar = factory());
}(this, (function () { 'use strict';
})(this, (function () { 'use strict';

@@ -176,2 +176,7 @@ /*! *****************************************************************************

}
function maybePrevent(e) {
if (e.cancelable) {
e.preventDefault();
}
}
vendor && vendor !== 'standard' ? '-' + vendor.toLowerCase() + '-' : '';

@@ -387,3 +392,3 @@ var transform = prefixStyle('transform');

var point = (e.touches ? e.touches[0] : e);
e.preventDefault();
maybePrevent(e);
e.stopPropagation();

@@ -400,3 +405,3 @@ this.initiated = true;

var pointPos = point[this.indicator.keysMap.point];
e.preventDefault();
maybePrevent(e);
e.stopPropagation();

@@ -412,3 +417,3 @@ var delta = pointPos - this.lastPoint;

this.initiated = false;
e.preventDefault();
maybePrevent(e);
e.stopPropagation();

@@ -822,2 +827,2 @@ this.hooks.trigger(this.hooks.eventTypes.touchEnd);

})));
}));

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).ScrollBar=e()}(this,function(){"use strict";var c=function(){return(c=Object.assign||function(t){for(var e,o=1,s=arguments.length;o<s;o++)for(var i in e=arguments[o])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};var s="undefined"!=typeof window,e=s&&navigator.userAgent.toLowerCase();e&&/wechatdevtools/.test(e),e&&e.indexOf("android"),function(){if("string"==typeof e){var t=/os (\d\d?_\d(_\d)?)/.exec(e);if(!t)return;t=t[1].split("_").map(function(t){return parseInt(t,10)});13===t[0]&&t[1]}}();var i=!1;if(s)try{var t={};Object.defineProperty(t,"passive",{get:function(){i=!0}}),window.addEventListener("test-passive",function(){},t)}catch(t){}function p(){return window.performance&&window.performance.now&&window.performance.timing?window.performance.now()+window.performance.timing.navigationStart:+new Date}function d(t,e,o){return t<e?e:o<t?o:t}var r=s&&document.createElement("div").style,o=function(){if(!s)return!1;for(var t=0,e=[{key:"standard",value:"transform"},{key:"webkit",value:"webkitTransform"},{key:"Moz",value:"MozTransform"},{key:"O",value:"OTransform"},{key:"ms",value:"msTransform"}];t<e.length;t++){var o=e[t];if(void 0!==r[o.value])return o.key}return!1}();function n(t){return!1===o?t:"standard"===o?"transitionEnd"===t?"transitionend":t:o+t.charAt(0).toUpperCase()+t.substr(1)}function a(t,e,o,s){s=i?{passive:!1,capture:!!s}:!!s;t.addEventListener(e,o,s)}function l(t,e,o,s){t.removeEventListener(e,o,{capture:!!s})}o&&"standard"!==o&&o.toLowerCase();var h=n("transform");n("transition");s&&n("perspective")in r;var u=h,f=n("transitionTimingFunction"),v=n("transitionDuration"),y=(n("transitionDelay"),n("transformOrigin"),n("transitionEnd"),n("transitionProperty"),m.prototype.on=function(t,e,o){return void 0===o&&(o=this),this.hasType(t),this.events[t]||(this.events[t]=[]),this.events[t].push([e,o]),this},m.prototype.once=function(s,i,r){var n=this;void 0===r&&(r=this),this.hasType(s);var a=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];n.off(s,a);var o=i.apply(r,t);if(!0===o)return o};return a.fn=i,this.on(s,a),this},m.prototype.off=function(t,e){if(!t&&!e)return this.events={},this;if(t){if(this.hasType(t),!e)return this.events[t]=[],this;var o=this.events[t];if(!o)return this;for(var s=o.length;s--;)(o[s][0]===e||o[s][0]&&o[s][0].fn===e)&&o.splice(s,1);return this}},m.prototype.trigger=function(t){for(var e=[],o=1;o<arguments.length;o++)e[o-1]=arguments[o];this.hasType(t);t=this.events[t];if(t)for(var s,i=t.length,r=function(){for(var t=0,e=0,o=arguments.length;e<o;e++)t+=arguments[e].length;for(var s=Array(t),i=0,e=0;e<o;e++)for(var r=arguments[e],n=0,a=r.length;n<a;n++,i++)s[i]=r[n];return s}(t),n=0;n<i;n++){var a=r[n],l=a[0],a=a[1];if(l&&!0===(s=l.apply(a,e)))return s}},m.prototype.registerType=function(t){var e=this;t.forEach(function(t){e.eventTypes[t]=t})},m.prototype.destroy=function(){this.events={},this.eventTypes={}},m.prototype.hasType=function(t){var e=this.eventTypes;e[t]===t||(e='EventEmitter has used unknown event type: "'+t+'", should be oneof ['+Object.keys(e).map(function(t){return JSON.stringify(t)})+"]",console.error("[BScroll warn]: "+e))},m);function m(t){this.events={},this.eventTypes={},this.registerType(t)}var g=(k.prototype.destroy=function(){this.removeDOMEvents(),this.events=[]},k.prototype.addDOMEvents=function(){this.handleDOMEvents(a)},k.prototype.removeDOMEvents=function(){this.handleDOMEvents(l)},k.prototype.handleDOMEvents=function(e){var o=this,s=this.wrapper;this.events.forEach(function(t){e(s,t.name,o,!!t.capture)})},k.prototype.handleEvent=function(e){var o=e.type;this.events.some(function(t){return t.name===o&&(t.handler(e),!0)})},k);function k(t,e){this.wrapper=t,this.events=e,this.addDOMEvents()}var T=(b.prototype.registerEvents=function(){var t=this.options,e=t.disableMouse,o=t.disableTouch,s=[],i=[],t=[];e||(s.push({name:"mousedown",handler:this.start.bind(this)}),i.push({name:"mousemove",handler:this.move.bind(this)}),t.push({name:"mouseup",handler:this.end.bind(this)})),o||(s.push({name:"touchstart",handler:this.start.bind(this)}),i.push({name:"touchmove",handler:this.move.bind(this)}),t.push({name:"touchend",handler:this.end.bind(this)},{name:"touchcancel",handler:this.end.bind(this)})),this.startEventRegister=new g(this.indicator.indicatorEl,s),this.moveEventRegister=new g(window,i),this.endEventRegister=new g(window,t)},b.prototype.BScrollIsDisabled=function(){return!this.indicator.scroll.enabled},b.prototype.start=function(t){var e;this.BScrollIsDisabled()||(e=t.touches?t.touches[0]:t,t.preventDefault(),t.stopPropagation(),this.initiated=!0,this.lastPoint=e[this.indicator.keysMap.point],this.hooks.trigger(this.hooks.eventTypes.touchStart))},b.prototype.move=function(t){var e;this.initiated&&(e=(t.touches?t.touches[0]:t)[this.indicator.keysMap.point],t.preventDefault(),t.stopPropagation(),t=e-this.lastPoint,this.lastPoint=e,this.hooks.trigger(this.hooks.eventTypes.touchMove,t))},b.prototype.end=function(t){this.initiated&&(this.initiated=!1,t.preventDefault(),t.stopPropagation(),this.hooks.trigger(this.hooks.eventTypes.touchEnd))},b.prototype.destroy=function(){this.startEventRegister.destroy(),this.moveEventRegister.destroy(),this.endEventRegister.destroy()},b);function b(t,e){this.indicator=t,this.options=e,this.hooks=new y(["touchStart","touchMove","touchEnd"]),this.registerEvents()}var w=(S.prototype.handleFade=function(){this.options.fade&&(this.wrapper.style.opacity="0")},S.prototype.handleHooks=function(){var o=this,t=this.options,e=t.fade,s=t.interactive,i=t.scrollbarTrackClickable,r=this.scroll,n=r.hooks,a=r.scroller.translater.hooks,t=r.scroller.animater.hooks;this.registerHooks(n,n.eventTypes.refresh,this.refresh),this.registerHooks(a,a.eventTypes.translate,function(t){var e=o.keysMap.hasScroll;o.scroll[e]&&o.updatePosition(t)}),this.registerHooks(t,t.eventTypes.time,this.transitionTime),this.registerHooks(t,t.eventTypes.timeFunction,this.transitionTimingFunction),e&&(this.registerHooks(r,r.eventTypes.scrollEnd,function(){o.fade()}),this.registerHooks(r,r.eventTypes.scrollStart,function(){o.fade(!0)}),r.eventTypes.mousewheelStart&&r.eventTypes.mousewheelEnd&&(this.registerHooks(r,r.eventTypes.mousewheelStart,function(){o.fade(!0)}),this.registerHooks(r,r.eventTypes.mousewheelMove,function(){o.fade(!0)}),this.registerHooks(r,r.eventTypes.mousewheelEnd,function(){o.fade()}))),s&&(s=(r=this.scroll.options).disableMouse,r=r.disableTouch,this.eventHandler=new T(this,{disableMouse:s,disableTouch:r}),r=this.eventHandler.hooks,this.registerHooks(r,r.eventTypes.touchStart,this.startHandler),this.registerHooks(r,r.eventTypes.touchMove,this.moveHandler),this.registerHooks(r,r.eventTypes.touchEnd,this.endHandler)),i&&this.bindClick()},S.prototype.registerHooks=function(t,e,o){t.on(e,o,this),this.hooksFn.push([t,e,o])},S.prototype.bindClick=function(){var t=this.wrapper;this.clickEventRegister=new g(t,[{name:"click",handler:this.handleClick.bind(this)}])},S.prototype.handleClick=function(t){var e=this.calculateclickOffsetPos(t),o=this.scroll,t=o.x,o=o.y,t="horizontal"===this.direction?e:t,o="vertical"===this.direction?e:o;this.scroll.scrollTo(t,o,this.options.scrollbarTrackOffsetTime)},S.prototype.calculateclickOffsetPos=function(t){var e=this.keysMap,o=e.point,s=e.domRect,i=this.options.scrollbarTrackOffsetType,e=t[o]-this.wrapperRect[s],t=e<this.currentPos?-1:1,o=0,s=this.currentPos;return"step"===i?o=this.scrollInfo.baseSize*t:(o=0,s=e),this.newPos(s,o,this.scrollInfo)},S.prototype.getKeysMap=function(){return"vertical"===this.direction?{hasScroll:"hasVerticalScroll",size:"height",wrapperSize:"clientHeight",scrollerSize:"scrollerHeight",maxScrollPos:"maxScrollY",pos:"y",point:"pageY",translateProperty:"translateY",domRect:"top"}:{hasScroll:"hasHorizontalScroll",size:"width",wrapperSize:"clientWidth",scrollerSize:"scrollerWidth",maxScrollPos:"maxScrollX",pos:"x",point:"pageX",translateProperty:"translateX",domRect:"left"}},S.prototype.fade=function(t){var e=this.options,o=e.fadeInTime,s=e.fadeOutTime,e=this.wrapper;e.style[v]=(t?o:s)+"ms",e.style.opacity=t?"1":"0"},S.prototype.refresh=function(){var t,e,o=this.keysMap.hasScroll,s=this.scroll,i=s.x,r=s.y;this.wrapperRect=this.wrapper.getBoundingClientRect(),this.canScroll(s[o])&&(t=(e=this.keysMap).wrapperSize,o=e.scrollerSize,e=e.maxScrollPos,this.scrollInfo=this.refreshScrollInfo(this.wrapper[t],s[o],s[e],this.indicatorEl[t]),this.updatePosition({x:i,y:r}))},S.prototype.transitionTime=function(t){this.indicatorEl.style[v]=(t=void 0===t?0:t)+"ms"},S.prototype.transitionTimingFunction=function(t){this.indicatorEl.style[f]=t},S.prototype.canScroll=function(t){return this.wrapper.style.display=t?"block":"none",t},S.prototype.refreshScrollInfo=function(t,e,o,s){e=Math.max(Math.round(t*t/(e||t||1)),this.options.minSize),s=t-(e=this.options.isCustom?s:e);return{baseSize:e,maxScrollPos:s,minScrollPos:0,sizeRatio:s/o}},S.prototype.updatePosition=function(t){var e=this.caculatePosAndSize(t,this.scrollInfo),t=e.pos,e=e.size;this.refreshStyle(e,t),this.currentPos=t},S.prototype.caculatePosAndSize=function(t,e){var o,s=this.keysMap.pos,i=e.sizeRatio,r=e.baseSize,n=e.maxScrollPos,a=e.minScrollPos,e=this.options.minSize,s=Math.round(i*t[s]);return s<a?(o=Math.max(r+3*s,e),s=a):n<s?s=n+r-(o=Math.max(r-3*(s-n),e)):o=r,{pos:s,size:o}},S.prototype.refreshStyle=function(t,e){var o=this.keysMap,s=o.translateProperty,i=o.size,o=this.scroll.options.translateZ;this.indicatorEl.style[i]=t+"px",this.indicatorEl.style[u]=s+"("+e+"px)"+o},S.prototype.startHandler=function(){this.moved=!1,this.startTime=p(),this.transitionTime(),this.scroll.scroller.hooks.trigger(this.scroll.scroller.hooks.eventTypes.beforeScrollStart)},S.prototype.moveHandler=function(t){this.moved||this.indicatorNotMoved(t)||(this.moved=!0,this.scroll.scroller.hooks.trigger(this.scroll.scroller.hooks.eventTypes.scrollStart)),this.moved&&(t=this.newPos(this.currentPos,t,this.scrollInfo),this.syncBScroll(t))},S.prototype.endHandler=function(){var t,e;this.moved&&(t=(e=this.scroll).x,e=e.y,this.scroll.scroller.hooks.trigger(this.scroll.scroller.hooks.eventTypes.scrollEnd,{x:t,y:e}))},S.prototype.indicatorNotMoved=function(t){var e=this.currentPos,o=this.scrollInfo,s=o.maxScrollPos;return e===o.minScrollPos&&t<=0||e===s&&0<=t},S.prototype.syncBScroll=function(t){var e=p(),o=this.scroll,s=o.x,i=o.y,r=o.options,n=o.scroller,a=o.maxScrollY,l=o.minScrollY,h=o.maxScrollX,c=o.minScrollX,o=r.probeType,r=r.momentumLimitTime,i={x:s,y:i};"vertical"===this.direction?i.y=d(t,a,l):i.x=d(t,h,c),n.translater.translate(i),e-this.startTime>r&&(this.startTime=e,1===o&&n.hooks.trigger(n.hooks.eventTypes.scroll,i)),1<o&&n.hooks.trigger(n.hooks.eventTypes.scroll,i)},S.prototype.newPos=function(t,e,o){var s=o.maxScrollPos,i=o.sizeRatio,e=d(e=t+e,o.minScrollPos,s);return Math.round(e/i)},S.prototype.destroy=function(){var t=this.options,e=t.interactive,o=t.scrollbarTrackClickable,t=t.isCustom;e&&this.eventHandler.destroy(),o&&this.clickEventRegister.destroy(),t||this.wrapper.parentNode.removeChild(this.wrapper),this.hooksFn.forEach(function(t){var e=t[0],o=t[1],t=t[2];e.off(o,t)}),this.hooksFn.length=0},S);function S(t,e){this.scroll=t,this.options=e,this.hooksFn=[],this.wrapper=e.wrapper,this.direction=e.direction,this.indicatorEl=this.wrapper.children[0],this.keysMap=this.getKeysMap(),this.handleFade(),this.handleHooks()}function E(t){this.scroll=t,this.handleOptions(),this.createIndicators(),this.handleHooks()}return E.prototype.handleHooks=function(){var o=this,t=this.scroll;t.hooks.on(t.hooks.eventTypes.destroy,function(){for(var t=0,e=o.indicators;t<e.length;t++)e[t].destroy()})},E.prototype.handleOptions=function(){var t=!0===this.scroll.options.scrollbar?{}:this.scroll.options.scrollbar;this.options=function(t,e){for(var o in e)t[o]=e[o];return t}({fade:!0,fadeInTime:250,fadeOutTime:500,interactive:!1,customElements:[],minSize:8,scrollbarTrackClickable:!1,scrollbarTrackOffsetType:"step",scrollbarTrackOffsetTime:300},t)},E.prototype.createIndicators=function(){for(var t,e,o,s,i=this.scroll,r=[],n=["scrollX","scrollY"],a=["horizontal","vertical"],l=this.options.customElements,h=0;h<n.length;h++)i.options[n[h]]&&(t=l.shift(),e=a[h],o=!1,(s=t||this.createScrollbarElement(e))!==t?i.wrapper.appendChild(s):o=!0,o=c(c({wrapper:s,direction:e},this.options),{isCustom:o}),r.push(new w(i,o)));this.indicators=r},E.prototype.createScrollbarElement=function(t,e){void 0===e&&(e=this.options.scrollbarTrackClickable);var o=document.createElement("div"),s=document.createElement("div");return o.style.cssText="position:absolute;z-index:9999;overflow:hidden;",s.style.cssText="box-sizing:border-box;position:absolute;background:rgba(0,0,0,0.5);border:1px solid rgba(255,255,255,0.9);border-radius:3px;",s.className="bscroll-indicator","horizontal"===t?(o.style.cssText+="height:7px;left:2px;right:2px;bottom:0;",s.style.height="100%",o.className="bscroll-horizontal-scrollbar"):(o.style.cssText+="width:7px;bottom:2px;top:2px;right:1px;",s.style.width="100%",o.className="bscroll-vertical-scrollbar"),e||(o.style.cssText+="pointer-events:none;"),o.appendChild(s),o},E.pluginName="scrollbar",E});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).ScrollBar=e()}(this,function(){"use strict";var c=function(){return(c=Object.assign||function(t){for(var e,o=1,s=arguments.length;o<s;o++)for(var i in e=arguments[o])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};var s="undefined"!=typeof window,t=s&&navigator.userAgent.toLowerCase();if(t&&/wechatdevtools/.test(t),t&&t.indexOf("android"),"string"==typeof t)(t=/os (\d\d?_\d(_\d)?)/.exec(t))&&(13===(t=t[1].split("_").map(function(t){return parseInt(t,10)}))[0]&&t[1]);var i=!1;if(s)try{var e={};Object.defineProperty(e,"passive",{get:function(){i=!0}}),window.addEventListener("test-passive",function(){},e)}catch(t){}function p(){return window.performance&&window.performance.now&&window.performance.timing?window.performance.now()+window.performance.timing.navigationStart:+new Date}function d(t,e,o){return t<e?e:o<t?o:t}var r=s&&document.createElement("div").style,o=function(){if(s)for(var t=0,e=[{key:"standard",value:"transform"},{key:"webkit",value:"webkitTransform"},{key:"Moz",value:"MozTransform"},{key:"O",value:"OTransform"},{key:"ms",value:"msTransform"}];t<e.length;t++){var o=e[t];if(void 0!==r[o.value])return o.key}return!1}();function n(t){return!1===o?t:"standard"===o?"transitionEnd"===t?"transitionend":t:o+t.charAt(0).toUpperCase()+t.substr(1)}function a(t,e,o,s){s=i?{passive:!1,capture:!!s}:!!s;t.addEventListener(e,o,s)}function l(t,e,o,s){t.removeEventListener(e,o,{capture:!!s})}function h(t){t.cancelable&&t.preventDefault()}o&&"standard"!==o&&o.toLowerCase();t=n("transform");n("transition");s&&n("perspective")in r;var u=t,f=n("transitionTimingFunction"),v=n("transitionDuration"),y=(n("transitionDelay"),n("transformOrigin"),n("transitionEnd"),n("transitionProperty"),m.prototype.on=function(t,e,o){return void 0===o&&(o=this),this.hasType(t),this.events[t]||(this.events[t]=[]),this.events[t].push([e,o]),this},m.prototype.once=function(s,i,r){var n=this,a=(void 0===r&&(r=this),this.hasType(s),function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];n.off(s,a);var o=i.apply(r,t);if(!0===o)return o});return a.fn=i,this.on(s,a),this},m.prototype.off=function(t,e){if(!t&&!e)return this.events={},this;if(t){if(this.hasType(t),e){var o=this.events[t];if(o)for(var s=o.length;s--;)(o[s][0]===e||o[s][0]&&o[s][0].fn===e)&&o.splice(s,1)}else this.events[t]=[];return this}},m.prototype.trigger=function(t){for(var e=[],o=1;o<arguments.length;o++)e[o-1]=arguments[o];this.hasType(t);t=this.events[t];if(t)for(var s=t.length,i=function(){for(var t=0,e=0,o=arguments.length;e<o;e++)t+=arguments[e].length;for(var s=Array(t),i=0,e=0;e<o;e++)for(var r=arguments[e],n=0,a=r.length;n<a;n++,i++)s[i]=r[n];return s}(t),r=0;r<s;r++){var n=i[r],a=n[0],n=n[1];if(a&&!0===(a=a.apply(n,e)))return a}},m.prototype.registerType=function(t){var e=this;t.forEach(function(t){e.eventTypes[t]=t})},m.prototype.destroy=function(){this.events={},this.eventTypes={}},m.prototype.hasType=function(t){var e=this.eventTypes;e[t]!==t&&(t='EventEmitter has used unknown event type: "'+t+'", should be oneof ['+Object.keys(e).map(function(t){return JSON.stringify(t)})+"]",console.error("[BScroll warn]: "+t))},m);function m(t){this.events={},this.eventTypes={},this.registerType(t)}k.prototype.destroy=function(){this.removeDOMEvents(),this.events=[]},k.prototype.addDOMEvents=function(){this.handleDOMEvents(a)},k.prototype.removeDOMEvents=function(){this.handleDOMEvents(l)},k.prototype.handleDOMEvents=function(e){var o=this,s=this.wrapper;this.events.forEach(function(t){e(s,t.name,o,!!t.capture)})},k.prototype.handleEvent=function(e){var o=e.type;this.events.some(function(t){return t.name===o&&(t.handler(e),!0)})};var g=k;function k(t,e){this.wrapper=t,this.events=e,this.addDOMEvents()}b.prototype.registerEvents=function(){var t=this.options,e=t.disableMouse,t=t.disableTouch,o=[],s=[],i=[];e||(o.push({name:"mousedown",handler:this.start.bind(this)}),s.push({name:"mousemove",handler:this.move.bind(this)}),i.push({name:"mouseup",handler:this.end.bind(this)})),t||(o.push({name:"touchstart",handler:this.start.bind(this)}),s.push({name:"touchmove",handler:this.move.bind(this)}),i.push({name:"touchend",handler:this.end.bind(this)},{name:"touchcancel",handler:this.end.bind(this)})),this.startEventRegister=new g(this.indicator.indicatorEl,o),this.moveEventRegister=new g(window,s),this.endEventRegister=new g(window,i)},b.prototype.BScrollIsDisabled=function(){return!this.indicator.scroll.enabled},b.prototype.start=function(t){var e;this.BScrollIsDisabled()||(e=t.touches?t.touches[0]:t,h(t),t.stopPropagation(),this.initiated=!0,this.lastPoint=e[this.indicator.keysMap.point],this.hooks.trigger(this.hooks.eventTypes.touchStart))},b.prototype.move=function(t){var e;this.initiated&&(e=(t.touches?t.touches[0]:t)[this.indicator.keysMap.point],h(t),t.stopPropagation(),t=e-this.lastPoint,this.lastPoint=e,this.hooks.trigger(this.hooks.eventTypes.touchMove,t))},b.prototype.end=function(t){this.initiated&&(this.initiated=!1,h(t),t.stopPropagation(),this.hooks.trigger(this.hooks.eventTypes.touchEnd))},b.prototype.destroy=function(){this.startEventRegister.destroy(),this.moveEventRegister.destroy(),this.endEventRegister.destroy()};var T=b;function b(t,e){this.indicator=t,this.options=e,this.hooks=new y(["touchStart","touchMove","touchEnd"]),this.registerEvents()}S.prototype.handleFade=function(){this.options.fade&&(this.wrapper.style.opacity="0")},S.prototype.handleHooks=function(){var o=this,t=this.options,e=t.fade,s=t.interactive,t=t.scrollbarTrackClickable,i=this.scroll,r=i.hooks,n=i.scroller.translater.hooks,a=i.scroller.animater.hooks;this.registerHooks(r,r.eventTypes.refresh,this.refresh),this.registerHooks(n,n.eventTypes.translate,function(t){var e=o.keysMap.hasScroll;o.scroll[e]&&o.updatePosition(t)}),this.registerHooks(a,a.eventTypes.time,this.transitionTime),this.registerHooks(a,a.eventTypes.timeFunction,this.transitionTimingFunction),e&&(this.registerHooks(i,i.eventTypes.scrollEnd,function(){o.fade()}),this.registerHooks(i,i.eventTypes.scrollStart,function(){o.fade(!0)}),i.eventTypes.mousewheelStart&&i.eventTypes.mousewheelEnd&&(this.registerHooks(i,i.eventTypes.mousewheelStart,function(){o.fade(!0)}),this.registerHooks(i,i.eventTypes.mousewheelMove,function(){o.fade(!0)}),this.registerHooks(i,i.eventTypes.mousewheelEnd,function(){o.fade()}))),s&&(n=(r=this.scroll.options).disableMouse,a=r.disableTouch,this.eventHandler=new T(this,{disableMouse:n,disableTouch:a}),e=this.eventHandler.hooks,this.registerHooks(e,e.eventTypes.touchStart,this.startHandler),this.registerHooks(e,e.eventTypes.touchMove,this.moveHandler),this.registerHooks(e,e.eventTypes.touchEnd,this.endHandler)),t&&this.bindClick()},S.prototype.registerHooks=function(t,e,o){t.on(e,o,this),this.hooksFn.push([t,e,o])},S.prototype.bindClick=function(){var t=this.wrapper;this.clickEventRegister=new g(t,[{name:"click",handler:this.handleClick.bind(this)}])},S.prototype.handleClick=function(t){var t=this.calculateclickOffsetPos(t),e=this.scroll,o=e.x,e=e.y,o="horizontal"===this.direction?t:o,e="vertical"===this.direction?t:e;this.scroll.scrollTo(o,e,this.options.scrollbarTrackOffsetTime)},S.prototype.calculateclickOffsetPos=function(t){var e=this.keysMap,o=e.point,e=e.domRect,s=this.options.scrollbarTrackOffsetType,t=t[o]-this.wrapperRect[e],o=t<this.currentPos?-1:1,e=0,i=this.currentPos;return"step"===s?e=this.scrollInfo.baseSize*o:(e=0,i=t),this.newPos(i,e,this.scrollInfo)},S.prototype.getKeysMap=function(){return"vertical"===this.direction?{hasScroll:"hasVerticalScroll",size:"height",wrapperSize:"clientHeight",scrollerSize:"scrollerHeight",maxScrollPos:"maxScrollY",pos:"y",point:"pageY",translateProperty:"translateY",domRect:"top"}:{hasScroll:"hasHorizontalScroll",size:"width",wrapperSize:"clientWidth",scrollerSize:"scrollerWidth",maxScrollPos:"maxScrollX",pos:"x",point:"pageX",translateProperty:"translateX",domRect:"left"}},S.prototype.fade=function(t){var e=this.options,o=e.fadeInTime,e=e.fadeOutTime,s=this.wrapper;s.style[v]=(t?o:e)+"ms",s.style.opacity=t?"1":"0"},S.prototype.refresh=function(){var t,e,o=this.keysMap.hasScroll,s=this.scroll,i=s.x,r=s.y;this.wrapperRect=this.wrapper.getBoundingClientRect(),this.canScroll(s[o])&&(t=(o=this.keysMap).wrapperSize,e=o.scrollerSize,o=o.maxScrollPos,this.scrollInfo=this.refreshScrollInfo(this.wrapper[t],s[e],s[o],this.indicatorEl[t]),this.updatePosition({x:i,y:r}))},S.prototype.transitionTime=function(t){this.indicatorEl.style[v]=(t=void 0===t?0:t)+"ms"},S.prototype.transitionTimingFunction=function(t){this.indicatorEl.style[f]=t},S.prototype.canScroll=function(t){return this.wrapper.style.display=t?"block":"none",t},S.prototype.refreshScrollInfo=function(t,e,o,s){e=Math.max(Math.round(t*t/(e||t||1)),this.options.minSize),t-=e=this.options.isCustom?s:e;return{baseSize:e,maxScrollPos:t,minScrollPos:0,sizeRatio:t/o}},S.prototype.updatePosition=function(t){var t=this.caculatePosAndSize(t,this.scrollInfo),e=t.pos,t=t.size;this.refreshStyle(t,e),this.currentPos=e},S.prototype.caculatePosAndSize=function(t,e){var o,s=this.keysMap.pos,i=e.sizeRatio,r=e.baseSize,n=e.maxScrollPos,e=e.minScrollPos,a=this.options.minSize,i=Math.round(i*t[s]);return i<e?(o=Math.max(r+3*i,a),i=e):n<i?i=n+r-(o=Math.max(r-3*(i-n),a)):o=r,{pos:i,size:o}},S.prototype.refreshStyle=function(t,e){var o=this.keysMap,s=o.translateProperty,o=o.size,i=this.scroll.options.translateZ;this.indicatorEl.style[o]=t+"px",this.indicatorEl.style[u]=s+"("+e+"px)"+i},S.prototype.startHandler=function(){this.moved=!1,this.startTime=p(),this.transitionTime(),this.scroll.scroller.hooks.trigger(this.scroll.scroller.hooks.eventTypes.beforeScrollStart)},S.prototype.moveHandler=function(t){this.moved||this.indicatorNotMoved(t)||(this.moved=!0,this.scroll.scroller.hooks.trigger(this.scroll.scroller.hooks.eventTypes.scrollStart)),this.moved&&(t=this.newPos(this.currentPos,t,this.scrollInfo),this.syncBScroll(t))},S.prototype.endHandler=function(){var t,e;this.moved&&(t=(e=this.scroll).x,e=e.y,this.scroll.scroller.hooks.trigger(this.scroll.scroller.hooks.eventTypes.scrollEnd,{x:t,y:e}))},S.prototype.indicatorNotMoved=function(t){var e=this.currentPos,o=this.scrollInfo,s=o.maxScrollPos;return e===o.minScrollPos&&t<=0||e===s&&0<=t},S.prototype.syncBScroll=function(t){var e=p(),o=this.scroll,s=o.x,i=o.y,r=o.options,n=o.scroller,a=o.maxScrollY,l=o.minScrollY,h=o.maxScrollX,o=o.minScrollX,c=r.probeType,r=r.momentumLimitTime,s={x:s,y:i};"vertical"===this.direction?s.y=d(t,a,l):s.x=d(t,h,o),n.translater.translate(s),e-this.startTime>r&&(this.startTime=e,1===c&&n.hooks.trigger(n.hooks.eventTypes.scroll,s)),1<c&&n.hooks.trigger(n.hooks.eventTypes.scroll,s)},S.prototype.newPos=function(t,e,o){var s=o.maxScrollPos,i=o.sizeRatio,t=d(t+e,o.minScrollPos,s);return Math.round(t/i)},S.prototype.destroy=function(){var t=this.options,e=t.interactive,o=t.scrollbarTrackClickable,t=t.isCustom;e&&this.eventHandler.destroy(),o&&this.clickEventRegister.destroy(),t||this.wrapper.parentNode.removeChild(this.wrapper),this.hooksFn.forEach(function(t){var e=t[0],o=t[1],t=t[2];e.off(o,t)}),this.hooksFn.length=0};var w=S;function S(t,e){this.scroll=t,this.options=e,this.hooksFn=[],this.wrapper=e.wrapper,this.direction=e.direction,this.indicatorEl=this.wrapper.children[0],this.keysMap=this.getKeysMap(),this.handleFade(),this.handleHooks()}function E(t){this.scroll=t,this.handleOptions(),this.createIndicators(),this.handleHooks()}return E.prototype.handleHooks=function(){var o=this,t=this.scroll;t.hooks.on(t.hooks.eventTypes.destroy,function(){for(var t=0,e=o.indicators;t<e.length;t++)e[t].destroy()})},E.prototype.handleOptions=function(){var t=!0===this.scroll.options.scrollbar?{}:this.scroll.options.scrollbar;this.options=function(t,e){for(var o in e)t[o]=e[o];return t}({fade:!0,fadeInTime:250,fadeOutTime:500,interactive:!1,customElements:[],minSize:8,scrollbarTrackClickable:!1,scrollbarTrackOffsetType:"step",scrollbarTrackOffsetTime:300},t)},E.prototype.createIndicators=function(){for(var t,e,o,s,i=this.scroll,r=[],n=["scrollX","scrollY"],a=["horizontal","vertical"],l=this.options.customElements,h=0;h<n.length;h++)i.options[n[h]]&&(t=l.shift(),e=a[h],o=!1,(s=t||this.createScrollbarElement(e))!==t?i.wrapper.appendChild(s):o=!0,t=c(c({wrapper:s,direction:e},this.options),{isCustom:o}),r.push(new w(i,t)));this.indicators=r},E.prototype.createScrollbarElement=function(t,e){void 0===e&&(e=this.options.scrollbarTrackClickable);var o=document.createElement("div"),s=document.createElement("div");return o.style.cssText="position:absolute;z-index:9999;overflow:hidden;",s.style.cssText="box-sizing:border-box;position:absolute;background:rgba(0,0,0,0.5);border:1px solid rgba(255,255,255,0.9);border-radius:3px;",s.className="bscroll-indicator","horizontal"===t?(o.style.cssText+="height:7px;left:2px;right:2px;bottom:0;",s.style.height="100%",o.className="bscroll-horizontal-scrollbar"):(o.style.cssText+="width:7px;bottom:2px;top:2px;right:1px;",s.style.width="100%",o.className="bscroll-vertical-scrollbar"),e||(o.style.cssText+="pointer-events:none;"),o.appendChild(s),o},E.pluginName="scrollbar",E});
{
"name": "@better-scroll/scroll-bar",
"version": "2.4.2",
"version": "2.5.0",
"description": "scrollbar is used to BetterScroll, which behaves like browser scrollbar",

@@ -33,5 +33,5 @@ "author": {

"dependencies": {
"@better-scroll/core": "^2.4.2"
"@better-scroll/core": "^2.5.0"
},
"gitHead": "c97e67ecf15e616d998e67aa4ce15a7c429691c3"
"gitHead": "0313d72f89a7e928522210d814b9025baf0559cb"
}

@@ -6,2 +6,3 @@ import BScroll from '@better-scroll/core'

EventEmitter,
maybePrevent,
} from '@better-scroll/shared-utils'

@@ -95,3 +96,3 @@ import Indicator from './indicator'

e.preventDefault()
maybePrevent(e)
e.stopPropagation()

@@ -111,3 +112,3 @@

e.preventDefault()
maybePrevent(e)
e.stopPropagation()

@@ -126,3 +127,3 @@

e.preventDefault()
maybePrevent(e)
e.stopPropagation()

@@ -129,0 +130,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc