@better-scroll/core
Advanced tools
Comparing version 2.0.5 to 2.0.6
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).BScroll={})}(this,function(t){"use strict";var i=function(t,e){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])})(t,e)};function e(t,e){function o(){this.constructor=t}i(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}var c=function(){return(c=Object.assign||function(t){for(var e,o=1,i=arguments.length;o<i;o++)for(var s in e=arguments[o])Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s]);return t}).apply(this,arguments)};function p(){for(var t=0,e=0,o=arguments.length;e<o;e++)t+=arguments[e].length;for(var i=Array(t),s=0,e=0;e<o;e++)for(var n=arguments[e],r=0,h=n.length;r<h;r++,s++)i[s]=n[r];return i}var s=[{sourceKey:"scroller.scrollBehaviorX.currentPos",key:"x"},{sourceKey:"scroller.scrollBehaviorY.currentPos",key:"y"},{sourceKey:"scroller.scrollBehaviorX.hasScroll",key:"hasHorizontalScroll"},{sourceKey:"scroller.scrollBehaviorY.hasScroll",key:"hasVerticalScroll"},{sourceKey:"scroller.scrollBehaviorX.contentSize",key:"scrollerWidth"},{sourceKey:"scroller.scrollBehaviorY.contentSize",key:"scrollerHeight"},{sourceKey:"scroller.scrollBehaviorX.maxScrollPos",key:"maxScrollX"},{sourceKey:"scroller.scrollBehaviorY.maxScrollPos",key:"maxScrollY"},{sourceKey:"scroller.scrollBehaviorX.minScrollPos",key:"minScrollX"},{sourceKey:"scroller.scrollBehaviorY.minScrollPos",key:"minScrollY"},{sourceKey:"scroller.scrollBehaviorX.movingDirection",key:"movingDirectionX"},{sourceKey:"scroller.scrollBehaviorY.movingDirection",key:"movingDirectionY"},{sourceKey:"scroller.scrollBehaviorX.direction",key:"directionX"},{sourceKey:"scroller.scrollBehaviorY.direction",key:"directionY"},{sourceKey:"scroller.actions.enabled",key:"enabled"},{sourceKey:"scroller.animater.pending",key:"pending"},{sourceKey:"scroller.animater.stop",key:"stop"},{sourceKey:"scroller.scrollTo",key:"scrollTo"},{sourceKey:"scroller.scrollBy",key:"scrollBy"},{sourceKey:"scroller.scrollToElement",key:"scrollToElement"},{sourceKey:"scroller.resetPosition",key:"resetPosition"}];function n(t){console.error("[BScroll warn]: "+t)}var r="undefined"!=typeof window,o=r&&navigator.userAgent.toLowerCase(),h=!(!o||!/wechatdevtools/.test(o)),a=o&&0<o.indexOf("android"),l=function(){if("string"!=typeof o)return!1;var t=/os (\d\d?_\d(_\d)?)/.exec(o);if(!t)return!1;var e=t[1].split("_").map(function(t){return parseInt(t,10)});return!!(13<=e[0]&&4<=e[1])}();function u(){return window.performance&&window.performance.now&&window.performance.timing?window.performance.now()+window.performance.timing.navigationStart:+new Date}var d=function(t,e){for(var o in e)t[o]=e[o];return t};function f(t){return null==t}var v=r&&document.createElement("div").style,y=function(){if(!r)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!==v[o.value])return o.key}return!1}();function m(t){return!1===y?t:"standard"===y?"transitionEnd"===t?"transitionend":t:y+t.charAt(0).toUpperCase()+t.substr(1)}function g(t){return"string"==typeof t?document.querySelector(t):t}function k(t,e,o,i){t.addEventListener(e,o,{passive:!1,capture:!!i})}function T(t,e,o,i){t.removeEventListener(e,o,{capture:!!i})}function b(t){for(var e=0,o=0;t;)e-=t.offsetLeft,o-=t.offsetTop,t=t.offsetParent;return{left:e,top:o}}y&&"standard"!==y&&y.toLowerCase();var S=m("transform"),P=m("transition"),w=r&&m("perspective")in v,E=r&&("ontouchstart"in window||h),B=r&&P in v,C={transform:S,transition:P,transitionTimingFunction:m("transitionTimingFunction"),transitionDuration:m("transitionDuration"),transitionDelay:m("transitionDelay"),transformOrigin:m("transformOrigin"),transitionEnd:m("transitionEnd"),transitionProperty:m("transitionProperty")},D={touchstart:1,touchmove:1,touchend:1,mousedown:2,mousemove:2,mouseup:2};function X(t){if(t instanceof window.SVGElement){var e=t.getBoundingClientRect();return{top:e.top,left:e.left,width:e.width,height:e.height}}return{top:t.offsetTop,left:t.offsetLeft,width:t.offsetWidth,height:t.offsetHeight}}function x(t,e){for(var o in e)if(e[o].test(t[o]))return!0;return!1}var Y=x;function O(t,e){var o;void 0===e&&(e="click"),"mouseup"===t.type?o=t:"touchend"!==t.type&&"touchcancel"!==t.type||(o=t.changedTouches[0]);var i,s={};o&&(s.screenX=o.screenX||0,s.screenY=o.screenY||0,s.clientX=o.clientX||0,s.clientY=o.clientY||0);var n=!0,r=!0,h={ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey};if("undefined"!=typeof MouseEvent)try{i=new MouseEvent(e,d(c({bubbles:n,cancelable:r},h),s))}catch(t){a()}else a();function a(){(i=document.createEvent("Event")).initEvent(e,n,r),d(i,s)}i.forwardedTouchEvent=!0,i._constructed=!0,t.target.dispatchEvent(i)}var M={swipe:{style:"cubic-bezier(0.23, 1, 0.32, 1)",fn:function(t){return 1+--t*t*t*t*t}},swipeBounce:{style:"cubic-bezier(0.25, 0.46, 0.45, 0.94)",fn:function(t){return t*(2-t)}},bounce:{style:"cubic-bezier(0.165, 0.84, 0.44, 1)",fn:function(t){return 1- --t*t*t*t}}},L=r&&window;function A(){}function z(t){}var F=r?L.requestAnimationFrame||L.webkitRequestAnimationFrame||L.mozRequestAnimationFrame||L.oRequestAnimationFrame||function(t){return window.setTimeout(t,(t.interval||100/60)/2)}:A,H=r?L.cancelAnimationFrame||L.webkitCancelAnimationFrame||L.mozCancelAnimationFrame||L.oCancelAnimationFrame||function(t){window.clearTimeout(t)}:A,K={enumerable:!0,configurable:!0,get:z,set:z};var R=(j.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},j.prototype.once=function(o,i,s){var n=this;void 0===s&&(s=this),this.hasType(o);var r=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];n.off(o,r),i.apply(s,t)};return r.fn=i,this.on(o,r),this},j.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 i=o.length;i--;)(o[i][0]===e||o[i][0]&&o[i][0].fn===e)&&o.splice(i,1);return this}},j.prototype.trigger=function(t){for(var e=[],o=1;o<arguments.length;o++)e[o-1]=arguments[o];this.hasType(t);var i=this.events[t];if(i)for(var s,n=i.length,r=p(i),h=0;h<n;h++){var a=r[h],c=a[0],l=a[1];if(c&&!0===(s=c.apply(l,e)))return s}},j.prototype.registerType=function(t){var e=this;t.forEach(function(t){e.eventTypes[t]=t})},j.prototype.destroy=function(){this.events={},this.eventTypes={}},j.prototype.hasType=function(t){var e=this.eventTypes;e[t]===t||n('EventEmitter has used unknown event type: "'+t+'", should be oneof ['+Object.keys(e).map(function(t){return JSON.stringify(t)})+"]")},j);function j(t){this.events={},this.eventTypes={},this.registerType(t)}var I=(_.prototype.destroy=function(){this.removeDOMEvents(),this.events=[]},_.prototype.addDOMEvents=function(){this.handleDOMEvents(k)},_.prototype.removeDOMEvents=function(){this.handleDOMEvents(T)},_.prototype.handleDOMEvents=function(e){var o=this,i=this.wrapper;this.events.forEach(function(t){e(i,t.name,o,!!t.capture)})},_.prototype.handleEvent=function(e){var o=e.type;this.events.some(function(t){return t.name===o&&(t.handler(e),!0)})},_);function _(t,e){this.wrapper=t,this.events=e,this.addDOMEvents()}function W(){}var N,q=(e(U,N=W),U.prototype.merge=function(t){if(!t)return this;for(var e in t)"bounce"!==e?this[e]=t[e]:this.bounce=this.resolveBounce(t[e]);return this},U.prototype.process=function(){return this.translateZ=this.HWCompositing&&w?" translateZ(1px)":"",this.useTransition=this.useTransition&&B,this.preventDefault=!this.eventPassthrough&&this.preventDefault,this.scrollX="horizontal"!==this.eventPassthrough&&this.scrollX,this.scrollY="vertical"!==this.eventPassthrough&&this.scrollY,this.freeScroll=this.freeScroll&&!this.eventPassthrough,this.scrollX=!!this.freeScroll||this.scrollX,this.scrollY=!!this.freeScroll||this.scrollY,this.directionLockThreshold=this.eventPassthrough?0:this.directionLockThreshold,this},U.prototype.resolveBounce=function(t){var e={top:!0,right:!0,bottom:!0,left:!0},o="object"==typeof t?d(e,t):t?e:{top:!1,right:!1,bottom:!1,left:!1};return o},U);function U(){var t=N.call(this)||this;return t.startX=0,t.startY=0,t.scrollX=!1,t.scrollY=!0,t.freeScroll=!1,t.directionLockThreshold=5,t.eventPassthrough="",t.click=!1,t.dblclick=!1,t.tap="",t.bounce={top:!0,bottom:!0,left:!0,right:!0},t.bounceTime=800,t.momentum=!0,t.momentumLimitTime=300,t.momentumLimitDistance=15,t.swipeTime=2500,t.swipeBounceTime=500,t.deceleration=.0015,t.flickLimitTime=200,t.flickLimitDistance=100,t.resizePolling=60,t.probeType=0,t.stopPropagation=!1,t.preventDefault=!0,t.preventDefaultException={tagName:/^(INPUT|TEXTAREA|BUTTON|SELECT|AUDIO)$/},t.tagException={tagName:/^TEXTAREA$/},t.HWCompositing=!0,t.useTransition=!0,t.bindToWrapper=!1,t.bindToTarget=!1,t.disableMouse=E,t.disableTouch=!E,t.autoBlur=!0,t.autoEndDistance=5,t.outOfBoundaryDampingFactor=1/3,t.specifiedIndexAsContent=0,t}var Z=(V.prototype.handleDOMEvents=function(){var t=this.options,e=t.bindToWrapper,o=t.disableMouse,i=t.disableTouch,s=t.click,n=this.wrapper,r=e?n:window,h=[],a=[],c=!i,l=!o;s&&h.push({name:"click",handler:this.click.bind(this),capture:!0}),c&&(h.push({name:"touchstart",handler:this.start.bind(this)}),a.push({name:"touchmove",handler:this.move.bind(this)},{name:"touchend",handler:this.end.bind(this)},{name:"touchcancel",handler:this.end.bind(this)})),l&&(h.push({name:"mousedown",handler:this.start.bind(this)}),a.push({name:"mousemove",handler:this.move.bind(this)},{name:"mouseup",handler:this.end.bind(this)})),this.wrapperEventRegister=new I(n,h),this.targetEventRegister=new I(r,a)},V.prototype.beforeHandler=function(t,e){var o=this.options,i=o.preventDefault,s=o.stopPropagation,n=o.preventDefaultException;!{start:function(){return i&&!x(t.target,n)},end:function(){return i&&!x(t.target,n)},move:function(){return i}}[e]()||t.preventDefault(),s&&t.stopPropagation()},V.prototype.setInitiated=function(t){void 0===t&&(t=0),this.initiated=t},V.prototype.start=function(t){var e,o=D[t.type];this.initiated&&this.initiated!==o||(this.setInitiated(o),Y(t.target,this.options.tagException)?this.setInitiated():2===o&&0!==t.button||this.hooks.trigger(this.hooks.eventTypes.beforeStart,t)||(this.beforeHandler(t,"start"),e=t.touches?t.touches[0]:t,this.pointX=e.pageX,this.pointY=e.pageY,this.hooks.trigger(this.hooks.eventTypes.start,t)))},V.prototype.move=function(t){var e,o,i,s,n,r,h,a;D[t.type]===this.initiated&&(this.beforeHandler(t,"move"),o=(e=t.touches?t.touches[0]:t).pageX-this.pointX,i=e.pageY-this.pointY,this.pointX=e.pageX,this.pointY=e.pageY,this.hooks.trigger(this.hooks.eventTypes.move,{deltaX:o,deltaY:i,e:t})||(s=document.documentElement.scrollLeft||window.pageXOffset||document.body.scrollLeft,n=document.documentElement.scrollTop||window.pageYOffset||document.body.scrollTop,r=this.pointX-s,h=this.pointY-n,a=this.options.autoEndDistance,(r>document.documentElement.clientWidth-a||h>document.documentElement.clientHeight-a||r<a||h<a)&&this.end(t)))},V.prototype.end=function(t){D[t.type]===this.initiated&&(this.setInitiated(),this.beforeHandler(t,"end"),this.hooks.trigger(this.hooks.eventTypes.end,t))},V.prototype.click=function(t){this.hooks.trigger(this.hooks.eventTypes.click,t)},V.prototype.setContent=function(t){t!==this.wrapper&&(this.wrapper=t,this.wrapperEventRegister.destroy(),this.targetEventRegister.destroy(),this.handleDOMEvents())},V.prototype.destroy=function(){this.wrapperEventRegister.destroy(),this.targetEventRegister.destroy(),this.hooks.destroy()},V);function V(t,e){this.wrapper=t,this.options=e,this.hooks=new R(["beforeStart","start","move","end","click"]),this.handleDOMEvents()}var $={x:["translateX","px"],y:["translateY","px"]},G=(J.prototype.getComputedPosition=function(){var t=window.getComputedStyle(this.content,null)[C.transform].split(")")[0].split(", ");return{x:+(t[12]||t[4])||0,y:+(t[13]||t[5])||0}},J.prototype.translate=function(s){var n=[];Object.keys(s).forEach(function(t){var e,o,i;!$[t]||(e=$[t][0])&&(o=$[t][1],i=s[t],n.push(e+"("+i+o+")"))}),this.hooks.trigger(this.hooks.eventTypes.beforeTranslate,n,s),this.style[C.transform]=n.join(" "),this.hooks.trigger(this.hooks.eventTypes.translate,s)},J.prototype.setContent=function(t){this.content!==t&&(this.content=t,this.style=t.style)},J.prototype.destroy=function(){this.hooks.destroy()},J);function J(t){this.setContent(t),this.hooks=new R(["beforeTranslate","translate"])}var Q=(tt.prototype.translate=function(t){this.translater.translate(t)},tt.prototype.setPending=function(t){this.pending=t},tt.prototype.setForceStopped=function(t){this.forceStopped=t},tt.prototype.setContent=function(t){this.content!==t&&(this.content=t,this.style=t.style,this.stop())},tt.prototype.destroy=function(){this.hooks.destroy(),H(this.timer)},tt);function tt(t,e,o){this.translater=e,this.options=o,this.timer=0,this.hooks=new R(["move","end","beforeForceStop","forceStop","callStop","time","timeFunction"]),this.setContent(t)}var et,ot=(e(it,et=Q),it.prototype.startProbe=function(){var e=this,o=function(){var t=e.translater.getComputedPosition();e.hooks.trigger(e.hooks.eventTypes.move,t),e.pending||e.forceStopped||e.hooks.trigger(e.hooks.eventTypes.end,t),e.pending&&(e.timer=F(o))};H(this.timer),o()},it.prototype.transitionTime=function(t){void 0===t&&(t=0),this.style[C.transitionDuration]=t+"ms",this.hooks.trigger(this.hooks.eventTypes.time,t)},it.prototype.transitionTimingFunction=function(t){this.style[C.transitionTimingFunction]=t,this.hooks.trigger(this.hooks.eventTypes.timeFunction,t)},it.prototype.transitionProperty=function(){this.style[C.transitionProperty]=C.transform},it.prototype.move=function(t,e,o,i){this.setPending(0<o),this.transitionTimingFunction(i),this.transitionProperty(),this.transitionTime(o),this.translate(e),o&&3===this.options.probeType&&this.startProbe(),o||(this._reflow=this.content.offsetHeight,this.hooks.trigger(this.hooks.eventTypes.move,e),this.hooks.trigger(this.hooks.eventTypes.end,e))},it.prototype.doStop=function(){var t=this.pending;if(this.setForceStopped(!1),t){this.setPending(!1),H(this.timer);var e=this.translater.getComputedPosition(),o=e.x,i=e.y;if(this.transitionTime(),this.translate({x:o,y:i}),this.setForceStopped(!0),this.hooks.trigger(this.hooks.eventTypes.beforeForceStop,{x:o,y:i}))return!0;this.hooks.trigger(this.hooks.eventTypes.forceStop,{x:o,y:i})}return t},it.prototype.stop=function(){this.doStop()&&(this.hooks.trigger(this.hooks.eventTypes.callStop),this.setForceStopped(!1))},it);function it(){return null!==et&&et.apply(this,arguments)||this}var st,nt=(e(rt,st=Q),rt.prototype.move=function(t,e,o,i){if(!o)return this.translate(e),this.hooks.trigger(this.hooks.eventTypes.move,e),void this.hooks.trigger(this.hooks.eventTypes.end,e);this.animate(t,e,o,i)},rt.prototype.animate=function(n,r,e,o){var h=this,a=u(),c=a+e,l=function(){var t=u();if(c<=t)return h.translate(r),h.hooks.trigger(h.hooks.eventTypes.move,r),void h.hooks.trigger(h.hooks.eventTypes.end,r);var i=o((t-a)/e),s={};Object.keys(r).forEach(function(t){var e=n[t],o=r[t];s[t]=(o-e)*i+e}),h.translate(s),3===h.options.probeType&&h.hooks.trigger(h.hooks.eventTypes.move,s),h.pending&&(h.timer=F(l)),h.pending||h.forceStopped||h.hooks.trigger(h.hooks.eventTypes.end,r)};this.setPending(!0),H(this.timer),l()},rt.prototype.doStop=function(){var t=this.pending;if(this.setForceStopped(!1),t){this.setPending(!1),H(this.timer);var e=this.translater.getComputedPosition();if(this.setForceStopped(!0),this.hooks.trigger(this.hooks.eventTypes.beforeForceStop,e))return!0;this.hooks.trigger(this.hooks.eventTypes.forceStop,e)}return t},rt.prototype.stop=function(){this.doStop()&&(this.hooks.trigger(this.hooks.eventTypes.callStop),this.setForceStopped(!1))},rt);function rt(){return null!==st&&st.apply(this,arguments)||this}var ht,at,ct,lt,pt=(ut.prototype.start=function(){this.dist=0,this.setMovingDirection(0),this.setDirection(0)},ut.prototype.move=function(t){return t=this.hasScroll?t:0,this.setMovingDirection(t),this.performDampingAlgorithm(t,this.options.outOfBoundaryDampingFactor)},ut.prototype.setMovingDirection=function(t){this.movingDirection=0<t?-1:t<0?1:0},ut.prototype.setDirection=function(t){this.direction=0<t?-1:t<0?1:0},ut.prototype.performDampingAlgorithm=function(t,e){var o=this.currentPos+t;return(o>this.minScrollPos||o<this.maxScrollPos)&&(o=o>this.minScrollPos&&this.options.bounces[0]||o<this.maxScrollPos&&this.options.bounces[1]?this.currentPos+t*e:o>this.minScrollPos?this.minScrollPos:this.maxScrollPos),o},ut.prototype.end=function(t){var e,o={duration:0},i=Math.abs(this.currentPos-this.startPos);return this.options.momentum&&t<this.options.momentumLimitTime&&i>this.options.momentumLimitDistance?(e=-1===this.direction&&this.options.bounces[0]||1===this.direction&&this.options.bounces[1]?this.wrapperSize:0,o=this.hasScroll?this.momentum(this.currentPos,this.startPos,t,this.maxScrollPos,this.minScrollPos,e,this.options):{destination:this.currentPos,duration:0}):this.hooks.trigger(this.hooks.eventTypes.end,o),o},ut.prototype.momentum=function(t,e,o,i,s,n,r){void 0===r&&(r=this.options);var h=t-e,a=Math.abs(h)/o,c=r.deceleration,l=r.swipeBounceTime,p={destination:t+a/c*(h<0?-1:1),duration:r.swipeTime,rate:15};return this.hooks.trigger(this.hooks.eventTypes.momentum,p,h),p.destination<i?(p.destination=n?Math.max(i-n/4,i-n/p.rate*a):i,p.duration=l):p.destination>s&&(p.destination=n?Math.min(s+n/4,s+n/p.rate*a):s,p.duration=l),p.destination=Math.round(p.destination),p},ut.prototype.updateDirection=function(){var t=Math.round(this.currentPos)-this.absStartPos;this.setDirection(t)},ut.prototype.refresh=function(t){var e=this.options.rect,o=e.size,i=e.position,s="static"===window.getComputedStyle(this.wrapper,null).position,n=X(this.wrapper);this.wrapperSize=n[o],this.setContent(t);var r=X(this.content);this.contentSize=r[o],this.relativeOffset=r[i],s&&(this.relativeOffset-=n[i]),this.computeBoundary(),this.setDirection(0)},ut.prototype.setContent=function(t){t!==this.content&&(this.content=t,this.resetState())},ut.prototype.resetState=function(){this.currentPos=0,this.startPos=0,this.dist=0,this.setDirection(0),this.setMovingDirection(0),this.resetStartPos()},ut.prototype.computeBoundary=function(){this.hooks.trigger(this.hooks.eventTypes.beforeComputeBoundary);var t={minScrollPos:0,maxScrollPos:this.wrapperSize-this.contentSize};t.maxScrollPos<0&&(t.maxScrollPos-=this.relativeOffset,0===this.options.specifiedIndexAsContent&&(t.minScrollPos=-this.relativeOffset)),this.hooks.trigger(this.hooks.eventTypes.computeBoundary,t),this.minScrollPos=t.minScrollPos,this.maxScrollPos=t.maxScrollPos,this.hasScroll=this.options.scrollable&&this.maxScrollPos<this.minScrollPos,!this.hasScroll&&this.minScrollPos<this.maxScrollPos&&(this.maxScrollPos=this.minScrollPos,this.contentSize=this.wrapperSize)},ut.prototype.updatePosition=function(t){this.currentPos=t},ut.prototype.getCurrentPos=function(){return Math.round(this.currentPos)},ut.prototype.checkInBoundary=function(){var t=this.adjustPosition(this.currentPos);return{position:t,inBoundary:t===this.getCurrentPos()}},ut.prototype.adjustPosition=function(t){var e=Math.round(t);return!this.hasScroll&&!this.hooks.trigger(this.hooks.eventTypes.ignoreHasScroll)||e>this.minScrollPos?e=this.minScrollPos:e<this.maxScrollPos&&(e=this.maxScrollPos),e},ut.prototype.updateStartPos=function(){this.startPos=this.currentPos},ut.prototype.updateAbsStartPos=function(){this.absStartPos=this.currentPos},ut.prototype.resetStartPos=function(){this.updateStartPos(),this.updateAbsStartPos()},ut.prototype.getAbsDist=function(t){return this.dist+=t,Math.abs(this.dist)},ut.prototype.destroy=function(){this.hooks.destroy()},ut);function ut(t,e,o){this.wrapper=t,this.options=o,this.hooks=new R(["beforeComputeBoundary","computeBoundary","momentum","end","ignoreHasScroll"]),this.refresh(e)}var dt=((ht={}).yes=function(t){return!0},ht.no=function(t){return t.preventDefault(),!1},ht),ft=((at={}).horizontal=((ct={}).yes="horizontal",ct.no="vertical",ct),at.vertical=((lt={}).yes="vertical",lt.no="horizontal",lt),at),vt=(yt.prototype.reset=function(){this.directionLocked=""},yt.prototype.checkMovingDirection=function(t,e,o){return this.computeDirectionLock(t,e),this.handleEventPassthrough(o)},yt.prototype.adjustDelta=function(t,e){return"horizontal"===this.directionLocked?e=0:"vertical"===this.directionLocked&&(t=0),{deltaX:t,deltaY:e}},yt.prototype.computeDirectionLock=function(t,e){""!==this.directionLocked||this.freeScroll||(t>e+this.directionLockThreshold?this.directionLocked="horizontal":e>=t+this.directionLockThreshold?this.directionLocked="vertical":this.directionLocked="none")},yt.prototype.handleEventPassthrough=function(t){var e=ft[this.directionLocked];if(e){if(this.eventPassthrough===e.yes)return dt.yes(t);if(this.eventPassthrough===e.no)return dt.no(t)}return!1},yt);function yt(t,e,o){this.directionLockThreshold=t,this.freeScroll=e,this.eventPassthrough=o,this.reset()}var mt=(gt.prototype.bindActionsHandler=function(){var s=this;this.actionsHandler.hooks.on(this.actionsHandler.hooks.eventTypes.start,function(t){return!s.enabled||s.handleStart(t)}),this.actionsHandler.hooks.on(this.actionsHandler.hooks.eventTypes.move,function(t){var e=t.deltaX,o=t.deltaY,i=t.e;return!s.enabled||s.handleMove(e,o,i)}),this.actionsHandler.hooks.on(this.actionsHandler.hooks.eventTypes.end,function(t){return!s.enabled||s.handleEnd(t)}),this.actionsHandler.hooks.on(this.actionsHandler.hooks.eventTypes.click,function(t){s.enabled&&!t._constructed&&s.handleClick(t)})},gt.prototype.handleStart=function(t){var e=u();this.moved=!1,this.startTime=e,this.directionLockAction.reset(),this.scrollBehaviorX.start(),this.scrollBehaviorY.start(),this.animater.doStop(),this.scrollBehaviorX.resetStartPos(),this.scrollBehaviorY.resetStartPos(),this.hooks.trigger(this.hooks.eventTypes.start,t)},gt.prototype.handleMove=function(t,e,o){if(!this.hooks.trigger(this.hooks.eventTypes.beforeMove,o)){var i=this.scrollBehaviorX.getAbsDist(t),s=this.scrollBehaviorY.getAbsDist(e),n=u();if(this.checkMomentum(i,s,n))return!0;if(this.directionLockAction.checkMovingDirection(i,s,o))return this.actionsHandler.setInitiated(),!0;var r=this.directionLockAction.adjustDelta(t,e),h=this.scrollBehaviorX.move(r.deltaX),a=this.scrollBehaviorY.move(r.deltaY);this.moved||(this.moved=!0,this.hooks.trigger(this.hooks.eventTypes.scrollStart)),this.animater.translate({x:h,y:a}),this.dispatchScroll(n)}},gt.prototype.dispatchScroll=function(t){t-this.startTime>this.options.momentumLimitTime&&(this.startTime=t,this.scrollBehaviorX.updateStartPos(),this.scrollBehaviorY.updateStartPos(),1===this.options.probeType&&this.hooks.trigger(this.hooks.eventTypes.scroll,this.getCurrentPos())),1<this.options.probeType&&this.hooks.trigger(this.hooks.eventTypes.scroll,this.getCurrentPos())},gt.prototype.checkMomentum=function(t,e,o){return o-this.endTime>this.options.momentumLimitTime&&e<this.options.momentumLimitDistance&&t<this.options.momentumLimitDistance},gt.prototype.handleEnd=function(t){if(!this.hooks.trigger(this.hooks.eventTypes.beforeEnd,t)){var e=this.getCurrentPos();if(this.scrollBehaviorX.updateDirection(),this.scrollBehaviorY.updateDirection(),this.hooks.trigger(this.hooks.eventTypes.end,t,e))return!0;this.animater.translate(e),this.endTime=u();var o=this.endTime-this.startTime;this.hooks.trigger(this.hooks.eventTypes.scrollEnd,e,o)}},gt.prototype.handleClick=function(t){x(t.target,this.options.preventDefaultException)||(t.preventDefault(),t.stopPropagation())},gt.prototype.getCurrentPos=function(){return{x:this.scrollBehaviorX.getCurrentPos(),y:this.scrollBehaviorY.getCurrentPos()}},gt.prototype.refresh=function(){this.endTime=0},gt.prototype.destroy=function(){this.hooks.destroy()},gt);function gt(t,e,o,i,s){this.hooks=new R(["start","beforeMove","scrollStart","scroll","beforeEnd","end","scrollEnd"]),this.scrollBehaviorX=t,this.scrollBehaviorY=e,this.actionsHandler=o,this.animater=i,this.options=s,this.directionLockAction=new vt(s.directionLockThreshold,s.freeScroll,s.eventPassthrough),this.enabled=!0,this.bindActionsHandler()}function kt(o,t,e,i){var s=["momentum","momentumLimitTime","momentumLimitDistance","deceleration","swipeBounceTime","swipeTime","outOfBoundaryDampingFactor","specifiedIndexAsContent"].reduce(function(t,e){return t[e]=o[e],t},{});return s.scrollable=!!o[t],s.bounces=e,s.rect=i,s}function Tt(i,s,t){t.forEach(function(t){var e,o;"string"==typeof t?e=o=t:(e=t.source,o=t.target),i.on(e,function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return s.trigger.apply(s,p([o],t))})})}var bt=(St.prototype.init=function(){var t=this;this.bindTranslater(),this.bindAnimater(),this.bindActions(),this.hooks.on(this.hooks.eventTypes.scrollEnd,function(){t.togglePointerEvents(!0)})},St.prototype.registerTransitionEnd=function(){this.transitionEndRegister=new I(this.content,[{name:C.transitionEnd,handler:this.transitionEnd.bind(this)}])},St.prototype.bindTranslater=function(){var o=this,t=this.translater.hooks;t.on(t.eventTypes.beforeTranslate,function(t){o.options.translateZ&&t.push(o.options.translateZ)}),t.on(t.eventTypes.translate,function(t){var e=o.getCurrentPos();o.updatePositions(t),t.x===e.x&&t.y===e.y||o.togglePointerEvents(!1)})},St.prototype.bindAnimater=function(){var e=this;this.animater.hooks.on(this.animater.hooks.eventTypes.end,function(t){e.resetPosition(e.options.bounceTime)||(e.animater.setPending(!1),e.hooks.trigger(e.hooks.eventTypes.scrollEnd,t))}),Tt(this.animater.hooks,this.hooks,[{source:this.animater.hooks.eventTypes.move,target:this.hooks.eventTypes.scroll},{source:this.animater.hooks.eventTypes.forceStop,target:this.hooks.eventTypes.scrollEnd}])},St.prototype.bindActions=function(){var s=this,n=this.actions;Tt(n.hooks,this.hooks,[{source:n.hooks.eventTypes.start,target:this.hooks.eventTypes.beforeStart},{source:n.hooks.eventTypes.start,target:this.hooks.eventTypes.beforeScrollStart},{source:n.hooks.eventTypes.beforeMove,target:this.hooks.eventTypes.beforeMove},{source:n.hooks.eventTypes.scrollStart,target:this.hooks.eventTypes.scrollStart},{source:n.hooks.eventTypes.scroll,target:this.hooks.eventTypes.scroll},{source:n.hooks.eventTypes.beforeEnd,target:this.hooks.eventTypes.beforeEnd}]),n.hooks.on(n.hooks.eventTypes.end,function(t,e){return s.hooks.trigger(s.hooks.eventTypes.touchEnd,e),!!s.hooks.trigger(s.hooks.eventTypes.end,e)||(!(n.moved||(s.hooks.trigger(s.hooks.eventTypes.scrollCancel),!s.checkClick(t)))||(s.resetPosition(s.options.bounceTime,M.bounce)?(s.animater.setForceStopped(!1),!0):void 0))}),n.hooks.on(n.hooks.eventTypes.scrollEnd,function(t,e){var o=Math.abs(t.x-s.scrollBehaviorX.startPos),i=Math.abs(t.y-s.scrollBehaviorY.startPos);if(s.checkFlick(e,o,i))return s.animater.setForceStopped(!1),void s.hooks.trigger(s.hooks.eventTypes.flick);!s.momentum(t,e)&&(!s.animater.forceStopped||n.moved)?s.hooks.trigger(s.hooks.eventTypes.scrollEnd,t):s.animater.setForceStopped(!1)})},St.prototype.checkFlick=function(t,e,o){if(1<this.hooks.events.flick.length&&t<this.options.flickLimitTime&&e<this.options.flickLimitDistance&&o<this.options.flickLimitDistance&&(1<o||1<e))return!0},St.prototype.momentum=function(t,e){var o={time:0,easing:M.swiper,newX:t.x,newY:t.y},i=this.scrollBehaviorX.end(e),s=this.scrollBehaviorY.end(e);if(o.newX=f(i.destination)?o.newX:i.destination,o.newY=f(s.destination)?o.newY:s.destination,o.time=Math.max(i.duration,s.duration),this.hooks.trigger(this.hooks.eventTypes.momentum,o,this),o.newX!==t.x||o.newY!==t.y)return(o.newX>this.scrollBehaviorX.minScrollPos||o.newX<this.scrollBehaviorX.maxScrollPos||o.newY>this.scrollBehaviorY.minScrollPos||o.newY<this.scrollBehaviorY.maxScrollPos)&&(o.easing=M.swipeBounce),this.scrollTo(o.newX,o.newY,o.time,o.easing),!0},St.prototype.checkClick=function(t){var e,o,i,s=this.animater.forceStopped;if(this.hooks.trigger(this.hooks.eventTypes.checkClick))return this.animater.setForceStopped(!1),!0;if(s)return!1;var n,r,h=this.options.dblclick,a=!1;return h&&this.lastClickTime&&(r=void 0===(n=h.delay)?300:n,u()-this.lastClickTime<r&&(a=!0,O(t,"dblclick"))),this.options.tap&&(e=t,o=this.options.tap,(i=document.createEvent("Event")).initEvent(o,!0,!0),i.pageX=e.pageX,i.pageY=e.pageY,e.target.dispatchEvent(i)),this.options.click&&!x(t.target,this.options.preventDefaultException)&&O(t),this.lastClickTime=a?null:u(),!0},St.prototype.resize=function(){var t=this;this.actions.enabled&&(a&&(this.wrapper.scrollTop=0),clearTimeout(this.resizeTimeout),this.resizeTimeout=window.setTimeout(function(){t.hooks.trigger(t.hooks.eventTypes.resize)},this.options.resizePolling))},St.prototype.transitionEnd=function(t){t.target===this.content&&this.animater.pending&&(this.animater.transitionTime(),this.resetPosition(this.options.bounceTime,M.bounce)||(this.animater.setPending(!1),3!==this.options.probeType&&this.hooks.trigger(this.hooks.eventTypes.scrollEnd,this.getCurrentPos())))},St.prototype.togglePointerEvents=function(t){void 0===t&&(t=!0);for(var e=this.content.children.length?this.content.children:[this.content],o=t?"auto":"none",i=0;i<e.length;i++){var s=e[i];s.isBScrollContainer||(s.style.pointerEvents=o)}},St.prototype.refresh=function(t){var e=this.setContent(t);this.hooks.trigger(this.hooks.eventTypes.beforeRefresh),this.scrollBehaviorX.refresh(t),this.scrollBehaviorY.refresh(t),e&&(this.translater.setContent(t),this.animater.setContent(t),this.transitionEndRegister.destroy(),this.registerTransitionEnd(),this.options.bindToTarget&&this.actionsHandler.setContent(t)),this.actions.refresh(),this.wrapperOffset=b(this.wrapper)},St.prototype.setContent=function(t){var e=t!==this.content;return e&&(this.content=t),e},St.prototype.scrollBy=function(t,e,o,i){void 0===o&&(o=0);var s=this.getCurrentPos(),n=s.x,r=s.y;i=i||M.bounce,t+=n,e+=r,this.scrollTo(t,e,o,i)},St.prototype.scrollTo=function(t,e,o,i,s){void 0===o&&(o=0),void 0===i&&(i=M.bounce),void 0===s&&(s={start:{},end:{}});var n=this.options.useTransition?i.style:i.fn,r=this.getCurrentPos(),h=c({x:r.x,y:r.y},s.start),a=c({x:t,y:e},s.end);this.hooks.trigger(this.hooks.eventTypes.scrollTo,a),function(t,e){for(var o=0,i=Object.keys(t);o<i.length;o++){var s=i[o];if(t[s]!==e[s])return}return 1}(h,a)||this.animater.move(h,a,o,n)},St.prototype.scrollToElement=function(t,e,o,i,s){function n(t,e,o){return"number"==typeof t?t:t?Math.round(e/2-o/2):0}var r=g(t),h=b(r);o=n(o,r.offsetWidth,this.wrapper.offsetWidth),i=n(i,r.offsetHeight,this.wrapper.offsetHeight);function a(t,e,o,i){return t-=e,t=i.adjustPosition(t-o)}h.left=a(h.left,this.wrapperOffset.left,o,this.scrollBehaviorX),h.top=a(h.top,this.wrapperOffset.top,i,this.scrollBehaviorY),this.hooks.trigger(this.hooks.eventTypes.scrollToElement,r,h)||this.scrollTo(h.left,h.top,e,s)},St.prototype.resetPosition=function(t,e){void 0===t&&(t=0),void 0===e&&(e=M.bounce);var o=this.scrollBehaviorX.checkInBoundary(),i=o.position,s=o.inBoundary,n=this.scrollBehaviorY.checkInBoundary(),r=n.position,h=n.inBoundary;return(!s||!h)&&(l&&(this._reflow=this.content.offsetHeight),this.scrollTo(i,r,t,e),!0)},St.prototype.updatePositions=function(t){this.scrollBehaviorX.updatePosition(t.x),this.scrollBehaviorY.updatePosition(t.y)},St.prototype.getCurrentPos=function(){return this.actions.getCurrentPos()},St.prototype.enable=function(){this.actions.enabled=!0},St.prototype.disable=function(){H(this.animater.timer),this.actions.enabled=!1},St.prototype.destroy=function(){var e=this;["resizeRegister","transitionEndRegister","actionsHandler","actions","hooks","animater","translater","scrollBehaviorX","scrollBehaviorY"].forEach(function(t){return e[t].destroy()})},St);function St(t,e,o){this.wrapper=t,this.content=e,this.resizeTimeout=0,this.hooks=new R(["beforeStart","beforeMove","beforeScrollStart","scrollStart","scroll","beforeEnd","scrollEnd","resize","touchEnd","end","flick","scrollCancel","momentum","scrollTo","scrollToElement","beforeRefresh"]),this.options=o;var i,s,n,r,h,a,c=this.options.bounce,l=c.left,p=c.right,u=c.top,d=c.bottom;this.scrollBehaviorX=new pt(t,e,kt(o,"scrollX",[l,p],{size:"width",position:"left"})),this.scrollBehaviorY=new pt(t,e,kt(o,"scrollY",[u,d],{size:"height",position:"top"})),this.translater=new G(this.content),this.animater=(i=this.content,s=this.translater,n=this.options,r=n.useTransition,h={},Object.defineProperty(h,"probeType",{enumerable:!0,configurable:!1,get:function(){return n.probeType}}),new(r?ot:nt)(i,s,h)),this.actionsHandler=new Z(this.options.bindToTarget?this.content:t,(a=this.options,["click","bindToWrapper","disableMouse","disableTouch","preventDefault","stopPropagation","tagException","preventDefaultException","autoEndDistance"].reduce(function(t,e){return t[e]=a[e],t},{}))),this.actions=new mt(this.scrollBehaviorX,this.scrollBehaviorY,this.actionsHandler,this.animater,this.options);var f=this.resize.bind(this);this.resizeRegister=new I(window,[{name:"orientationchange",handler:f},{name:"resize",handler:f}]),this.registerTransitionEnd(),this.init()}var Pt,wt=(e(Et,Pt=R),Et.use=function(e){var t=e.pluginName;return Et.plugins.some(function(t){return e===t.ctor})||(f(t)?n("Plugin Class must specify plugin's name in static property by 'pluginName' field."):Et.pluginsMap[t]?n("This plugin has been registered, maybe you need change plugin's name"):(Et.pluginsMap[t]=!0,Et.plugins.push({name:t,applyOrder:e.applyOrder,ctor:e}))),Et},Et.prototype.setContent=function(t){var e=!1,o=!0,i=t.children[this.options.specifiedIndexAsContent];return i?(e=this.content!==i)&&(this.content=i):(n("The wrapper need at least one child element to be content element to scroll."),o=!1),{valid:o,contentChanged:e}},Et.prototype.init=function(t){var e=this;(this.wrapper=t).isBScrollContainer=!0,this.scroller=new bt(t,this.content,this.options),this.scroller.hooks.on(this.scroller.hooks.eventTypes.resize,function(){e.refresh()}),this.eventBubbling(),this.handleAutoBlur(),this.enable(),this.proxy(s),this.applyPlugins(),this.refreshWithoutReset(this.content);var o=this.options,i={x:o.startX,y:o.startY};this.hooks.trigger(this.hooks.eventTypes.beforeInitialScrollTo,i)||this.scroller.scrollTo(i.x,i.y)},Et.prototype.applyPlugins=function(){var o=this,i=this.options;Et.plugins.sort(function(t,e){var o,i=((o={}).pre=-1,o.post=1,o);return(t.applyOrder?i[t.applyOrder]:0)-(e.applyOrder?i[e.applyOrder]:0)}).forEach(function(t){var e=t.ctor;i[t.name]&&"function"==typeof e&&(o.plugins[t.name]=new e(o))})},Et.prototype.handleAutoBlur=function(){this.options.autoBlur&&this.on(this.eventTypes.beforeScrollStart,function(){var t=document.activeElement;!t||"INPUT"!==t.tagName&&"TEXTAREA"!==t.tagName||t.blur()})},Et.prototype.eventBubbling=function(){Tt(this.scroller.hooks,this,[this.eventTypes.beforeScrollStart,this.eventTypes.scrollStart,this.eventTypes.scroll,this.eventTypes.scrollEnd,this.eventTypes.scrollCancel,this.eventTypes.touchEnd,this.eventTypes.flick])},Et.prototype.refreshWithoutReset=function(t){this.scroller.refresh(t),this.hooks.trigger(this.hooks.eventTypes.refresh,t),this.trigger(this.eventTypes.refresh,t)},Et.prototype.proxy=function(t){var r=this;t.forEach(function(t){var e,o,i,s=t.key,n=t.sourceKey;e=r,o=n,i=s,K.get=function(){return function(t,e){for(var o=e.split("."),i=0;i<o.length-1;i++)if("object"!=typeof(t=t[o[i]])||!t)return;var s=o.pop();return"function"==typeof t[s]?function(){return t[s].apply(t,arguments)}:t[s]}(this,o)},K.set=function(t){!function(t,e,o){for(var i,s=e.split("."),n=0;n<s.length-1;n++)t[i=s[n]]||(t[i]={}),t=t[i];t[s.pop()]=o}(this,o,t)},Object.defineProperty(e,i,K)})},Et.prototype.refresh=function(){var t,e=this.setContent(this.wrapper),o=e.contentChanged;e.valid&&(t=this.content,this.refreshWithoutReset(t),o&&(this.hooks.trigger(this.hooks.eventTypes.contentChanged,t),this.trigger(this.eventTypes.contentChanged,t)),this.scroller.resetPosition())},Et.prototype.enable=function(){this.scroller.enable(),this.hooks.trigger(this.hooks.eventTypes.enable),this.trigger(this.eventTypes.enable)},Et.prototype.disable=function(){this.scroller.disable(),this.hooks.trigger(this.hooks.eventTypes.disable),this.trigger(this.eventTypes.disable)},Et.prototype.destroy=function(){this.hooks.trigger(this.hooks.eventTypes.destroy),this.trigger(this.eventTypes.destroy),this.scroller.destroy()},Et.prototype.eventRegister=function(t){this.registerType(t)},Et.plugins=[],Et.pluginsMap={},Et);function Et(t,e){var o=Pt.call(this,["refresh","contentChanged","enable","disable","beforeScrollStart","scrollStart","scroll","scrollEnd","scrollCancel","touchEnd","flick","destroy"])||this,i=g(t);return i?(o.plugins={},o.options=(new q).merge(e).process(),o.setContent(i).valid&&(o.hooks=new R(["refresh","enable","disable","destroy","beforeInitialScrollTo","contentChanged"]),o.init(i)),o):(n("Can not resolve the wrapper DOM."),o)}function Bt(t,e){return new wt(t,e)}Bt.use=wt.use,Bt.plugins=wt.plugins,Bt.pluginsMap=wt.pluginsMap;var Ct=Bt;t.Behavior=pt,t.CustomOptions=W,t.createBScroll=Bt,t.default=Ct,Object.defineProperty(t,"__esModule",{value:!0})}),"undefined"!=typeof window&&window.BScroll&&(window.BScroll=window.BScroll.default); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).BScroll={})}(this,function(t){"use strict";var i=function(t,e){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])})(t,e)};function e(t,e){function o(){this.constructor=t}i(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}var c=function(){return(c=Object.assign||function(t){for(var e,o=1,i=arguments.length;o<i;o++)for(var n in e=arguments[o])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,arguments)};function p(){for(var t=0,e=0,o=arguments.length;e<o;e++)t+=arguments[e].length;for(var i=Array(t),n=0,e=0;e<o;e++)for(var s=arguments[e],r=0,h=s.length;r<h;r++,n++)i[n]=s[r];return i}var n=[{sourceKey:"scroller.scrollBehaviorX.currentPos",key:"x"},{sourceKey:"scroller.scrollBehaviorY.currentPos",key:"y"},{sourceKey:"scroller.scrollBehaviorX.hasScroll",key:"hasHorizontalScroll"},{sourceKey:"scroller.scrollBehaviorY.hasScroll",key:"hasVerticalScroll"},{sourceKey:"scroller.scrollBehaviorX.contentSize",key:"scrollerWidth"},{sourceKey:"scroller.scrollBehaviorY.contentSize",key:"scrollerHeight"},{sourceKey:"scroller.scrollBehaviorX.maxScrollPos",key:"maxScrollX"},{sourceKey:"scroller.scrollBehaviorY.maxScrollPos",key:"maxScrollY"},{sourceKey:"scroller.scrollBehaviorX.minScrollPos",key:"minScrollX"},{sourceKey:"scroller.scrollBehaviorY.minScrollPos",key:"minScrollY"},{sourceKey:"scroller.scrollBehaviorX.movingDirection",key:"movingDirectionX"},{sourceKey:"scroller.scrollBehaviorY.movingDirection",key:"movingDirectionY"},{sourceKey:"scroller.scrollBehaviorX.direction",key:"directionX"},{sourceKey:"scroller.scrollBehaviorY.direction",key:"directionY"},{sourceKey:"scroller.actions.enabled",key:"enabled"},{sourceKey:"scroller.animater.pending",key:"pending"},{sourceKey:"scroller.animater.stop",key:"stop"},{sourceKey:"scroller.scrollTo",key:"scrollTo"},{sourceKey:"scroller.scrollBy",key:"scrollBy"},{sourceKey:"scroller.scrollToElement",key:"scrollToElement"},{sourceKey:"scroller.resetPosition",key:"resetPosition"}];function s(t){console.error("[BScroll warn]: "+t)}var r="undefined"!=typeof window,o=r&&navigator.userAgent.toLowerCase(),h=!(!o||!/wechatdevtools/.test(o)),a=o&&0<o.indexOf("android"),l=function(){if("string"!=typeof o)return!1;var t=/os (\d\d?_\d(_\d)?)/.exec(o);if(!t)return!1;var e=t[1].split("_").map(function(t){return parseInt(t,10)});return!!(13<=e[0]&&4<=e[1])}();function u(){return window.performance&&window.performance.now&&window.performance.timing?window.performance.now()+window.performance.timing.navigationStart:+new Date}var d=function(t,e){for(var o in e)t[o]=e[o];return t};function f(t){return null==t}var v=r&&document.createElement("div").style,y=function(){if(!r)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!==v[o.value])return o.key}return!1}();function m(t){return!1===y?t:"standard"===y?"transitionEnd"===t?"transitionend":t:y+t.charAt(0).toUpperCase()+t.substr(1)}function g(t){return"string"==typeof t?document.querySelector(t):t}function k(t,e,o,i){t.addEventListener(e,o,{passive:!1,capture:!!i})}function T(t,e,o,i){t.removeEventListener(e,o,{capture:!!i})}function b(t){for(var e=0,o=0;t;)e-=t.offsetLeft,o-=t.offsetTop,t=t.offsetParent;return{left:e,top:o}}y&&"standard"!==y&&y.toLowerCase();var S=m("transform"),P=m("transition"),w=r&&m("perspective")in v,E=r&&("ontouchstart"in window||h),B=r&&P in v,C={transform:S,transition:P,transitionTimingFunction:m("transitionTimingFunction"),transitionDuration:m("transitionDuration"),transitionDelay:m("transitionDelay"),transformOrigin:m("transformOrigin"),transitionEnd:m("transitionEnd"),transitionProperty:m("transitionProperty")},D={touchstart:1,touchmove:1,touchend:1,mousedown:2,mousemove:2,mouseup:2};function x(t){if(t instanceof window.SVGElement){var e=t.getBoundingClientRect();return{top:e.top,left:e.left,width:e.width,height:e.height}}return{top:t.offsetTop,left:t.offsetLeft,width:t.offsetWidth,height:t.offsetHeight}}function X(t,e){for(var o in e)if(e[o].test(t[o]))return!0;return!1}var Y=X;function O(t,e){var o;void 0===e&&(e="click"),"mouseup"===t.type?o=t:"touchend"!==t.type&&"touchcancel"!==t.type||(o=t.changedTouches[0]);var i,n={};o&&(n.screenX=o.screenX||0,n.screenY=o.screenY||0,n.clientX=o.clientX||0,n.clientY=o.clientY||0);var s=!0,r=!0,h={ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey};if("undefined"!=typeof MouseEvent)try{i=new MouseEvent(e,d(c({bubbles:s,cancelable:r},h),n))}catch(t){a()}else a();function a(){(i=document.createEvent("Event")).initEvent(e,s,r),d(i,n)}i.forwardedTouchEvent=!0,i._constructed=!0,t.target.dispatchEvent(i)}var M={swipe:{style:"cubic-bezier(0.23, 1, 0.32, 1)",fn:function(t){return 1+--t*t*t*t*t}},swipeBounce:{style:"cubic-bezier(0.25, 0.46, 0.45, 0.94)",fn:function(t){return t*(2-t)}},bounce:{style:"cubic-bezier(0.165, 0.84, 0.44, 1)",fn:function(t){return 1- --t*t*t*t}}},L=r&&window;function A(){}function z(t){}var F=r?L.requestAnimationFrame||L.webkitRequestAnimationFrame||L.mozRequestAnimationFrame||L.oRequestAnimationFrame||function(t){return window.setTimeout(t,(t.interval||1e3/60)/2)}:A,H=r?L.cancelAnimationFrame||L.webkitCancelAnimationFrame||L.mozCancelAnimationFrame||L.oCancelAnimationFrame||function(t){window.clearTimeout(t)}:A,K={enumerable:!0,configurable:!0,get:z,set:z};var R=(j.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},j.prototype.once=function(o,i,n){var s=this;void 0===n&&(n=this),this.hasType(o);var r=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];s.off(o,r),i.apply(n,t)};return r.fn=i,this.on(o,r),this},j.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 i=o.length;i--;)(o[i][0]===e||o[i][0]&&o[i][0].fn===e)&&o.splice(i,1);return this}},j.prototype.trigger=function(t){for(var e=[],o=1;o<arguments.length;o++)e[o-1]=arguments[o];this.hasType(t);var i=this.events[t];if(i)for(var n,s=i.length,r=p(i),h=0;h<s;h++){var a=r[h],c=a[0],l=a[1];if(c&&!0===(n=c.apply(l,e)))return n}},j.prototype.registerType=function(t){var e=this;t.forEach(function(t){e.eventTypes[t]=t})},j.prototype.destroy=function(){this.events={},this.eventTypes={}},j.prototype.hasType=function(t){var e=this.eventTypes;e[t]===t||s('EventEmitter has used unknown event type: "'+t+'", should be oneof ['+Object.keys(e).map(function(t){return JSON.stringify(t)})+"]")},j);function j(t){this.events={},this.eventTypes={},this.registerType(t)}var I=(_.prototype.destroy=function(){this.removeDOMEvents(),this.events=[]},_.prototype.addDOMEvents=function(){this.handleDOMEvents(k)},_.prototype.removeDOMEvents=function(){this.handleDOMEvents(T)},_.prototype.handleDOMEvents=function(e){var o=this,i=this.wrapper;this.events.forEach(function(t){e(i,t.name,o,!!t.capture)})},_.prototype.handleEvent=function(e){var o=e.type;this.events.some(function(t){return t.name===o&&(t.handler(e),!0)})},_);function _(t,e){this.wrapper=t,this.events=e,this.addDOMEvents()}function W(){}var N,q=(e(U,N=W),U.prototype.merge=function(t){if(!t)return this;for(var e in t)"bounce"!==e?this[e]=t[e]:this.bounce=this.resolveBounce(t[e]);return this},U.prototype.process=function(){return this.translateZ=this.HWCompositing&&w?" translateZ(1px)":"",this.useTransition=this.useTransition&&B,this.preventDefault=!this.eventPassthrough&&this.preventDefault,this.scrollX="horizontal"!==this.eventPassthrough&&this.scrollX,this.scrollY="vertical"!==this.eventPassthrough&&this.scrollY,this.freeScroll=this.freeScroll&&!this.eventPassthrough,this.scrollX=!!this.freeScroll||this.scrollX,this.scrollY=!!this.freeScroll||this.scrollY,this.directionLockThreshold=this.eventPassthrough?0:this.directionLockThreshold,this},U.prototype.resolveBounce=function(t){var e={top:!0,right:!0,bottom:!0,left:!0},o="object"==typeof t?d(e,t):t?e:{top:!1,right:!1,bottom:!1,left:!1};return o},U);function U(){var t=N.call(this)||this;return t.startX=0,t.startY=0,t.scrollX=!1,t.scrollY=!0,t.freeScroll=!1,t.directionLockThreshold=5,t.eventPassthrough="",t.click=!1,t.dblclick=!1,t.tap="",t.bounce={top:!0,bottom:!0,left:!0,right:!0},t.bounceTime=800,t.momentum=!0,t.momentumLimitTime=300,t.momentumLimitDistance=15,t.swipeTime=2500,t.swipeBounceTime=500,t.deceleration=.0015,t.flickLimitTime=200,t.flickLimitDistance=100,t.resizePolling=60,t.probeType=0,t.stopPropagation=!1,t.preventDefault=!0,t.preventDefaultException={tagName:/^(INPUT|TEXTAREA|BUTTON|SELECT|AUDIO)$/},t.tagException={tagName:/^TEXTAREA$/},t.HWCompositing=!0,t.useTransition=!0,t.bindToWrapper=!1,t.bindToTarget=!1,t.disableMouse=E,t.disableTouch=!E,t.autoBlur=!0,t.autoEndDistance=5,t.outOfBoundaryDampingFactor=1/3,t.specifiedIndexAsContent=0,t}var Z=(V.prototype.handleDOMEvents=function(){var t=this.options,e=t.bindToWrapper,o=t.disableMouse,i=t.disableTouch,n=t.click,s=this.wrapper,r=e?s:window,h=[],a=[],c=!i,l=!o;n&&h.push({name:"click",handler:this.click.bind(this),capture:!0}),c&&(h.push({name:"touchstart",handler:this.start.bind(this)}),a.push({name:"touchmove",handler:this.move.bind(this)},{name:"touchend",handler:this.end.bind(this)},{name:"touchcancel",handler:this.end.bind(this)})),l&&(h.push({name:"mousedown",handler:this.start.bind(this)}),a.push({name:"mousemove",handler:this.move.bind(this)},{name:"mouseup",handler:this.end.bind(this)})),this.wrapperEventRegister=new I(s,h),this.targetEventRegister=new I(r,a)},V.prototype.beforeHandler=function(t,e){var o=this.options,i=o.preventDefault,n=o.stopPropagation,s=o.preventDefaultException;!{start:function(){return i&&!X(t.target,s)},end:function(){return i&&!X(t.target,s)},move:function(){return i}}[e]()||t.preventDefault(),n&&t.stopPropagation()},V.prototype.setInitiated=function(t){void 0===t&&(t=0),this.initiated=t},V.prototype.start=function(t){var e,o=D[t.type];this.initiated&&this.initiated!==o||(this.setInitiated(o),Y(t.target,this.options.tagException)?this.setInitiated():2===o&&0!==t.button||this.hooks.trigger(this.hooks.eventTypes.beforeStart,t)||(this.beforeHandler(t,"start"),e=t.touches?t.touches[0]:t,this.pointX=e.pageX,this.pointY=e.pageY,this.hooks.trigger(this.hooks.eventTypes.start,t)))},V.prototype.move=function(t){var e,o,i,n,s,r,h,a;D[t.type]===this.initiated&&(this.beforeHandler(t,"move"),o=(e=t.touches?t.touches[0]:t).pageX-this.pointX,i=e.pageY-this.pointY,this.pointX=e.pageX,this.pointY=e.pageY,this.hooks.trigger(this.hooks.eventTypes.move,{deltaX:o,deltaY:i,e:t})||(n=document.documentElement.scrollLeft||window.pageXOffset||document.body.scrollLeft,s=document.documentElement.scrollTop||window.pageYOffset||document.body.scrollTop,r=this.pointX-n,h=this.pointY-s,a=this.options.autoEndDistance,(r>document.documentElement.clientWidth-a||h>document.documentElement.clientHeight-a||r<a||h<a)&&this.end(t)))},V.prototype.end=function(t){D[t.type]===this.initiated&&(this.setInitiated(),this.beforeHandler(t,"end"),this.hooks.trigger(this.hooks.eventTypes.end,t))},V.prototype.click=function(t){this.hooks.trigger(this.hooks.eventTypes.click,t)},V.prototype.setContent=function(t){t!==this.wrapper&&(this.wrapper=t,this.wrapperEventRegister.destroy(),this.targetEventRegister.destroy(),this.handleDOMEvents())},V.prototype.destroy=function(){this.wrapperEventRegister.destroy(),this.targetEventRegister.destroy(),this.hooks.destroy()},V);function V(t,e){this.wrapper=t,this.options=e,this.hooks=new R(["beforeStart","start","move","end","click"]),this.handleDOMEvents()}var $={x:["translateX","px"],y:["translateY","px"]},G=(J.prototype.getComputedPosition=function(){var t=window.getComputedStyle(this.content,null)[C.transform].split(")")[0].split(", ");return{x:+(t[12]||t[4])||0,y:+(t[13]||t[5])||0}},J.prototype.translate=function(n){var s=[];Object.keys(n).forEach(function(t){var e,o,i;!$[t]||(e=$[t][0])&&(o=$[t][1],i=n[t],s.push(e+"("+i+o+")"))}),this.hooks.trigger(this.hooks.eventTypes.beforeTranslate,s,n),this.style[C.transform]=s.join(" "),this.hooks.trigger(this.hooks.eventTypes.translate,n)},J.prototype.setContent=function(t){this.content!==t&&(this.content=t,this.style=t.style)},J.prototype.destroy=function(){this.hooks.destroy()},J);function J(t){this.setContent(t),this.hooks=new R(["beforeTranslate","translate"])}var Q=(tt.prototype.translate=function(t){this.translater.translate(t)},tt.prototype.setPending=function(t){this.pending=t},tt.prototype.setForceStopped=function(t){this.forceStopped=t},tt.prototype.setContent=function(t){this.content!==t&&(this.content=t,this.style=t.style,this.stop())},tt.prototype.destroy=function(){this.hooks.destroy(),H(this.timer)},tt);function tt(t,e,o){this.translater=e,this.options=o,this.timer=0,this.hooks=new R(["move","end","beforeForceStop","forceStop","callStop","time","timeFunction"]),this.setContent(t)}function et(t,e,o,i){function n(t,e){var o=t-e;return 0<o?-1:o<0?1:0}var s=n(e.x,t.x),r=n(e.y,t.y),h=o.x-i.x,a=o.y-i.y;return s*h<=0&&r*a<=0}var ot,it=(e(nt,ot=Q),nt.prototype.startProbe=function(e){var o=this,i=this.translater.getComputedPosition(),n=i,s=function(){var t=o.translater.getComputedPosition();et(n,e,t,i)&&o.hooks.trigger(o.hooks.eventTypes.move,t),i=t,o.pending||o.forceStopped||o.hooks.trigger(o.hooks.eventTypes.end,t),o.pending&&(o.timer=F(s))};H(this.timer),s()},nt.prototype.transitionTime=function(t){void 0===t&&(t=0),this.style[C.transitionDuration]=t+"ms",this.hooks.trigger(this.hooks.eventTypes.time,t)},nt.prototype.transitionTimingFunction=function(t){this.style[C.transitionTimingFunction]=t,this.hooks.trigger(this.hooks.eventTypes.timeFunction,t)},nt.prototype.transitionProperty=function(){this.style[C.transitionProperty]=C.transform},nt.prototype.move=function(t,e,o,i){this.setPending(0<o),this.transitionTimingFunction(i),this.transitionProperty(),this.transitionTime(o),this.translate(e),o&&3===this.options.probeType&&this.startProbe(e),o||(this._reflow=this.content.offsetHeight,this.hooks.trigger(this.hooks.eventTypes.move,e),this.hooks.trigger(this.hooks.eventTypes.end,e))},nt.prototype.doStop=function(){var t=this.pending;if(this.setForceStopped(!1),t){this.setPending(!1),H(this.timer);var e=this.translater.getComputedPosition(),o=e.x,i=e.y;if(this.transitionTime(),this.translate({x:o,y:i}),this.setForceStopped(!0),this.hooks.trigger(this.hooks.eventTypes.beforeForceStop,{x:o,y:i}))return!0;this.hooks.trigger(this.hooks.eventTypes.forceStop,{x:o,y:i})}return t},nt.prototype.stop=function(){this.doStop()&&(this.hooks.trigger(this.hooks.eventTypes.callStop),this.setForceStopped(!1))},nt);function nt(){return null!==ot&&ot.apply(this,arguments)||this}var st,rt=(e(ht,st=Q),ht.prototype.move=function(t,e,o,i){if(!o)return this.translate(e),this.hooks.trigger(this.hooks.eventTypes.move,e),void this.hooks.trigger(this.hooks.eventTypes.end,e);this.animate(t,e,o,i)},ht.prototype.animate=function(s,r,e,o){var h=this,a=u(),c=a+e,l=function(){var t=u();if(c<=t)return h.translate(r),h.hooks.trigger(h.hooks.eventTypes.move,r),void h.hooks.trigger(h.hooks.eventTypes.end,r);var i=o((t-a)/e),n={};Object.keys(r).forEach(function(t){var e=s[t],o=r[t];n[t]=(o-e)*i+e}),h.translate(n),3===h.options.probeType&&h.hooks.trigger(h.hooks.eventTypes.move,n),h.pending&&(h.timer=F(l)),h.pending||h.forceStopped||h.hooks.trigger(h.hooks.eventTypes.end,r)};this.setPending(!0),H(this.timer),l()},ht.prototype.doStop=function(){var t=this.pending;if(this.setForceStopped(!1),t){this.setPending(!1),H(this.timer);var e=this.translater.getComputedPosition();if(this.setForceStopped(!0),this.hooks.trigger(this.hooks.eventTypes.beforeForceStop,e))return!0;this.hooks.trigger(this.hooks.eventTypes.forceStop,e)}return t},ht.prototype.stop=function(){this.doStop()&&(this.hooks.trigger(this.hooks.eventTypes.callStop),this.setForceStopped(!1))},ht);function ht(){return null!==st&&st.apply(this,arguments)||this}var at,ct,lt,pt,ut=(dt.prototype.start=function(){this.dist=0,this.setMovingDirection(0),this.setDirection(0)},dt.prototype.move=function(t){return t=this.hasScroll?t:0,this.setMovingDirection(t),this.performDampingAlgorithm(t,this.options.outOfBoundaryDampingFactor)},dt.prototype.setMovingDirection=function(t){this.movingDirection=0<t?-1:t<0?1:0},dt.prototype.setDirection=function(t){this.direction=0<t?-1:t<0?1:0},dt.prototype.performDampingAlgorithm=function(t,e){var o=this.currentPos+t;return(o>this.minScrollPos||o<this.maxScrollPos)&&(o=o>this.minScrollPos&&this.options.bounces[0]||o<this.maxScrollPos&&this.options.bounces[1]?this.currentPos+t*e:o>this.minScrollPos?this.minScrollPos:this.maxScrollPos),o},dt.prototype.end=function(t){var e,o={duration:0},i=Math.abs(this.currentPos-this.startPos);return this.options.momentum&&t<this.options.momentumLimitTime&&i>this.options.momentumLimitDistance?(e=-1===this.direction&&this.options.bounces[0]||1===this.direction&&this.options.bounces[1]?this.wrapperSize:0,o=this.hasScroll?this.momentum(this.currentPos,this.startPos,t,this.maxScrollPos,this.minScrollPos,e,this.options):{destination:this.currentPos,duration:0}):this.hooks.trigger(this.hooks.eventTypes.end,o),o},dt.prototype.momentum=function(t,e,o,i,n,s,r){void 0===r&&(r=this.options);var h=t-e,a=Math.abs(h)/o,c=r.deceleration,l=r.swipeBounceTime,p={destination:t+a/c*(h<0?-1:1),duration:r.swipeTime,rate:15};return this.hooks.trigger(this.hooks.eventTypes.momentum,p,h),p.destination<i?(p.destination=s?Math.max(i-s/4,i-s/p.rate*a):i,p.duration=l):p.destination>n&&(p.destination=s?Math.min(n+s/4,n+s/p.rate*a):n,p.duration=l),p.destination=Math.round(p.destination),p},dt.prototype.updateDirection=function(){var t=Math.round(this.currentPos)-this.absStartPos;this.setDirection(t)},dt.prototype.refresh=function(t){var e=this.options.rect,o=e.size,i=e.position,n="static"===window.getComputedStyle(this.wrapper,null).position,s=x(this.wrapper);this.wrapperSize=s[o],this.setContent(t);var r=x(this.content);this.contentSize=r[o],this.relativeOffset=r[i],n&&(this.relativeOffset-=s[i]),this.computeBoundary(),this.setDirection(0)},dt.prototype.setContent=function(t){t!==this.content&&(this.content=t,this.resetState())},dt.prototype.resetState=function(){this.currentPos=0,this.startPos=0,this.dist=0,this.setDirection(0),this.setMovingDirection(0),this.resetStartPos()},dt.prototype.computeBoundary=function(){this.hooks.trigger(this.hooks.eventTypes.beforeComputeBoundary);var t={minScrollPos:0,maxScrollPos:this.wrapperSize-this.contentSize};t.maxScrollPos<0&&(t.maxScrollPos-=this.relativeOffset,0===this.options.specifiedIndexAsContent&&(t.minScrollPos=-this.relativeOffset)),this.hooks.trigger(this.hooks.eventTypes.computeBoundary,t),this.minScrollPos=t.minScrollPos,this.maxScrollPos=t.maxScrollPos,this.hasScroll=this.options.scrollable&&this.maxScrollPos<this.minScrollPos,!this.hasScroll&&this.minScrollPos<this.maxScrollPos&&(this.maxScrollPos=this.minScrollPos,this.contentSize=this.wrapperSize)},dt.prototype.updatePosition=function(t){this.currentPos=t},dt.prototype.getCurrentPos=function(){return Math.round(this.currentPos)},dt.prototype.checkInBoundary=function(){var t=this.adjustPosition(this.currentPos);return{position:t,inBoundary:t===this.getCurrentPos()}},dt.prototype.adjustPosition=function(t){var e=Math.round(t);return!this.hasScroll&&!this.hooks.trigger(this.hooks.eventTypes.ignoreHasScroll)||e>this.minScrollPos?e=this.minScrollPos:e<this.maxScrollPos&&(e=this.maxScrollPos),e},dt.prototype.updateStartPos=function(){this.startPos=this.currentPos},dt.prototype.updateAbsStartPos=function(){this.absStartPos=this.currentPos},dt.prototype.resetStartPos=function(){this.updateStartPos(),this.updateAbsStartPos()},dt.prototype.getAbsDist=function(t){return this.dist+=t,Math.abs(this.dist)},dt.prototype.destroy=function(){this.hooks.destroy()},dt);function dt(t,e,o){this.wrapper=t,this.options=o,this.hooks=new R(["beforeComputeBoundary","computeBoundary","momentum","end","ignoreHasScroll"]),this.refresh(e)}var ft=((at={}).yes=function(t){return!0},at.no=function(t){return t.preventDefault(),!1},at),vt=((ct={}).horizontal=((lt={}).yes="horizontal",lt.no="vertical",lt),ct.vertical=((pt={}).yes="vertical",pt.no="horizontal",pt),ct),yt=(mt.prototype.reset=function(){this.directionLocked=""},mt.prototype.checkMovingDirection=function(t,e,o){return this.computeDirectionLock(t,e),this.handleEventPassthrough(o)},mt.prototype.adjustDelta=function(t,e){return"horizontal"===this.directionLocked?e=0:"vertical"===this.directionLocked&&(t=0),{deltaX:t,deltaY:e}},mt.prototype.computeDirectionLock=function(t,e){""!==this.directionLocked||this.freeScroll||(t>e+this.directionLockThreshold?this.directionLocked="horizontal":e>=t+this.directionLockThreshold?this.directionLocked="vertical":this.directionLocked="none")},mt.prototype.handleEventPassthrough=function(t){var e=vt[this.directionLocked];if(e){if(this.eventPassthrough===e.yes)return ft.yes(t);if(this.eventPassthrough===e.no)return ft.no(t)}return!1},mt);function mt(t,e,o){this.directionLockThreshold=t,this.freeScroll=e,this.eventPassthrough=o,this.reset()}var gt=(kt.prototype.bindActionsHandler=function(){var n=this;this.actionsHandler.hooks.on(this.actionsHandler.hooks.eventTypes.start,function(t){return!n.enabled||n.handleStart(t)}),this.actionsHandler.hooks.on(this.actionsHandler.hooks.eventTypes.move,function(t){var e=t.deltaX,o=t.deltaY,i=t.e;return!n.enabled||n.handleMove(e,o,i)}),this.actionsHandler.hooks.on(this.actionsHandler.hooks.eventTypes.end,function(t){return!n.enabled||n.handleEnd(t)}),this.actionsHandler.hooks.on(this.actionsHandler.hooks.eventTypes.click,function(t){n.enabled&&!t._constructed&&n.handleClick(t)})},kt.prototype.handleStart=function(t){var e=u();this.moved=!1,this.startTime=e,this.directionLockAction.reset(),this.scrollBehaviorX.start(),this.scrollBehaviorY.start(),this.animater.doStop(),this.scrollBehaviorX.resetStartPos(),this.scrollBehaviorY.resetStartPos(),this.hooks.trigger(this.hooks.eventTypes.start,t)},kt.prototype.handleMove=function(t,e,o){if(!this.hooks.trigger(this.hooks.eventTypes.beforeMove,o)){var i=this.scrollBehaviorX.getAbsDist(t),n=this.scrollBehaviorY.getAbsDist(e),s=u();if(this.checkMomentum(i,n,s))return!0;if(this.directionLockAction.checkMovingDirection(i,n,o))return this.actionsHandler.setInitiated(),!0;var r=this.directionLockAction.adjustDelta(t,e),h=this.scrollBehaviorX.move(r.deltaX),a=this.scrollBehaviorY.move(r.deltaY);this.moved||(this.moved=!0,this.hooks.trigger(this.hooks.eventTypes.scrollStart)),this.animater.translate({x:h,y:a}),this.dispatchScroll(s)}},kt.prototype.dispatchScroll=function(t){t-this.startTime>this.options.momentumLimitTime&&(this.startTime=t,this.scrollBehaviorX.updateStartPos(),this.scrollBehaviorY.updateStartPos(),1===this.options.probeType&&this.hooks.trigger(this.hooks.eventTypes.scroll,this.getCurrentPos())),1<this.options.probeType&&this.hooks.trigger(this.hooks.eventTypes.scroll,this.getCurrentPos())},kt.prototype.checkMomentum=function(t,e,o){return o-this.endTime>this.options.momentumLimitTime&&e<this.options.momentumLimitDistance&&t<this.options.momentumLimitDistance},kt.prototype.handleEnd=function(t){if(!this.hooks.trigger(this.hooks.eventTypes.beforeEnd,t)){var e=this.getCurrentPos();if(this.scrollBehaviorX.updateDirection(),this.scrollBehaviorY.updateDirection(),this.hooks.trigger(this.hooks.eventTypes.end,t,e))return!0;this.animater.translate(e),this.endTime=u();var o=this.endTime-this.startTime;this.hooks.trigger(this.hooks.eventTypes.scrollEnd,e,o)}},kt.prototype.handleClick=function(t){X(t.target,this.options.preventDefaultException)||(t.preventDefault(),t.stopPropagation())},kt.prototype.getCurrentPos=function(){return{x:this.scrollBehaviorX.getCurrentPos(),y:this.scrollBehaviorY.getCurrentPos()}},kt.prototype.refresh=function(){this.endTime=0},kt.prototype.destroy=function(){this.hooks.destroy()},kt);function kt(t,e,o,i,n){this.hooks=new R(["start","beforeMove","scrollStart","scroll","beforeEnd","end","scrollEnd"]),this.scrollBehaviorX=t,this.scrollBehaviorY=e,this.actionsHandler=o,this.animater=i,this.options=n,this.directionLockAction=new yt(n.directionLockThreshold,n.freeScroll,n.eventPassthrough),this.enabled=!0,this.bindActionsHandler()}function Tt(o,t,e,i){var n=["momentum","momentumLimitTime","momentumLimitDistance","deceleration","swipeBounceTime","swipeTime","outOfBoundaryDampingFactor","specifiedIndexAsContent"].reduce(function(t,e){return t[e]=o[e],t},{});return n.scrollable=!!o[t],n.bounces=e,n.rect=i,n}function bt(i,n,t){t.forEach(function(t){var e,o;"string"==typeof t?e=o=t:(e=t.source,o=t.target),i.on(e,function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return n.trigger.apply(n,p([o],t))})})}var St=(Pt.prototype.init=function(){var t=this;this.bindTranslater(),this.bindAnimater(),this.bindActions(),this.hooks.on(this.hooks.eventTypes.scrollEnd,function(){t.togglePointerEvents(!0)})},Pt.prototype.registerTransitionEnd=function(){this.transitionEndRegister=new I(this.content,[{name:C.transitionEnd,handler:this.transitionEnd.bind(this)}])},Pt.prototype.bindTranslater=function(){var o=this,t=this.translater.hooks;t.on(t.eventTypes.beforeTranslate,function(t){o.options.translateZ&&t.push(o.options.translateZ)}),t.on(t.eventTypes.translate,function(t){var e=o.getCurrentPos();o.updatePositions(t),t.x===e.x&&t.y===e.y||o.togglePointerEvents(!1)})},Pt.prototype.bindAnimater=function(){var e=this;this.animater.hooks.on(this.animater.hooks.eventTypes.end,function(t){e.resetPosition(e.options.bounceTime)||(e.animater.setPending(!1),e.hooks.trigger(e.hooks.eventTypes.scrollEnd,t))}),bt(this.animater.hooks,this.hooks,[{source:this.animater.hooks.eventTypes.move,target:this.hooks.eventTypes.scroll},{source:this.animater.hooks.eventTypes.forceStop,target:this.hooks.eventTypes.scrollEnd}])},Pt.prototype.bindActions=function(){var n=this,s=this.actions;bt(s.hooks,this.hooks,[{source:s.hooks.eventTypes.start,target:this.hooks.eventTypes.beforeStart},{source:s.hooks.eventTypes.start,target:this.hooks.eventTypes.beforeScrollStart},{source:s.hooks.eventTypes.beforeMove,target:this.hooks.eventTypes.beforeMove},{source:s.hooks.eventTypes.scrollStart,target:this.hooks.eventTypes.scrollStart},{source:s.hooks.eventTypes.scroll,target:this.hooks.eventTypes.scroll},{source:s.hooks.eventTypes.beforeEnd,target:this.hooks.eventTypes.beforeEnd}]),s.hooks.on(s.hooks.eventTypes.end,function(t,e){return n.hooks.trigger(n.hooks.eventTypes.touchEnd,e),!!n.hooks.trigger(n.hooks.eventTypes.end,e)||(!(s.moved||(n.hooks.trigger(n.hooks.eventTypes.scrollCancel),!n.checkClick(t)))||(n.resetPosition(n.options.bounceTime,M.bounce)?(n.animater.setForceStopped(!1),!0):void 0))}),s.hooks.on(s.hooks.eventTypes.scrollEnd,function(t,e){var o=Math.abs(t.x-n.scrollBehaviorX.startPos),i=Math.abs(t.y-n.scrollBehaviorY.startPos);if(n.checkFlick(e,o,i))return n.animater.setForceStopped(!1),void n.hooks.trigger(n.hooks.eventTypes.flick);!n.momentum(t,e)&&(!n.animater.forceStopped||s.moved)?n.hooks.trigger(n.hooks.eventTypes.scrollEnd,t):n.animater.setForceStopped(!1)})},Pt.prototype.checkFlick=function(t,e,o){if(1<this.hooks.events.flick.length&&t<this.options.flickLimitTime&&e<this.options.flickLimitDistance&&o<this.options.flickLimitDistance&&(1<o||1<e))return!0},Pt.prototype.momentum=function(t,e){var o={time:0,easing:M.swiper,newX:t.x,newY:t.y},i=this.scrollBehaviorX.end(e),n=this.scrollBehaviorY.end(e);if(o.newX=f(i.destination)?o.newX:i.destination,o.newY=f(n.destination)?o.newY:n.destination,o.time=Math.max(i.duration,n.duration),this.hooks.trigger(this.hooks.eventTypes.momentum,o,this),o.newX!==t.x||o.newY!==t.y)return(o.newX>this.scrollBehaviorX.minScrollPos||o.newX<this.scrollBehaviorX.maxScrollPos||o.newY>this.scrollBehaviorY.minScrollPos||o.newY<this.scrollBehaviorY.maxScrollPos)&&(o.easing=M.swipeBounce),this.scrollTo(o.newX,o.newY,o.time,o.easing),!0},Pt.prototype.checkClick=function(t){var e,o,i,n=this.animater.forceStopped;if(this.hooks.trigger(this.hooks.eventTypes.checkClick))return this.animater.setForceStopped(!1),!0;if(n)return!1;var s,r,h=this.options.dblclick,a=!1;return h&&this.lastClickTime&&(r=void 0===(s=h.delay)?300:s,u()-this.lastClickTime<r&&(a=!0,O(t,"dblclick"))),this.options.tap&&(e=t,o=this.options.tap,(i=document.createEvent("Event")).initEvent(o,!0,!0),i.pageX=e.pageX,i.pageY=e.pageY,e.target.dispatchEvent(i)),this.options.click&&!X(t.target,this.options.preventDefaultException)&&O(t),this.lastClickTime=a?null:u(),!0},Pt.prototype.resize=function(){var t=this;this.actions.enabled&&(a&&(this.wrapper.scrollTop=0),clearTimeout(this.resizeTimeout),this.resizeTimeout=window.setTimeout(function(){t.hooks.trigger(t.hooks.eventTypes.resize)},this.options.resizePolling))},Pt.prototype.transitionEnd=function(t){t.target===this.content&&this.animater.pending&&(this.animater.transitionTime(),this.resetPosition(this.options.bounceTime,M.bounce)||(this.animater.setPending(!1),3!==this.options.probeType&&this.hooks.trigger(this.hooks.eventTypes.scrollEnd,this.getCurrentPos())))},Pt.prototype.togglePointerEvents=function(t){void 0===t&&(t=!0);for(var e=this.content.children.length?this.content.children:[this.content],o=t?"auto":"none",i=0;i<e.length;i++){var n=e[i];n.isBScrollContainer||(n.style.pointerEvents=o)}},Pt.prototype.refresh=function(t){var e=this.setContent(t);this.hooks.trigger(this.hooks.eventTypes.beforeRefresh),this.scrollBehaviorX.refresh(t),this.scrollBehaviorY.refresh(t),e&&(this.translater.setContent(t),this.animater.setContent(t),this.transitionEndRegister.destroy(),this.registerTransitionEnd(),this.options.bindToTarget&&this.actionsHandler.setContent(t)),this.actions.refresh(),this.wrapperOffset=b(this.wrapper)},Pt.prototype.setContent=function(t){var e=t!==this.content;return e&&(this.content=t),e},Pt.prototype.scrollBy=function(t,e,o,i){void 0===o&&(o=0);var n=this.getCurrentPos(),s=n.x,r=n.y;i=i||M.bounce,t+=s,e+=r,this.scrollTo(t,e,o,i)},Pt.prototype.scrollTo=function(t,e,o,i,n){void 0===o&&(o=0),void 0===i&&(i=M.bounce),void 0===n&&(n={start:{},end:{}});var s=this.options.useTransition?i.style:i.fn,r=this.getCurrentPos(),h=c({x:r.x,y:r.y},n.start),a=c({x:t,y:e},n.end);this.hooks.trigger(this.hooks.eventTypes.scrollTo,a),function(t,e){for(var o=0,i=Object.keys(t);o<i.length;o++){var n=i[o];if(t[n]!==e[n])return}return 1}(h,a)||this.animater.move(h,a,o,s)},Pt.prototype.scrollToElement=function(t,e,o,i,n){function s(t,e,o){return"number"==typeof t?t:t?Math.round(e/2-o/2):0}var r=g(t),h=b(r);o=s(o,r.offsetWidth,this.wrapper.offsetWidth),i=s(i,r.offsetHeight,this.wrapper.offsetHeight);function a(t,e,o,i){return t-=e,t=i.adjustPosition(t-o)}h.left=a(h.left,this.wrapperOffset.left,o,this.scrollBehaviorX),h.top=a(h.top,this.wrapperOffset.top,i,this.scrollBehaviorY),this.hooks.trigger(this.hooks.eventTypes.scrollToElement,r,h)||this.scrollTo(h.left,h.top,e,n)},Pt.prototype.resetPosition=function(t,e){void 0===t&&(t=0),void 0===e&&(e=M.bounce);var o=this.scrollBehaviorX.checkInBoundary(),i=o.position,n=o.inBoundary,s=this.scrollBehaviorY.checkInBoundary(),r=s.position,h=s.inBoundary;return(!n||!h)&&(l&&(this._reflow=this.content.offsetHeight),this.scrollTo(i,r,t,e),!0)},Pt.prototype.updatePositions=function(t){this.scrollBehaviorX.updatePosition(t.x),this.scrollBehaviorY.updatePosition(t.y)},Pt.prototype.getCurrentPos=function(){return this.actions.getCurrentPos()},Pt.prototype.enable=function(){this.actions.enabled=!0},Pt.prototype.disable=function(){H(this.animater.timer),this.actions.enabled=!1},Pt.prototype.destroy=function(){var e=this;["resizeRegister","transitionEndRegister","actionsHandler","actions","hooks","animater","translater","scrollBehaviorX","scrollBehaviorY"].forEach(function(t){return e[t].destroy()})},Pt);function Pt(t,e,o){this.wrapper=t,this.content=e,this.resizeTimeout=0,this.hooks=new R(["beforeStart","beforeMove","beforeScrollStart","scrollStart","scroll","beforeEnd","scrollEnd","resize","touchEnd","end","flick","scrollCancel","momentum","scrollTo","scrollToElement","beforeRefresh"]),this.options=o;var i,n,s,r,h,a,c=this.options.bounce,l=c.left,p=c.right,u=c.top,d=c.bottom;this.scrollBehaviorX=new ut(t,e,Tt(o,"scrollX",[l,p],{size:"width",position:"left"})),this.scrollBehaviorY=new ut(t,e,Tt(o,"scrollY",[u,d],{size:"height",position:"top"})),this.translater=new G(this.content),this.animater=(i=this.content,n=this.translater,s=this.options,r=s.useTransition,h={},Object.defineProperty(h,"probeType",{enumerable:!0,configurable:!1,get:function(){return s.probeType}}),new(r?it:rt)(i,n,h)),this.actionsHandler=new Z(this.options.bindToTarget?this.content:t,(a=this.options,["click","bindToWrapper","disableMouse","disableTouch","preventDefault","stopPropagation","tagException","preventDefaultException","autoEndDistance"].reduce(function(t,e){return t[e]=a[e],t},{}))),this.actions=new gt(this.scrollBehaviorX,this.scrollBehaviorY,this.actionsHandler,this.animater,this.options);var f=this.resize.bind(this);this.resizeRegister=new I(window,[{name:"orientationchange",handler:f},{name:"resize",handler:f}]),this.registerTransitionEnd(),this.init()}var wt,Et=(e(Bt,wt=R),Bt.use=function(e){var t=e.pluginName;return Bt.plugins.some(function(t){return e===t.ctor})||(f(t)?s("Plugin Class must specify plugin's name in static property by 'pluginName' field."):Bt.pluginsMap[t]?s("This plugin has been registered, maybe you need change plugin's name"):(Bt.pluginsMap[t]=!0,Bt.plugins.push({name:t,applyOrder:e.applyOrder,ctor:e}))),Bt},Bt.prototype.setContent=function(t){var e=!1,o=!0,i=t.children[this.options.specifiedIndexAsContent];return i?(e=this.content!==i)&&(this.content=i):(s("The wrapper need at least one child element to be content element to scroll."),o=!1),{valid:o,contentChanged:e}},Bt.prototype.init=function(t){var e=this;(this.wrapper=t).isBScrollContainer=!0,this.scroller=new St(t,this.content,this.options),this.scroller.hooks.on(this.scroller.hooks.eventTypes.resize,function(){e.refresh()}),this.eventBubbling(),this.handleAutoBlur(),this.enable(),this.proxy(n),this.applyPlugins(),this.refreshWithoutReset(this.content);var o=this.options,i={x:o.startX,y:o.startY};this.hooks.trigger(this.hooks.eventTypes.beforeInitialScrollTo,i)||this.scroller.scrollTo(i.x,i.y)},Bt.prototype.applyPlugins=function(){var o=this,i=this.options;Bt.plugins.sort(function(t,e){var o,i=((o={}).pre=-1,o.post=1,o);return(t.applyOrder?i[t.applyOrder]:0)-(e.applyOrder?i[e.applyOrder]:0)}).forEach(function(t){var e=t.ctor;i[t.name]&&"function"==typeof e&&(o.plugins[t.name]=new e(o))})},Bt.prototype.handleAutoBlur=function(){this.options.autoBlur&&this.on(this.eventTypes.beforeScrollStart,function(){var t=document.activeElement;!t||"INPUT"!==t.tagName&&"TEXTAREA"!==t.tagName||t.blur()})},Bt.prototype.eventBubbling=function(){bt(this.scroller.hooks,this,[this.eventTypes.beforeScrollStart,this.eventTypes.scrollStart,this.eventTypes.scroll,this.eventTypes.scrollEnd,this.eventTypes.scrollCancel,this.eventTypes.touchEnd,this.eventTypes.flick])},Bt.prototype.refreshWithoutReset=function(t){this.scroller.refresh(t),this.hooks.trigger(this.hooks.eventTypes.refresh,t),this.trigger(this.eventTypes.refresh,t)},Bt.prototype.proxy=function(t){var r=this;t.forEach(function(t){var e,o,i,n=t.key,s=t.sourceKey;e=r,o=s,i=n,K.get=function(){return function(t,e){for(var o=e.split("."),i=0;i<o.length-1;i++)if("object"!=typeof(t=t[o[i]])||!t)return;var n=o.pop();return"function"==typeof t[n]?function(){return t[n].apply(t,arguments)}:t[n]}(this,o)},K.set=function(t){!function(t,e,o){for(var i,n=e.split("."),s=0;s<n.length-1;s++)t[i=n[s]]||(t[i]={}),t=t[i];t[n.pop()]=o}(this,o,t)},Object.defineProperty(e,i,K)})},Bt.prototype.refresh=function(){var t,e=this.setContent(this.wrapper),o=e.contentChanged;e.valid&&(t=this.content,this.refreshWithoutReset(t),o&&(this.hooks.trigger(this.hooks.eventTypes.contentChanged,t),this.trigger(this.eventTypes.contentChanged,t)),this.scroller.resetPosition())},Bt.prototype.enable=function(){this.scroller.enable(),this.hooks.trigger(this.hooks.eventTypes.enable),this.trigger(this.eventTypes.enable)},Bt.prototype.disable=function(){this.scroller.disable(),this.hooks.trigger(this.hooks.eventTypes.disable),this.trigger(this.eventTypes.disable)},Bt.prototype.destroy=function(){this.hooks.trigger(this.hooks.eventTypes.destroy),this.trigger(this.eventTypes.destroy),this.scroller.destroy()},Bt.prototype.eventRegister=function(t){this.registerType(t)},Bt.plugins=[],Bt.pluginsMap={},Bt);function Bt(t,e){var o=wt.call(this,["refresh","contentChanged","enable","disable","beforeScrollStart","scrollStart","scroll","scrollEnd","scrollCancel","touchEnd","flick","destroy"])||this,i=g(t);return i?(o.plugins={},o.options=(new q).merge(e).process(),o.setContent(i).valid&&(o.hooks=new R(["refresh","enable","disable","destroy","beforeInitialScrollTo","contentChanged"]),o.init(i)),o):(s("Can not resolve the wrapper DOM."),o)}function Ct(t,e){return new Et(t,e)}Ct.use=Et.use,Ct.plugins=Et.plugins,Ct.pluginsMap=Et.pluginsMap;var Dt=Ct;t.Behavior=ut,t.CustomOptions=W,t.createBScroll=Ct,t.default=Dt,Object.defineProperty(t,"__esModule",{value:!0})}),"undefined"!=typeof window&&window.BScroll&&(window.BScroll=window.BScroll.default); |
@@ -5,3 +5,3 @@ import { EaseFn } from '@better-scroll/shared-utils'; | ||
export default class Transition extends Base { | ||
startProbe(): void; | ||
startProbe(endPoint: TranslaterPoint): void; | ||
transitionTime(time?: number): void; | ||
@@ -8,0 +8,0 @@ transitionTimingFunction(easing: string): void; |
{ | ||
"name": "@better-scroll/core", | ||
"version": "2.0.5", | ||
"version": "2.0.6", | ||
"description": "Minimalistic core scrolling for BetterScroll, it is pure and tiny", | ||
@@ -34,5 +34,5 @@ "author": { | ||
"dependencies": { | ||
"@better-scroll/shared-utils": "^2.0.5" | ||
"@better-scroll/shared-utils": "^2.0.6" | ||
}, | ||
"gitHead": "8fb2cd55daa85f0df2ff8137fe699cb3bb820373" | ||
"gitHead": "00b314eada44d4c430eda138ccf27d3b91d39421" | ||
} |
@@ -23,2 +23,4 @@ import Scroller from '../scroller/Scroller' | ||
'flick', | ||
'alterOptions', | ||
'mousewheelEnd', | ||
]) | ||
@@ -25,0 +27,0 @@ const res = { |
@@ -20,3 +20,5 @@ export function createEvent(type: string, name: string): Event { | ||
interface CustomMouseEvent extends Event { | ||
button: 0 | ||
button: 0 | 1 | ||
pageX: number | ||
pageY: number | ||
} | ||
@@ -34,5 +36,11 @@ | ||
export function dispatchMouse(target: EventTarget, name = 'mousedown'): void { | ||
export function dispatchMouse( | ||
target: EventTarget, | ||
name = 'mousedown', | ||
useLeftButton = true | ||
): void { | ||
const event = <CustomMouseEvent>createEvent('', name) | ||
event.button = 0 | ||
event.button = useLeftButton ? 0 : 1 | ||
event.pageX = 0 | ||
event.pageY = 0 | ||
target.dispatchEvent(event) | ||
@@ -39,0 +47,0 @@ } |
@@ -5,6 +5,7 @@ import BScroll from '../index' | ||
let bscroll: BScroll | ||
let div = document.createElement('div') | ||
let wrapper = document.createElement('div') | ||
let content = document.createElement('p') | ||
wrapper.appendChild(content) | ||
beforeEach(() => { | ||
bscroll = new BScroll(div, {}) | ||
bscroll = new BScroll(wrapper, {}) | ||
}) | ||
@@ -16,3 +17,3 @@ afterEach(() => { | ||
it('should use plugins successfully when call use()', () => { | ||
it('use()', () => { | ||
const plugin = class MyPlugin { | ||
@@ -22,4 +23,22 @@ static pluginName = 'myPlugin' | ||
BScroll.use(plugin) | ||
// has installed | ||
BScroll.use(plugin) | ||
expect(BScroll.plugins.length).toBe(1) | ||
// Plugin should specify pluginName | ||
const spyFn = jest.spyOn(console, 'error') | ||
const unnamedPlugin = class UnnamedPlugin {} | ||
BScroll.use(unnamedPlugin as any) | ||
expect(spyFn).toBeCalled() | ||
spyFn.mockRestore() | ||
const spyFn2 = jest.spyOn(console, 'error') | ||
// duplicate register plugins | ||
const plugin2 = class MyPlugin2 { | ||
static pluginName = 'myPlugin' | ||
} | ||
BScroll.use(plugin2) | ||
expect(spyFn2).toBeCalled() | ||
spyFn2.mockRestore() | ||
}) | ||
@@ -52,5 +71,57 @@ | ||
expect(spy).toBeCalledTimes(2) | ||
}) | ||
spy.mockRestore() | ||
it('disable()', () => { | ||
const mockFn = jest.fn() | ||
bscroll.on(bscroll.eventTypes.disable, mockFn) | ||
bscroll.hooks.on(bscroll.hooks.eventTypes.disable, mockFn) | ||
bscroll.disable() | ||
expect(mockFn).toBeCalledTimes(2) | ||
}) | ||
it('destroy()', () => { | ||
const mockFn = jest.fn() | ||
bscroll.on(bscroll.eventTypes.destroy, mockFn) | ||
bscroll.hooks.on(bscroll.hooks.eventTypes.destroy, mockFn) | ||
bscroll.destroy() | ||
expect(mockFn).toBeCalledTimes(2) | ||
}) | ||
it('eventRegister()', () => { | ||
bscroll.eventRegister(['dummy']) | ||
expect(bscroll.eventTypes.dummy).toBeTruthy() | ||
}) | ||
it('should refresh when window resized', () => { | ||
const mockFn = jest.fn() | ||
bscroll.on(bscroll.eventTypes.refresh, mockFn) | ||
bscroll.scroller.hooks.trigger(bscroll.scroller.hooks.eventTypes.resize) | ||
expect(mockFn).toBeCalledTimes(1) | ||
}) | ||
it('plugin wanna control scroll position ', () => { | ||
const mockFn = jest.fn().mockImplementation(() => true) | ||
class DummyPlugin { | ||
static pluginName = 'dummy' | ||
constructor(scroll: BScroll) { | ||
scroll.hooks.on(scroll.hooks.eventTypes.beforeInitialScrollTo, mockFn) | ||
} | ||
} | ||
BScroll.use(DummyPlugin) | ||
bscroll = new BScroll(wrapper, { dummy: true }) | ||
expect(mockFn).toBeCalled() | ||
}) | ||
it('should trigger contentChanged hook when content DOM has changed', () => { | ||
const mockFn = jest.fn() | ||
bscroll.on(bscroll.eventTypes.contentChanged, mockFn) | ||
// content DOM has | ||
wrapper.removeChild(content) | ||
wrapper.appendChild(document.createElement('div')) | ||
bscroll.refresh() | ||
expect(mockFn).toBeCalled() | ||
}) | ||
}) |
@@ -117,2 +117,5 @@ import { OptionsConstructor } from '../Options' | ||
}) | ||
// an invalid parameter | ||
const ret = options.merge() | ||
expect(ret).toBe(options) | ||
}) | ||
@@ -119,0 +122,0 @@ |
@@ -30,2 +30,3 @@ import { EventEmitter } from '@better-scroll/shared-utils' | ||
setForceStopped: jest.fn(), | ||
setContent: jest.fn(), | ||
} | ||
@@ -32,0 +33,0 @@ }) |
@@ -33,2 +33,3 @@ import { EventEmitter } from '@better-scroll/shared-utils' | ||
setForceStopped: jest.fn(), | ||
setContent: jest.fn(), | ||
} | ||
@@ -35,0 +36,0 @@ }) |
@@ -22,3 +22,3 @@ import Translater from '../../translater' | ||
function createTransition(probeType: number) { | ||
function createAnimation(probeType: number) { | ||
const dom = document.createElement('div') | ||
@@ -44,3 +44,3 @@ const translater = new Translater(dom) | ||
it('should off hooks and cancelAnimationFrame when destroy', () => { | ||
const { animation } = createTransition(0) | ||
const { animation } = createAnimation(0) | ||
const hooksDestroySpy = jest.spyOn(animation.hooks, 'destroy') | ||
@@ -53,3 +53,3 @@ animation.destroy() | ||
it('should move to endPoint and trigger hooks in one step when time=0', () => { | ||
const { animation, translater } = createTransition(0) | ||
const { animation, translater } = createAnimation(0) | ||
const onMove = jest.fn() | ||
@@ -77,3 +77,3 @@ const onEnd = jest.fn() | ||
it('should move to endPoint for serveral steps with time', () => { | ||
const { animation, translater, dom } = createTransition(3) | ||
const { animation, translater, dom } = createAnimation(3) | ||
const onMove = jest.fn() | ||
@@ -130,3 +130,3 @@ const onEnd = jest.fn() | ||
it('should force stop', () => { | ||
const { animation, translater } = createTransition(3) | ||
const { animation, translater } = createAnimation(3) | ||
const onMove = jest.fn() | ||
@@ -183,2 +183,10 @@ const onForceStop = jest.fn() | ||
}) | ||
it('cancelable beforeForceStop hook ', () => { | ||
const { animation, translater } = createAnimation(3) | ||
animation.hooks.on(animation.hooks.eventTypes.beforeForceStop, () => true) | ||
animation.setPending(true) | ||
const ret = animation.doStop() | ||
expect(ret).toBe(true) | ||
}) | ||
}) |
@@ -128,3 +128,6 @@ import Translater from '../../translater/index' | ||
it('should startProbe with probeType=3', () => { | ||
const { transition } = createTransition(3) | ||
const { transition, translater } = createTransition(3) | ||
translater.getComputedPosition = jest.fn().mockImplementation(() => { | ||
return { x: 0, y: 0 } | ||
}) | ||
mockRequestAnimationFrame.mockImplementation((cb) => { | ||
@@ -159,2 +162,13 @@ setTimeout(() => { | ||
}) | ||
it('cancelable beforeForceStop hook ', () => { | ||
const { transition, translater } = createTransition(3) | ||
transition.hooks.on(transition.hooks.eventTypes.beforeForceStop, () => true) | ||
translater.getComputedPosition = jest.fn().mockImplementation(() => { | ||
return { x: 0, y: 0 } | ||
}) | ||
transition.setPending(true) | ||
const ret = transition.doStop() | ||
expect(ret).toBe(true) | ||
}) | ||
}) |
@@ -68,2 +68,3 @@ import Base from './Base' | ||
// should not dispatch end hook, because forceStop hook will do this. | ||
/* istanbul ignore if */ | ||
if (!this.pending && !this.forceStopped) { | ||
@@ -70,0 +71,0 @@ this.hooks.trigger(this.hooks.eventTypes.end, endPoint) |
@@ -10,8 +10,15 @@ import { | ||
import { TranslaterPoint } from '../translater' | ||
import { isValidPostion } from '../utils/compat' | ||
export default class Transition extends Base { | ||
startProbe() { | ||
startProbe(endPoint: TranslaterPoint) { | ||
let prePos = this.translater.getComputedPosition() | ||
let startPoint = prePos | ||
const probe = () => { | ||
let pos = this.translater.getComputedPosition() | ||
this.hooks.trigger(this.hooks.eventTypes.move, pos) | ||
if (isValidPostion(startPoint, endPoint, pos, prePos)) { | ||
this.hooks.trigger(this.hooks.eventTypes.move, pos) | ||
} | ||
prePos = pos | ||
// transition ends should dispatch end hook. | ||
@@ -59,3 +66,3 @@ // but when call stop() in animation.hooks.move or bs.scroll | ||
if (time && this.options.probeType === Probe.Realtime) { | ||
this.startProbe() | ||
this.startProbe(endPoint) | ||
} | ||
@@ -62,0 +69,0 @@ |
@@ -15,3 +15,5 @@ import { EventRegister, EventEmitter } from '@better-scroll/shared-utils' | ||
hooks: new EventEmitter(['beforeStart', 'start', 'move', 'end', 'click']), | ||
destroy: jest.fn() | ||
destroy: jest.fn(), | ||
setInitiated: jest.fn(), | ||
setContent: jest.fn(), | ||
} | ||
@@ -18,0 +20,0 @@ }) |
@@ -64,4 +64,22 @@ import ActionsHandler, { | ||
expect(beforeStartMockHandler).toBeCalled() | ||
expect(startMockHandler).toBeCalled() | ||
expect(beforeStartMockHandler).toBeCalledTimes(1) | ||
expect(startMockHandler).toBeCalledTimes(1) | ||
// return early | ||
actionsHandler.setInitiated(1) | ||
dispatchMouse(wrapper, 'mousedown') | ||
expect(beforeStartMockHandler).toBeCalledTimes(1) | ||
expect(startMockHandler).toBeCalledTimes(1) | ||
// only allow mouse left button | ||
actionsHandler.setInitiated(0) | ||
dispatchMouse(wrapper, 'mousedown', false) | ||
expect(beforeStartMockHandler).toBeCalledTimes(1) | ||
expect(startMockHandler).toBeCalledTimes(1) | ||
// cancelable beforeStart hook | ||
actionsHandler.hooks.on('beforeStart', () => true) | ||
dispatchMouse(wrapper, 'mousedown') | ||
expect(beforeStartMockHandler).toBeCalledTimes(2) | ||
expect(startMockHandler).toBeCalledTimes(1) | ||
}) | ||
@@ -71,7 +89,11 @@ | ||
actionsHandler = new ActionsHandler(wrapper, options) | ||
const moveMockHandler = jest.fn().mockImplementation(() => { | ||
const moveMockHandler1 = jest.fn().mockImplementationOnce(() => { | ||
return true | ||
}) | ||
const moveMockHandler2 = jest.fn().mockImplementation(() => { | ||
return 'dummy test' | ||
}) | ||
actionsHandler.hooks.on('move', moveMockHandler) | ||
actionsHandler.hooks.on('move', moveMockHandler1) | ||
actionsHandler.hooks.on('move', moveMockHandler2) | ||
@@ -82,3 +104,14 @@ dispatchMouse(wrapper, 'mousedown') | ||
expect(moveMockHandler).toBeCalled() | ||
expect(moveMockHandler1).toBeCalledTimes(1) | ||
// cancelable move hook | ||
expect(moveMockHandler2).not.toBeCalled() | ||
// simulate finger moved out of viewport | ||
actionsHandler.pointX = 5 | ||
const endMockHandler = jest.fn() | ||
actionsHandler.hooks.on(actionsHandler.hooks.eventTypes.end, endMockHandler) | ||
dispatchMouse(window, 'mousemove') | ||
expect(endMockHandler).toBeCalled() | ||
}) | ||
@@ -131,2 +164,19 @@ | ||
}) | ||
it('destroy()', () => { | ||
actionsHandler = new ActionsHandler(wrapper, options) | ||
actionsHandler.destroy() | ||
expect(actionsHandler.wrapperEventRegister.events.length).toBe(0) | ||
expect(actionsHandler.targetEventRegister.events.length).toBe(0) | ||
expect(actionsHandler.hooks.eventTypes).toMatchObject({}) | ||
expect(actionsHandler.hooks.events).toMatchObject({}) | ||
}) | ||
it('setContent()', () => { | ||
const p = document.createElement('p') | ||
actionsHandler.setContent(p) | ||
expect(actionsHandler.wrapper).toBe(p) | ||
}) | ||
}) |
@@ -196,2 +196,3 @@ import { BScrollInstance, propertiesConfig } from './Instance' | ||
private handleAutoBlur() { | ||
/* istanbul ignore if */ | ||
if (this.options.autoBlur) { | ||
@@ -198,0 +199,0 @@ this.on(this.eventTypes.beforeScrollStart, () => { |
@@ -30,3 +30,8 @@ import DirectionLock from '../DirectionLock' | ||
endTime: 0, | ||
getCurrentPos: jest.fn(), | ||
getCurrentPos: jest.fn().mockImplementation(() => { | ||
return { | ||
x: 0, | ||
y: 0, | ||
} | ||
}), | ||
refresh: jest.fn(), | ||
@@ -41,4 +46,4 @@ destroy: jest.fn(), | ||
'end', | ||
'scrollEnd' | ||
]) | ||
'scrollEnd', | ||
]), | ||
} | ||
@@ -45,0 +50,0 @@ } |
@@ -24,2 +24,3 @@ import { EventEmitter } from '@better-scroll/shared-utils' | ||
'computeBoundary', | ||
'ignoreHasScroll', | ||
]), | ||
@@ -33,3 +34,8 @@ start: jest.fn(), | ||
getCurrentPos: jest.fn(), | ||
checkInBoundary: jest.fn(), | ||
checkInBoundary: jest.fn().mockImplementation(() => { | ||
return { | ||
position: 0, | ||
inBoundary: false, | ||
} | ||
}), | ||
adjustPosition: jest.fn(), | ||
@@ -39,3 +45,5 @@ updateStartPos: jest.fn(), | ||
resetStartPos: jest.fn(), | ||
getAbsDist: jest.fn(), | ||
getAbsDist: jest.fn().mockImplementation((delta: number) => { | ||
return Math.abs(delta) | ||
}), | ||
destroy: jest.fn(), | ||
@@ -42,0 +50,0 @@ computeBoundary: jest.fn(), |
@@ -8,3 +8,15 @@ const DirectionLock = jest | ||
eventPassthrough: '', | ||
freeScroll: false | ||
freeScroll: false, | ||
reset: jest.fn(), | ||
checkMovingDirection: jest.fn().mockImplementation((ret = true) => { | ||
return ret | ||
}), | ||
adjustDelta: jest | ||
.fn() | ||
.mockImplementation((deltaX: number = 0, deltaY: number = 0) => { | ||
return { | ||
deltaX, | ||
deltaY, | ||
} | ||
}), | ||
} | ||
@@ -11,0 +23,0 @@ }) |
@@ -6,2 +6,3 @@ import { Behavior } from '../Behavior' | ||
import ActionsHandler from '../../base/ActionsHandler' | ||
import DirectionLockAction from '../DirectionLock' | ||
@@ -13,2 +14,3 @@ jest.mock('../Behavior') | ||
jest.mock('../../base/ActionsHandler') | ||
jest.mock('../DirectionLock') | ||
@@ -71,5 +73,11 @@ import Actions from '../Actions' | ||
let scrollHandler = jest.fn() | ||
actions.hooks.on('beforeMove', beforeMoveMockHandler) | ||
actions.hooks.on('scrollStart', scrollStartHandler) | ||
actions.hooks.on('scroll', scrollHandler) | ||
// cancelable beforeMove hook | ||
actions.hooks.on( | ||
actions.hooks.eventTypes.beforeMove, | ||
jest.fn().mockImplementationOnce(() => true) | ||
) | ||
actions.hooks.on(actions.hooks.eventTypes.beforeMove, beforeMoveMockHandler) | ||
actions.hooks.on(actions.hooks.eventTypes.scrollStart, scrollStartHandler) | ||
actions.hooks.on(actions.hooks.eventTypes.scroll, scrollHandler) | ||
actions.actionsHandler.hooks.trigger('move', { | ||
@@ -81,16 +89,46 @@ deltaX: 0, | ||
expect(beforeMoveMockHandler).toBeCalled() | ||
expect(beforeMoveMockHandler).toHaveBeenCalledWith(e) | ||
expect(beforeMoveMockHandler).toHaveBeenCalledTimes(0) | ||
// moved less than 15 px | ||
actions.endTime = Date.now() - 400 | ||
actions.actionsHandler.hooks.trigger('move', { | ||
deltaX: 0, | ||
deltaY: 10, | ||
e, | ||
}) | ||
expect(beforeMoveMockHandler).toHaveBeenCalledTimes(1) | ||
expect(actions.directionLockAction.checkMovingDirection).not.toBeCalled() | ||
// lock direction | ||
actions.endTime = Date.now() | ||
actions.actionsHandler.hooks.trigger('move', { | ||
deltaX: 10, | ||
deltaY: 0, | ||
e, | ||
}) | ||
expect(beforeMoveMockHandler).toHaveBeenCalledTimes(2) | ||
expect(actions.actionsHandler.setInitiated).toBeCalled() | ||
actions.startTime = Date.now() - 400 | ||
actions.options.probeType = 1 | ||
actions.actionsHandler.hooks.trigger('move', { | ||
deltaX: 0, | ||
deltaY: -20, | ||
e, | ||
}) | ||
expect(beforeMoveMockHandler).toHaveBeenCalledTimes(3) | ||
expect(scrollStartHandler).toBeCalled() | ||
// because probeType is 0 | ||
expect(scrollHandler).not.toBeCalled() | ||
expect(actions.scrollBehaviorX.getAbsDist).toBeCalled() | ||
expect(actions.scrollBehaviorY.getAbsDist).toBeCalled() | ||
expect(actions.scrollBehaviorX.getAbsDist).toHaveBeenCalledWith(0) | ||
expect(scrollHandler).toBeCalledTimes(1) | ||
expect(actions.scrollBehaviorY.getAbsDist).toHaveBeenCalledWith(-20) | ||
expect(actions.scrollBehaviorX.move).toBeCalled() | ||
expect(actions.scrollBehaviorY.move).toBeCalled() | ||
expect(actions.scrollBehaviorX.move).toHaveBeenCalledWith(0) | ||
expect(actions.scrollBehaviorY.move).toHaveBeenCalledWith(-20) | ||
actions.startTime = Date.now() | ||
actions.options.probeType = 3 | ||
actions.actionsHandler.hooks.trigger('move', { | ||
deltaX: 0, | ||
deltaY: -20, | ||
e, | ||
}) | ||
expect(scrollHandler).toBeCalledTimes(2) | ||
}) | ||
@@ -103,11 +141,37 @@ | ||
let e = new Event('touchend') | ||
actions.hooks.on('beforeEnd', beforeEndMockHandler) | ||
actions.hooks.on('end', endMockHandler) | ||
actions.hooks.on('scrollEnd', scrollEndHandler) | ||
actions.actionsHandler.hooks.trigger('end', e) | ||
// cancelable beforeEnd hook | ||
actions.hooks.on( | ||
actions.hooks.eventTypes.beforeEnd, | ||
jest.fn().mockImplementationOnce(() => true) | ||
) | ||
// cancelable end hook | ||
actions.hooks.on( | ||
actions.hooks.eventTypes.end, | ||
jest.fn().mockImplementationOnce(() => true) | ||
) | ||
actions.hooks.on(actions.hooks.eventTypes.beforeEnd, beforeEndMockHandler) | ||
actions.hooks.on(actions.hooks.eventTypes.end, endMockHandler) | ||
actions.hooks.on(actions.hooks.eventTypes.scrollEnd, scrollEndHandler) | ||
expect(beforeEndMockHandler).toBeCalled() | ||
expect(actions.scrollBehaviorX.updateDirection).toBeCalled() | ||
expect(actions.scrollBehaviorY.updateDirection).toBeCalled() | ||
expect(endMockHandler).toBeCalled() | ||
actions.actionsHandler.hooks.trigger( | ||
actions.actionsHandler.hooks.eventTypes.end, | ||
e | ||
) | ||
expect(beforeEndMockHandler).not.toBeCalled() | ||
expect(actions.scrollBehaviorX.updateDirection).not.toBeCalled() | ||
actions.actionsHandler.hooks.trigger( | ||
actions.actionsHandler.hooks.eventTypes.end, | ||
e | ||
) | ||
expect(beforeEndMockHandler).toHaveBeenCalledTimes(1) | ||
expect(actions.scrollBehaviorX.updateDirection).toHaveBeenCalledTimes(1) | ||
expect(actions.scrollBehaviorY.updateDirection).toHaveBeenCalledTimes(1) | ||
expect(endMockHandler).not.toBeCalled() | ||
actions.actionsHandler.hooks.trigger( | ||
actions.actionsHandler.hooks.eventTypes.end, | ||
e | ||
) | ||
expect(scrollEndHandler).toBeCalled() | ||
@@ -128,3 +192,3 @@ }) | ||
it('should gc when invoking destroy method', () => { | ||
it('destroy()', () => { | ||
actions.destroy() | ||
@@ -135,2 +199,31 @@ | ||
}) | ||
it('should can be disabled', () => { | ||
actions.enabled = false | ||
const actionsHandler = actions.actionsHandler | ||
actionsHandler.hooks.trigger(actionsHandler.hooks.eventTypes.start) | ||
expect(actions.directionLockAction.reset).not.toBeCalled() | ||
actionsHandler.hooks.trigger(actionsHandler.hooks.eventTypes.move, { | ||
deltaX: 0, | ||
deltaY: 0, | ||
}) | ||
expect(actions.scrollBehaviorX.getAbsDist).not.toBeCalled() | ||
actionsHandler.hooks.trigger(actionsHandler.hooks.eventTypes.end) | ||
expect(actions.scrollBehaviorX.updateDirection).not.toBeCalled() | ||
}) | ||
it('should prevent native click event', () => { | ||
actions.actionsHandler.hooks.trigger( | ||
actions.actionsHandler.hooks.eventTypes.click, | ||
{ | ||
_constructed: false, | ||
target: document.createElement('div'), | ||
preventDefault() {}, | ||
stopPropagation() {}, | ||
} | ||
) | ||
}) | ||
}) |
@@ -86,2 +86,13 @@ import { Behavior } from '../Behavior' | ||
}) | ||
behavior.hooks.on( | ||
behavior.hooks.eventTypes.momentum, | ||
(momentumData: any) => { | ||
momentumData.destination = 200 | ||
} | ||
) | ||
expect(behavior.end(100)).toEqual({ | ||
destination: -0, | ||
duration: 2500, | ||
rate: 15, | ||
}) | ||
}) | ||
@@ -107,2 +118,35 @@ | ||
}) | ||
it('performDampingAlgorithm()', () => { | ||
const ret = behavior.performDampingAlgorithm(20, 0.1) | ||
expect(ret).toBe(2) | ||
behavior.options.bounces = [false, false] | ||
// simulate out of the boundaries and no bounce | ||
const ret2 = behavior.performDampingAlgorithm(20, 0.1) | ||
expect(ret2).toBe(-0) | ||
}) | ||
it('getAbsDist()', () => { | ||
const ret = behavior.getAbsDist(-20) | ||
expect(ret).toBe(20) | ||
}) | ||
it('adjustPosition()', () => { | ||
const ret = behavior.adjustPosition(20.1) | ||
expect(ret).toBe(-0) | ||
}) | ||
it('computeBoundary()', () => { | ||
behavior.hooks.on( | ||
behavior.hooks.eventTypes.computeBoundary, | ||
(boundary: { minScrollPos: number; maxScrollPos: number }) => { | ||
boundary.minScrollPos = 20 | ||
boundary.maxScrollPos = 30 | ||
} | ||
) | ||
behavior.computeBoundary() | ||
expect(behavior.maxScrollPos).toEqual(behavior.minScrollPos) | ||
}) | ||
}) |
import DirectionLock from '../DirectionLock' | ||
import { | ||
Direction, | ||
DirectionLock as DirectionLockEnum, | ||
} from '@better-scroll/shared-utils' | ||
describe('DirectionLock Class tests', () => { | ||
@@ -33,2 +36,53 @@ let directionLock: DirectionLock | ||
}) | ||
it('adjustDelta() ', () => { | ||
directionLock.directionLocked = DirectionLockEnum.Horizontal | ||
const ret1 = directionLock.adjustDelta(20, 20) | ||
expect(ret1).toMatchObject({ | ||
deltaX: 20, | ||
deltaY: 0, | ||
}) | ||
directionLock.directionLocked = DirectionLockEnum.Vertical | ||
const ret2 = directionLock.adjustDelta(20, 20) | ||
expect(ret2).toMatchObject({ | ||
deltaX: 0, | ||
deltaY: 20, | ||
}) | ||
}) | ||
it('reset()', () => { | ||
directionLock.directionLocked = DirectionLockEnum.Vertical | ||
directionLock.reset() | ||
expect(directionLock.directionLocked).toBe(DirectionLockEnum.Default) | ||
}) | ||
it('checkMovingDirection()', () => { | ||
directionLock.directionLocked = DirectionLockEnum.Horizontal | ||
directionLock.eventPassthrough = DirectionLockEnum.Horizontal | ||
const ret1 = directionLock.checkMovingDirection(20, 20, { | ||
preventDefault() { | ||
return true | ||
}, | ||
} as any) | ||
expect(ret1).toBe(true) | ||
directionLock.directionLocked = DirectionLockEnum.Horizontal | ||
directionLock.eventPassthrough = DirectionLockEnum.Vertical | ||
const ret2 = directionLock.checkMovingDirection(20, 20, { | ||
preventDefault() { | ||
return true | ||
}, | ||
} as any) | ||
expect(ret2).toBe(false) | ||
// no locked | ||
directionLock.directionLocked = DirectionLockEnum.Default | ||
const ret3 = directionLock.checkMovingDirection(20, 20, { | ||
preventDefault() { | ||
return true | ||
}, | ||
} as any) | ||
expect(ret3).toBe(false) | ||
}) | ||
}) |
@@ -95,2 +95,3 @@ import { Behavior } from '../Behavior' | ||
let scrollEndMockHandler = jest.fn() | ||
scroller.hooks.on('scrollEnd', scrollEndMockHandler) | ||
scroller.scrollBehaviorX.checkInBoundary = jest | ||
@@ -112,8 +113,5 @@ .fn() | ||
}) | ||
scroller.hooks.on('scrollEnd', scrollEndMockHandler) | ||
scroller.animater.hooks.trigger('end', pos) | ||
expect(scroller.animater.setPending).toBeCalled() | ||
expect(scroller.animater.setPending).toHaveBeenCalledWith(false) | ||
expect(scrollEndMockHandler).toBeCalled() | ||
expect(scrollEndMockHandler).toHaveBeenCalledWith({ | ||
@@ -142,6 +140,21 @@ x: 0, | ||
let e = new Event('touch') as any | ||
scroller.hooks.on('touchEnd', touchEndMockHandler) | ||
scroller.hooks.trigger('touchEnd', { x: 0, y: 0 }) | ||
scroller.actions.hooks.trigger('end', e, { x: 0, y: 0 }) | ||
Object.defineProperty(e, 'target', { | ||
get() { | ||
return scroller.wrapper | ||
}, | ||
}) | ||
// cancelable scroller end hook | ||
scroller.hooks.on(scroller.hooks.eventTypes.touchEnd, touchEndMockHandler) | ||
scroller.hooks.trigger(scroller.hooks.eventTypes.touchEnd, { x: 0, y: 0 }) | ||
scroller.hooks.on( | ||
scroller.hooks.eventTypes.end, | ||
jest.fn().mockImplementationOnce(() => true) | ||
) | ||
const ret = scroller.actions.hooks.trigger( | ||
scroller.actions.hooks.eventTypes.end, | ||
e, | ||
{ x: 0, y: 0 } | ||
) | ||
expect(ret).toBe(true) | ||
expect(touchEndMockHandler).toBeCalled() | ||
@@ -152,14 +165,66 @@ expect(touchEndMockHandler).toHaveBeenCalledWith({ | ||
}) | ||
/* click operation */ | ||
// case 1 | ||
scroller.hooks.on( | ||
scroller.hooks.eventTypes.checkClick, | ||
jest.fn().mockImplementationOnce(() => true) | ||
) | ||
scroller.actions.hooks.trigger(scroller.actions.hooks.eventTypes.end, e, { | ||
x: 0, | ||
y: 0, | ||
}) | ||
expect(scroller.animater.setForceStopped).toBeCalledWith(false) | ||
// case 2 dblclick | ||
const mockFn2 = jest.fn() | ||
scroller.options.dblclick = true | ||
scroller.lastClickTime = Date.now() | ||
scroller.wrapper.addEventListener('dblclick', mockFn2) | ||
scroller.actions.hooks.trigger(scroller.actions.hooks.eventTypes.end, e, { | ||
x: 0, | ||
y: 0, | ||
}) | ||
expect(mockFn2).toBeCalled() | ||
// case 3 tap | ||
const mockFn3 = jest.fn() | ||
scroller.options.tap = 'tap' | ||
scroller.wrapper.addEventListener('tap', mockFn3) | ||
scroller.actions.hooks.trigger(scroller.actions.hooks.eventTypes.end, e, { | ||
x: 0, | ||
y: 0, | ||
}) | ||
expect(mockFn3).toBeCalled() | ||
// case 4 click | ||
const mockFn4 = jest.fn() | ||
scroller.options.click = true | ||
scroller.wrapper.addEventListener('click', mockFn4) | ||
scroller.actions.hooks.trigger(scroller.actions.hooks.eventTypes.end, e, { | ||
x: 0, | ||
y: 0, | ||
}) | ||
expect(mockFn4).toBeCalled() | ||
// case 5 force stopped | ||
scroller.animater.forceStopped = true | ||
const ret2 = scroller.actions.hooks.trigger( | ||
scroller.actions.hooks.eventTypes.end, | ||
e, | ||
{ x: 0, y: 0 } | ||
) | ||
expect(ret2).toBe(true) | ||
}) | ||
it('bind scrollEnd hook', () => { | ||
let scrollEndMockHandler = jest.fn() | ||
let momentumMockHandler = jest.fn() | ||
let noop = (() => {}) as any | ||
scroller.hooks.on('scrollEnd', scrollEndMockHandler) | ||
scroller.hooks.on('momentum', momentumMockHandler) | ||
scroller.hooks.events['flick'] = [noop] | ||
scroller.scrollBehaviorX.end = jest.fn().mockImplementation(() => { | ||
return { | ||
duration: 400, | ||
destination: 0, | ||
} | ||
@@ -170,17 +235,47 @@ }) | ||
duration: 400, | ||
destination: -20, | ||
} | ||
}) | ||
scroller.actions.hooks.trigger('scrollEnd', { x: 0, y: -20 }, 50) | ||
// flick | ||
const mockFn = jest.fn() | ||
scroller.hooks.events['flick'] = [noop, noop] | ||
scroller.hooks.on(scroller.hooks.eventTypes.flick, mockFn) | ||
scroller.actions.hooks.trigger( | ||
scroller.actions.hooks.eventTypes.scrollEnd, | ||
{ x: 0, y: -20 }, | ||
50 | ||
) | ||
expect(mockFn).toBeCalled() | ||
expect(scrollEndMockHandler).toBeCalled() | ||
expect(momentumMockHandler).toBeCalled() | ||
expect(momentumMockHandler).toHaveBeenCalledWith( | ||
{ | ||
easing: undefined, | ||
newX: 0, | ||
newY: -20, | ||
time: 400, | ||
}, | ||
expect.anything() | ||
// momentum | ||
scroller.hooks.events['flick'] = [] | ||
scroller.actions.hooks.trigger( | ||
scroller.actions.hooks.eventTypes.scrollEnd, | ||
{ x: 0, y: -40 }, | ||
50 | ||
) | ||
expect(scroller.animater.setForceStopped).toBeCalledWith(false) | ||
// force stop from transition | ||
scroller.actions.moved = false | ||
scroller.animater.forceStopped = true | ||
scroller.actions.hooks.trigger( | ||
scroller.actions.hooks.eventTypes.scrollEnd, | ||
{ x: 0, y: -20 }, | ||
50 | ||
) | ||
expect(scroller.animater.setForceStopped).toBeCalledWith(false) | ||
const mockFn2 = jest.fn() | ||
scroller.animater.forceStopped = false | ||
scroller.hooks.on(scroller.hooks.eventTypes.scrollEnd, mockFn2) | ||
scroller.actions.hooks.trigger( | ||
scroller.actions.hooks.eventTypes.scrollEnd, | ||
{ x: 0, y: -20 }, | ||
50 | ||
) | ||
expect(mockFn2).toBeCalledWith({ | ||
x: 0, | ||
y: -20, | ||
}) | ||
}) | ||
@@ -198,4 +293,9 @@ }) | ||
jest.clearAllTimers() | ||
expect(mockFn).toBeCalledTimes(1) | ||
expect(mockFn).toBeCalled() | ||
// disable scroller | ||
scroller.actions.enabled = false | ||
resizeEvent.initEvent('resize', true, true) | ||
window.dispatchEvent(resizeEvent) | ||
expect(mockFn).toBeCalledTimes(1) | ||
}) | ||
@@ -232,5 +332,8 @@ | ||
it('should trigger scrollToElement hook when scrollToElement method', () => { | ||
it('scrollToElement()', () => { | ||
let scrollToElementMockHandler = jest.fn() | ||
scroller.hooks.on('scrollToElement', scrollToElementMockHandler) | ||
scroller.hooks.on( | ||
scroller.hooks.eventTypes.scrollToElement, | ||
scrollToElementMockHandler | ||
) | ||
@@ -252,9 +355,29 @@ scroller.refresh(scroller.content) | ||
scroller.scrollToElement(content, 0, false, false) | ||
expect(scrollToElementMockHandler).toHaveBeenCalledWith(content, { | ||
expect(scrollToElementMockHandler).toBeCalled() | ||
// to a specified position | ||
scroller.scrollToElement(content, 0, 0, 0) | ||
expect(scrollToElementMockHandler).toHaveBeenLastCalledWith(content, { | ||
left: 0, | ||
top: 0, | ||
}) | ||
const mockFn2 = jest.fn() | ||
scroller.hooks.on(scroller.hooks.eventTypes.scrollToElement, () => true) | ||
scroller.hooks.on(scroller.hooks.eventTypes.scrollToElement, mockFn2) | ||
scroller.scrollToElement(content, 0, 0, 0) | ||
expect(mockFn2).not.toBeCalled() | ||
}) | ||
it('should enable or disable when call enable or disable method', () => { | ||
it('scrollBy ', () => { | ||
const mockFn = jest.fn() | ||
scroller.hooks.on(scroller.hooks.eventTypes.scrollTo, mockFn) | ||
scroller.scrollBy(20, 20) | ||
expect(mockFn).toBeCalledWith({ | ||
x: 20, | ||
y: 20, | ||
}) | ||
}) | ||
it('enable() & disable()', () => { | ||
scroller.disable() | ||
@@ -277,4 +400,5 @@ expect(scroller.actions.enabled).toBe(false) | ||
it('should invoking refresh method', () => { | ||
scroller.refresh(scroller.content) | ||
it('refresh()', () => { | ||
scroller.options.bindToTarget = true | ||
scroller.refresh(document.createElement('p')) | ||
@@ -284,5 +408,6 @@ expect(scroller.scrollBehaviorX.refresh).toBeCalled() | ||
expect(scroller.actions.refresh).toBeCalled() | ||
expect(scroller.actionsHandler.setContent).toBeCalled() | ||
}) | ||
it('should invoking destroy method', () => { | ||
it('destroy()', () => { | ||
scroller.destroy() | ||
@@ -301,2 +426,12 @@ const keys = [ | ||
}) | ||
it('resetPosition() ', () => { | ||
const mockFn = jest.fn() | ||
scroller.hooks.on(scroller.hooks.eventTypes.scrollTo, mockFn) | ||
scroller.resetPosition() | ||
expect(mockFn).toBeCalledWith({ | ||
x: 0, | ||
y: 0, | ||
}) | ||
}) | ||
}) |
@@ -202,2 +202,3 @@ import { getRect, Direction, EventEmitter } from '@better-scroll/shared-utils' | ||
this.relativeOffset = contentRect[position] | ||
/* istanbul ignore if */ | ||
if (isWrapperStatic) { | ||
@@ -204,0 +205,0 @@ this.relativeOffset -= wrapperRect[position] |
@@ -394,2 +394,3 @@ import ActionsHandler from '../base/ActionsHandler' | ||
// fix a scroll problem under Android condition | ||
/* istanbul ignore if */ | ||
if (isAndroid) { | ||
@@ -404,2 +405,3 @@ this.wrapper.scrollTop = 0 | ||
/* istanbul ignore next */ | ||
private transitionEnd(e: TouchEvent) { | ||
@@ -431,2 +433,3 @@ if (e.target !== this.content || !this.animater.pending) { | ||
// ignore BetterScroll instance's wrapper DOM | ||
/* istanbul ignore if */ | ||
if (node.isBScrollContainer) { | ||
@@ -589,2 +592,3 @@ continue | ||
/* istanbul ignore if */ | ||
if (isIOSBadVersion) { | ||
@@ -591,0 +595,0 @@ // fix ios 13.4 bouncing |
import { EventEmitter } from '@better-scroll/shared-utils' | ||
const Translater = jest.fn().mockImplementation(content => { | ||
const Translater = jest.fn().mockImplementation((content) => { | ||
return { | ||
@@ -9,3 +9,4 @@ style: content.style, | ||
translate: jest.fn(), | ||
destroy: jest.fn() | ||
destroy: jest.fn(), | ||
setContent: jest.fn(), | ||
} | ||
@@ -12,0 +13,0 @@ }) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
376380
71
9981