text: !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Slide=t()}(this,function(){"use strict";function e(e){console.error("[BScroll warn]: "+e)}function i(e,t){for(var i in t)e[i]=t[i];return e}var s="undefined"!=typeof window,o=s&&navigator.userAgent.toLowerCase();o&&/wechatdevtools/.test(o),o&&o.indexOf("android"),function(){if("string"!=typeof o)return;var e=/os (\d\d?_\d(_\d)?)/.exec(o);if(!e)return;var t=e[1].split("_").map(function(e){return parseInt(e,10)});13===t[0]&&t[1]}();function g(e,t,i){return e<t?t:i<e?i:e}var r=s&&document.createElement("div").style,t=function(){if(!s)return!1;for(var e=0,t=[{key:"standard",value:"transform"},{key:"webkit",value:"webkitTransform"},{key:"Moz",value:"MozTransform"},{key:"O",value:"OTransform"},{key:"ms",value:"msTransform"}];e<t.length;e++){var i=t[e];if(void 0!==r[i.value])return i.key}return!1}();function a(e){return!1===t?e:"standard"===t?"transitionEnd"===e?"transitionend":e:t+e.charAt(0).toUpperCase()+e.substr(1)}t&&"standard"!==t&&t.toLowerCase();var n=a("transform"),h=a("transition");s&&a("perspective")in r,a("transitionTimingFunction"),a("transitionDuration"),a("transitionDelay"),a("transformOrigin"),a("transitionEnd"),a("transitionProperty");var p={swipe:{style:"cubic-bezier(0.23, 1, 0.32, 1)",fn:function(e){return 1+--e*e*e*e*e}},swipeBounce:{style:"cubic-bezier(0.25, 0.46, 0.45, 0.94)",fn:function(e){return e*(2-e)}},bounce:{style:"cubic-bezier(0.165, 0.84, 0.44, 1)",fn:function(e){return 1- --e*e*e*e}}},l=(c.prototype.init=function(){var e=this.scroll.scroller,t=e.scrollBehaviorX,i=e.scrollBehaviorY;this.wrapperWidth=t.wrapperSize,this.wrapperHeight=i.wrapperSize,this.scrollerHeight=i.contentSize,this.scrollerWidth=t.contentSize,this.pages=this.buildPagesMatrix(this.wrapperWidth,this.wrapperHeight),this.pageLengthOfX=this.pages?this.pages.length:0,this.pageLengthOfY=this.pages&&this.pages[0]?this.pages[0].length:0},c.prototype.getPageStats=function(e,t){return this.pages[e][t]},c.prototype.getNearestPageIndex=function(e,t){for(var i=0,s=0,o=this.pages.length;i<o-1&&!(e>=this.pages[i][0].cx);i++);for(o=this.pages[i].length;s<o-1&&!(t>=this.pages[0][s].cy);s++);return{pageX:i,pageY:s}},c.prototype.buildPagesMatrix=function(e,t){for(var i,s,o=[],r=0,a=0,n=this.scroll.scroller.scrollBehaviorX.maxScrollPos,h=this.scroll.scroller.scrollBehaviorY.maxScrollPos,g=Math.round(e/2),p=Math.round(t/2);r>-this.scrollerWidth;){for(o[a]=[],i=s=0;i>-this.scrollerHeight;)o[a][s]={x:Math.max(r,n),y:Math.max(i,h),width:e,height:t,cx:r-g,cy:i-p},i-=t,s++;r-=e,a++}return o},c);function c(e){this.scroll=e,this.init()}var u={pageX:0,pageY:0,x:0,y:0},d=(f.prototype.refresh=function(){this.pagesMatrix=new l(this.scroll),this.checkSlideLoop(),this.currentPage=this.getAdjustedCurrentPage()},f.prototype.getAdjustedCurrentPage=function(){var e=this.currentPage,t=e.pageX,i=e.pageY,t=Math.min(t,this.pagesMatrix.pageLengthOfX-1),i=Math.min(i,this.pagesMatrix.pageLengthOfY-1);this.loopX&&(t=Math.min(t,this.pagesMatrix.pageLengthOfX-2)),this.loopY&&(i=Math.min(i,this.pagesMatrix.pageLengthOfY-2));var s=this.pagesMatrix.getPageStats(t,i);return{pageX:t,pageY:i,x:s.x,y:s.y}},f.prototype.setCurrentPage=function(e){this.currentPage=e},f.prototype.getInternalPage=function(e,t){e>=this.pagesMatrix.pageLengthOfX?e=this.pagesMatrix.pageLengthOfX-1:e<0&&(e=0),t>=this.pagesMatrix.pageLengthOfY?t=this.pagesMatrix.pageLengthOfY-1:t<0&&(t=0);var i=this.pagesMatrix.getPageStats(e,t);return{pageX:e,pageY:t,x:i.x,y:i.y}},f.prototype.getInitialPage=function(e){void 0===e&&(e=!1);var t=this.loopX?1:0,i=this.loopY?1:0,s=e?t:this.currentPage.pageX,o=e?i:this.currentPage.pageY,r=this.pagesMatrix.getPageStats(s,o);return{pageX:s,pageY:o,x:r.x,y:r.y}},f.prototype.getExposedPage=function(e){var t=i({},e);return this.loopX&&(t.pageX=this.fixedPage(t.pageX,this.pagesMatrix.pageLengthOfX-2)),this.loopY&&(t.pageY=this.fixedPage(t.pageY,this.pagesMatrix.pageLengthOfY-2)),t},f.prototype.getExposedPageByPageIndex=function(e,t){var i={pageX:e,pageY:t};this.loopX&&(i.pageX=e+1),this.loopY&&(i.pageY=t+1);var s=this.pagesMatrix.getPageStats(i.pageX,i.pageY);return{x:s.x,y:s.y,pageX:e,pageY:t}},f.prototype.getWillChangedPage=function(e){return e=i({},e),this.loopX&&(e.pageX=this.fixedPage(e.pageX,this.pagesMatrix.pageLengthOfX-2),e.x=this.pagesMatrix.getPageStats(e.pageX+1,0).x),this.loopY&&(e.pageY=this.fixedPage(e.pageY,this.pagesMatrix.pageLengthOfY-2),e.y=this.pagesMatrix.getPageStats(0,e.pageY+1).y),e},f.prototype.fixedPage=function(e,t){for(var i=[],s=0;s<t;s++)i.push(s);return i.unshift(t-1),i.push(0),i[e]},f.prototype.getPageStats=function(){return this.pagesMatrix.getPageStats(this.currentPage.pageX,this.currentPage.pageY)},f.prototype.getValidPageIndex=function(e,t){var i=this.pagesMatrix.pageLengthOfX-1,s=this.pagesMatrix.pageLengthOfY-1,o=0,r=0;return this.loopX&&(e+=1,o+=1,--i),this.loopY&&(t+=1,r+=1,--s),{pageX:e=g(e,o,i),pageY:t=g(t,r,s)}},f.prototype.nextPageIndex=function(){return this.getPageIndexByDirection("positive")},f.prototype.prevPageIndex=function(){return this.getPageIndexByDirection("negative")},f.prototype.getNearestPage=function(e,t){var i=this.pagesMatrix.getNearestPageIndex(e,t),s=i.pageX,o=i.pageY;return{x:this.pagesMatrix.getPageStats(s,0).x,y:this.pagesMatrix.getPageStats(0,o).y,pageX:s,pageY:o}},f.prototype.getPageByDirection=function(e,t,i){var s=e.pageX,o=e.pageY;return s===this.currentPage.pageX&&(s=g(s+t,0,this.pagesMatrix.pageLengthOfX-1)),o===this.currentPage.pageY&&(o=g(o+i,0,this.pagesMatrix.pageLengthOfY-1)),{x:this.pagesMatrix.getPageStats(s,0).x,y:this.pagesMatrix.getPageStats(0,o).y,pageX:s,pageY:o}},f.prototype.resetLoopPage=function(){if(this.loopX){if(0===this.currentPage.pageX)return{pageX:this.pagesMatrix.pageLengthOfX-2,pageY:this.currentPage.pageY};if(this.currentPage.pageX===this.pagesMatrix.pageLengthOfX-1)return{pageX:1,pageY:this.currentPage.pageY}}if(this.loopY){if(0===this.currentPage.pageY)return{pageX:this.currentPage.pageX,pageY:this.pagesMatrix.pageLengthOfY-2};if(this.currentPage.pageY===this.pagesMatrix.pageLengthOfY-1)return{pageX:this.currentPage.pageX,pageY:1}}},f.prototype.getPageIndexByDirection=function(e){var t=this.currentPage.pageX,i=this.currentPage.pageY;return this.slideX&&(t="negative"===e?t-1:t+1),this.slideY&&(i="negative"===e?i-1:i+1),{pageX:t,pageY:i}},f.prototype.checkSlideLoop=function(){this.wannaLoop=this.slideOptions.loop,1<this.pagesMatrix.pageLengthOfX?this.slideX=!0:this.slideX=!1,this.pagesMatrix.pages[0]&&1<this.pagesMatrix.pageLengthOfY?this.slideY=!0:this.slideY=!1,this.loopX=this.wannaLoop&&this.slideX,this.loopY=this.wannaLoop&&this.slideY,this.slideX&&this.slideY&&e("slide does not support two direction at the same time.")},f);function f(e,t){this.scroll=e,this.slideOptions=t,this.slideX=!1,this.slideY=!1,this.currentPage=i({},u)}var y=[{key:"next",name:"next"},{key:"prev",name:"prev"},{key:"goToPage",name:"goToPage"},{key:"getCurrentPage",name:"getCurrentPage"},{key:"startPlay",name:"startPlay"},{key:"pausePlay",name:"pausePlay"}].map(function(e){return{key:e.key,sourceKey:"plugins.slide."+e.name}});function P(e){this.scroll=e,this.cachedClonedPageDOM=[],this.resetLooping=!1,this.autoplayTimer=0,this.satisfyInitialization()&&this.init()}return P.prototype.satisfyInitialization=function(){return!(this.scroll.scroller.content.children.length<=0)||(e("slide need at least one slide page to be initialised.please check your DOM layout."),!1)},P.prototype.init=function(){this.willChangeToPage=i({},u),this.handleBScroll(),this.handleOptions(),this.handleHooks(),this.createPages()},P.prototype.createPages=function(){this.pages=new d(this.scroll,this.options)},P.prototype.handleBScroll=function(){this.scroll.registerType(["slideWillChange","slidePageChanged"]),this.scroll.proxy(y)},P.prototype.handleOptions=function(){var e=!0===this.scroll.options.slide?{}:this.scroll.options.slide,t={loop:!0,threshold:.1,speed:400,easing:p.bounce,listenFlick:!0,autoplay:!0,interval:3e3};this.options=i(t,e)},P.prototype.handleLoop=function(e){var t=this.options.loop,i=this.scroll.scroller.content,s=i.children.length;t&&(i!==e?(this.resetLoopChangedStatus(),this.removeClonedSlidePage(e),1<s&&this.cloneFirstAndLastSlidePage(i)):3===s&&this.initialised?(this.removeClonedSlidePage(i),this.moreToOnePageInLoop=!0,this.oneToMorePagesInLoop=!1):1<s?(this.initialised&&0===this.cachedClonedPageDOM.length?(this.oneToMorePagesInLoop=!0,this.moreToOnePageInLoop=!1):(this.removeClonedSlidePage(i),this.resetLoopChangedStatus()),this.cloneFirstAndLastSlidePage(i)):this.resetLoopChangedStatus())},P.prototype.resetLoopChangedStatus=function(){this.moreToOnePageInLoop=!1,this.oneToMorePagesInLoop=!1},P.prototype.handleHooks=function(){var t=this,e=this.scroll.hooks,i=this.scroll.scroller.hooks,s=this.options.listenFlick;this.prevContent=this.scroll.scroller.content,this.hooksFn=[],this.registerHooks(this.scroll,this.scroll.eventTypes.beforeScrollStart,this.pausePlay),this.registerHooks(this.scroll,this.scroll.eventTypes.scrollEnd,this.modifyCurrentPage),this.registerHooks(this.scroll,this.scroll.eventTypes.scrollEnd,this.startPlay),this.scroll.eventTypes.mousewheelMove&&(this.registerHooks(this.scroll,this.scroll.eventTypes.mousewheelMove,function(){return!0}),this.registerHooks(this.scroll,this.scroll.eventTypes.mousewheelEnd,function(e){1!==e.directionX&&1!==e.directionY||t.next(),-1!==e.directionX&&-1!==e.directionY||t.prev()})),this.registerHooks(e,e.eventTypes.refresh,this.refreshHandler),this.registerHooks(e,e.eventTypes.destroy,this.destroy),this.registerHooks(i,i.eventTypes.beforeRefresh,function(){t.handleLoop(t.prevContent),t.setSlideInlineStyle()}),this.registerHooks(i,i.eventTypes.momentum,this.modifyScrollMetaHandler),this.registerHooks(i,i.eventTypes.scroll,this.scrollHandler),this.registerHooks(i,i.eventTypes.checkClick,this.startPlay),s&&this.registerHooks(i,i.eventTypes.flick,this.flickHandler)},P.prototype.startPlay=function(){var e=this,t=this.options,i=t.interval;t.autoplay&&(clearTimeout(this.autoplayTimer),this.autoplayTimer=window.setTimeout(function(){e.next()},i))},P.prototype.pausePlay=function(){this.options.autoplay&&clearTimeout(this.autoplayTimer)},P.prototype.setSlideInlineStyle=function(){var e=this.scroll.scroller,h=e.content,g=e.wrapper,p=this.scroll.options;[{direction:"scrollX",sizeType:"offsetWidth",styleType:"width"},{direction:"scrollY",sizeType:"offsetHeight",styleType:"height"}].forEach(function(e){var t=e.direction,i=e.sizeType,s=e.styleType;if(p[t]){for(var o=g[i],r=h.children,a=r.length,n=0;n<a;n++){r[n].style[s]=o+"px"}h.style[s]=o*a+"px"}})},P.prototype.next=function(e,t){var i=this.pages.nextPageIndex(),s=i.pageX,o=i.pageY;this.goTo(s,o,e,t)},P.prototype.prev=function(e,t){var i=this.pages.prevPageIndex(),s=i.pageX,o=i.pageY;this.goTo(s,o,e,t)},P.prototype.goToPage=function(e,t,i,s){var o=this.pages.getValidPageIndex(e,t);this.goTo(o.pageX,o.pageY,i,s)},P.prototype.getCurrentPage=function(){return this.exposedPage||this.pages.getInitialPage(!0)},P.prototype.setCurrentPage=function(e){this.pages.setCurrentPage(e),this.exposedPage=this.pages.getExposedPage(e)},P.prototype.nearestPage=function(e,t){var i=this.scroll.scroller,s=i.scrollBehaviorX,o=i.scrollBehaviorY,r=s.maxScrollPos,a=s.minScrollPos,n=o.maxScrollPos,h=o.minScrollPos;return this.pages.getNearestPage(g(e,r,a),g(t,n,h))},P.prototype.satisfyThreshold=function(e,t){var i=this.scroll.scroller,s=i.scrollBehaviorX,o=i.scrollBehaviorY,r=!0;return Math.abs(e-s.absStartPos)<=this.thresholdX&&Math.abs(t-o.absStartPos)<=this.thresholdY&&(r=!1),r},P.prototype.refreshHandler=function(e){var t,i,s=this;this.satisfyInitialization()&&(this.pages.refresh(),this.computeThreshold(),(t=this.contentChanged=this.prevContent!==e)&&(this.prevContent=e),i=this.pages.getInitialPage(!this.initialised||t||this.oneToMorePagesInLoop||this.moreToOnePageInLoop),this.initialised?this.goTo(i.pageX,i.pageY,0):this.registerHooks(this.scroll.hooks,this.scroll.hooks.eventTypes.beforeInitialScrollTo,function(e){s.initialised=!0,e.x=i.x,e.y=i.y}),this.startPlay())},P.prototype.computeThreshold=function(){var e,t,i,s=this.options.threshold;s%1==0?(this.thresholdX=s,this.thresholdY=s):(t=(e=this.pages.getPageStats()).width,i=e.height,this.thresholdX=Math.round(t*s),this.thresholdY=Math.round(i*s))},P.prototype.cloneFirstAndLastSlidePage=function(e){var t,i,s,o,r,a=e.children,n=a[a.length-1].cloneNode(!0),h=a[0].cloneNode(!0);t=n,(r=(i=e).firstChild)?(s=t,(o=r).parentNode.insertBefore(s,o)):i.appendChild(t),e.appendChild(h),this.cachedClonedPageDOM=[n,h]},P.prototype.removeClonedSlidePage=function(i){(i&&i.children||[]).length&&this.cachedClonedPageDOM.forEach(function(e){var t;t=e,i.removeChild(t)}),this.cachedClonedPageDOM=[]},P.prototype.modifyCurrentPage=function(e){if(!this.scroll.scroller.animater.forceStopped){var t=this.getCurrentPage(),i=t.pageX,s=t.pageY,o=this.nearestPage(e.x,e.y);if(this.setCurrentPage(o),this.contentChanged)return!(this.contentChanged=!1);var r,a=this.getCurrentPage(),n=a.pageX,h=a.pageY;if(this.pageWillChangeTo(o),this.oneToMorePagesInLoop)return!(this.oneToMorePagesInLoop=!1);if(this.moreToOnePageInLoop&&0===i&&0===s)return!(this.moreToOnePageInLoop=!1);if(i===n&&s===h||(r=this.pages.getExposedPageByPageIndex(n,h),this.scroll.trigger(this.scroll.eventTypes.slidePageChanged,r)),!this.resetLooping){var g=this.pages.resetLoopPage();return g?(this.resetLooping=!0,this.goTo(g.pageX,g.pageY,0),!0):void 0}this.resetLooping=!1}},P.prototype.goTo=function(e,t,i,s){var o=this.pages.getInternalPage(e,t),r=s||this.options.easing||p.bounce,a=o.x,n=o.y,h=a-this.scroll.scroller.scrollBehaviorX.currentPos,g=n-this.scroll.scroller.scrollBehaviorY.currentPos;(h||g)&&(i=void 0===i?this.getEaseTime(h,g):i,this.scroll.scroller.scrollTo(a,n,i,r))},P.prototype.flickHandler=function(){var e=this.scroll.scroller,t=e.scrollBehaviorX,i=e.scrollBehaviorY,s=t.currentPos,o=t.startPos,r=t.direction,a=i.currentPos,n=i.startPos,h=i.direction,g=this.pages.currentPage,p=g.pageX,l=g.pageY,c=this.getEaseTime(s-o,a-n);this.goTo(p+r,l+h,c)},P.prototype.getEaseTime=function(e,t){return this.options.speed||Math.max(Math.max(Math.min(Math.abs(e),1e3),Math.min(Math.abs(t),1e3)),300)},P.prototype.modifyScrollMetaHandler=function(e){var t=this.scroll.scroller,i=t.scrollBehaviorX,s=t.scrollBehaviorY,o=t.animater,r=e.newX,a=e.newY,n=this.satisfyThreshold(r,a)||o.forceStopped?this.pages.getPageByDirection(this.nearestPage(r,a),i.direction,s.direction):this.pages.currentPage;e.time=this.getEaseTime(e.newX-n.x,e.newY-n.y),e.newX=n.x,e.newY=n.y,e.easing=this.options.easing||p.bounce},P.prototype.scrollHandler=function(e){var t,i=e.x,s=e.y;this.satisfyThreshold(i,s)&&(t=this.nearestPage(i,s),this.pageWillChangeTo(t))},P.prototype.pageWillChangeTo=function(e){var t,i,s=this.pages.getWillChangedPage(e);t=this.willChangeToPage,i=s,t.pageX===i.pageX&&t.pageY===i.pageY||(this.willChangeToPage=s,this.scroll.trigger(this.scroll.eventTypes.slideWillChange,this.willChangeToPage))},P.prototype.registerHooks=function(e,t,i){e.on(t,i,this),this.hooksFn.push([e,t,i])},P.prototype.destroy=function(){var e=this.scroll.scroller.content,t=this.options,i=t.loop,s=t.autoplay;i&&this.removeClonedSlidePage(e),s&&clearTimeout(this.autoplayTimer),this.hooksFn.forEach(function(e){var t=e[0],i=e[1],s=e[2];t.eventTypes[i]&&t.off(i,s)}),this.hooksFn.length=0},P.pluginName="slide",P});
  