text: !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Infinity=e()}(this,function(){"use strict";function e(t){console.error("[BScroll warn]: "+t)}var o=function(){return(o=Object.assign||function(t){for(var e,o=1,n=arguments.length;o<n;o++)for(var i in e=arguments[o])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function t(t,r,a,h){return new(a=a||Promise)(function(o,e){function n(t){try{s(h.next(t))}catch(t){e(t)}}function i(t){try{s(h.throw(t))}catch(t){e(t)}}function s(t){var e;t.done?o(t.value):((e=t.value)instanceof a?e:new a(function(t){t(e)})).then(n,i)}s((h=h.apply(t,r||[])).next())})}function s(o,n){var i,s,r,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},t={next:e(0),throw:e(1),return:e(2)};return"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function e(e){return function(t){return function(e){if(i)throw new TypeError("Generator is already executing.");for(;a;)try{if(i=1,s&&(r=2&e[0]?s.return:e[0]?s.throw||((r=s.return)&&r.call(s),0):s.next)&&!(r=r.call(s,e[1])).done)return r;switch(s=0,r&&(e=[2&e[0],r.value]),e[0]){case 0:case 1:r=e;break;case 4:return a.label++,{value:e[1],done:!1};case 5:a.label++,s=e[1],e=[0];continue;case 7:e=a.ops.pop(),a.trys.pop();continue;default:if(!(r=0<(r=a.trys).length&&r[r.length-1])&&(6===e[0]||2===e[0])){a=0;continue}if(3===e[0]&&(!r||e[1]>r[0]&&e[1]<r[3])){a.label=e[1];break}if(6===e[0]&&a.label<r[1]){a.label=r[1],r=e;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(e);break}r[2]&&a.ops.pop(),a.trys.pop();continue}e=n.call(o,a)}catch(t){e=[6,t],s=0}finally{i=r=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}([e,t])}}}var n="undefined"!=typeof window,i=n&&navigator.userAgent.toLowerCase(),r=(i&&/wechatdevtools/.test(i),i&&i.indexOf("android"),function(){if("string"!=typeof i)return;var t=/os (\d\d?_\d(_\d)?)/.exec(i);if(!t)return;var e=t[1].split("_").map(function(t){return parseInt(t,10)});13===e[0]&&e[1]}(),n&&document.createElement("div").style),a=function(){if(!n)return!1;for(var t=0,e=[{key:"standard",value:"transform"},{key:"webkit",value:"webkitTransform"},{key:"Moz",value:"MozTransform"},{key:"O",value:"OTransform"},{key:"ms",value:"msTransform"}];t<e.length;t++){var o=e[t];if(void 0!==r[o.value])return o.key}return!1}();function h(t){return!1===a?t:"standard"===a?"transitionEnd"===t?"transitionend":t:a+t.charAt(0).toUpperCase()+t.substr(1)}var p=a&&"standard"!==a?"-"+a.toLowerCase()+"-":"",l=h("transform"),c=h("transition"),f=(n&&h("perspective")in r,l),y=c,u=(h("transitionTimingFunction"),h("transitionDuration"),h("transitionDelay"),h("transformOrigin"),h("transitionEnd"),h("transitionProperty"),d.prototype.calculate=function(t,e){var o=t-this.lastPos;this.lastPos=t;var n=this.getDirection(o),i=this.calculateIndex(0,t,e),s=this.calculateIndex(i,t+this.wrapperHeight,e);return 1===n?(i-=10,s+=30):(i-=30,s+=10),i<0&&(i=0),{start:i,end:s}},d.prototype.getDirection=function(t){var e;if(0<t)e=1;else{if(!(t<0))return this.lastDirection;e=0}return this.lastDirection=e},d.prototype.calculateIndex=function(t,e,o){if(e<=0)return t;for(var n=t,i=o[n]&&-1!==o[n].pos?o[n].pos:0,s=0;n<o.length&&o[n].pos<e;)i=o[n].pos,n++;return n===o.length&&(s=Math.floor((e-i)/this.tombstoneHeight)),n+=s},d.prototype.resetState=function(){this.lastDirection=1,this.lastPos=0},d);function d(t,e){this.wrapperHeight=t,this.tombstoneHeight=e,this.lastDirection=1,this.lastPos=0}var m=function(){this.data=null,this.dom=null,this.tombstone=null,this.width=0,this.height=0,this.pos=0},v=(g.prototype.update=function(o){return t(this,void 0,void 0,function(){var e;return s(this,function(t){return this.hasMore||(o=Math.min(o,this.list.length)),o>this.list.length&&(e=o-this.list.length,this.addEmptyData(e)),[2,this.checkToFetch(o)]})})},g.prototype.add=function(t){for(var e=0;e<t.length;e++)this.list[this.loadedNum]?this.list[this.loadedNum]=o(o({},this.list[this.loadedNum]),{data:t[e]}):this.list[this.loadedNum]={data:t[e]},this.loadedNum++;return this.list},g.prototype.addEmptyData=function(t){for(var e=0;e<t;e++)this.list.push(new m);return this.list},g.prototype.fetch=function(o){return t(this,void 0,void 0,function(){var e;return s(this,function(t){switch(t.label){case 0:return this.fetching?[2,[]]:(this.fetching=!0,[4,this.fetchFn(o)]);case 1:return e=t.sent(),this.fetching=!1,[2,e]}})})},g.prototype.checkToFetch=function(i){return t(this,void 0,void 0,function(){var e,o,n;return s(this,function(t){switch(t.label){case 0:return this.hasMore?i<=this.loadedNum?[2]:(e=i-this.loadedNum,[4,this.fetch(e)]):[2];case 1:return(o=t.sent())instanceof Array&&o.length?(this.add(o),n=this.onFetchFinish(this.list,!0),[2,this.checkToFetch(n)]):("boolean"==typeof o&&!1===o&&(this.hasMore=!1,this.list.splice(this.loadedNum),this.onFetchFinish(this.list,!1)),[2])}})})},g.prototype.getList=function(){return this.list},g.prototype.resetState=function(){this.loadedNum=0,this.fetching=!1,this.hasMore=!0,this.list=[]},g);function g(t,e,o){this.fetchFn=e,this.onFetchFinish=o,this.loadedNum=0,this.fetching=!1,this.hasMore=!0,this.list=t||[]}var b=(w.isTombstone=function(t){return!(!t||!t.classList)&&t.classList.contains("tombstone")},w.prototype.getSize=function(){var t;this.initialed||((t=this.create()).style.position="absolute",document.body.appendChild(t),t.style.display="",this.height=t.offsetHeight,this.width=t.offsetWidth,document.body.removeChild(t),this.cached.push(t))},w.prototype.getOne=function(){var t=this.cached.pop();if(t){var e=t.style;return e.display="",e.opacity="1",e[f]="",e[y]="",t}return this.create()},w.prototype.recycle=function(t){for(var e=0,o=t;e<o.length;e++){var n=o[e];n.style.display="none",this.cached.push(n)}return this.cached},w.prototype.recycleOne=function(t){return this.cached.push(t),this.cached},w);function w(t){this.create=t,this.cached=[],this.width=0,this.height=0,this.initialed=!1,this.getSize()}var T=(D.prototype.update=function(t,e,o){e>=t.length&&(e=t.length-1),o>t.length&&(o=t.length),this.collectUnusedDom(t,e,o),this.createDom(t,e,o),this.cacheHeight(t,e,o);var n=this.positionDom(t,e,o);return{start:e,startPos:n.startPos,startDelta:n.startDelta,end:o,endPos:n.endPos}},D.prototype.collectUnusedDom=function(t,e,o){for(var n,i=0;i<t.length;i++){i!==e?t[i].dom&&(n=t[i].dom,b.isTombstone(n)?(this.tombstone.recycleOne(n),n.style.display="none"):this.unusedDom.push(n),t[i].dom=null):i=o-1}return t},D.prototype.createDom=function(t,e,o){for(var n=e;n<o;n++){var i=t[n].dom,s=t[n].data;if(i){if(!b.isTombstone(i)||!s)continue;t[n].tombstone=i,t[n].dom=null}(i=s?this.renderFn(s,this.unusedDom.pop()):this.tombstone.getOne()).style.position="absolute",t[n].dom=i,t[n].pos=-1,this.content.appendChild(i)}},D.prototype.cacheHeight=function(t,e,o){for(var n=e;n<o;n++)t[n].data&&!t[n].height&&(t[n].height=t[n].dom.offsetHeight)},D.prototype.positionDom=function(t,e,o){for(var n=this,i=[],s=this.getStartPos(t,e,o),r=s.start,a=s.delta,h=r,l=e;l<o;l++){var c,u=t[l].tombstone;u&&((c=u.style)[y]=p+"transform 200ms, opacity 200ms",c[f]="translateY("+h+"px)",c.opacity="0",t[l].tombstone=null,i.push(u)),t[l].dom&&t[l].pos!==h&&(t[l].dom.style[f]="translateY("+h+"px)",t[l].pos=h),h+=t[l].height||this.tombstone.height}var d=window.setTimeout(function(){n.tombstone.recycle(i)},200);return this.timers.push(d),{startPos:r,startDelta:a,endPos:h}},D.prototype.getStartPos=function(t,e,o){if(t[e]&&-1!==t[e].pos)return{start:t[e].pos,delta:0};for(var n=-1===t[0].pos?0:t[0].pos,i=0;i<e;i++)n+=t[i].height||this.tombstone.height;for(var s=n,r=e;r<o;r++)if(!b.isTombstone(t[r].dom)&&-1!==t[r].pos){n=t[r].pos;break}var a=r;if(a<o)for(;e<a;)n-=t[a-1].height,a--;return{start:n,delta:s-n}},D.prototype.removeTombstone=function(){for(var t=this.content.querySelectorAll(".tombstone"),e=t.length-1;0<=e;e--)this.content.removeChild(t[e])},D.prototype.setContent=function(t){t!==this.content&&(this.content=t)},D.prototype.destroy=function(){this.removeTombstone(),this.timers.forEach(function(t){clearTimeout(t)})},D.prototype.resetState=function(){this.destroy(),this.timers=[],this.unusedDom=[]},D);function D(t,e,o){this.renderFn=e,this.tombstone=o,this.unusedDom=[],this.timers=[],this.setContent(t)}function F(t){this.scroll=t,this.start=0,this.end=0,this.init()}return F.prototype.init=function(){var e=this;this.handleOptions();var t=this.options,o=t.fetch,n=t.render,i=t.createTombstone;this.tombstone=new b(i),this.indexCalculator=new u(this.scroll.scroller.scrollBehaviorY.wrapperSize,this.tombstone.height),this.domManager=new T(this.scroll.scroller.content,n,this.tombstone),this.dataManager=new v([],o,this.onFetchFinish.bind(this)),this.scroll.on(this.scroll.eventTypes.destroy,this.destroy,this),this.scroll.on(this.scroll.eventTypes.scroll,this.update,this),this.scroll.on(this.scroll.eventTypes.contentChanged,function(t){e.domManager.setContent(t),e.indexCalculator.resetState(),e.domManager.resetState(),e.dataManager.resetState(),e.update({y:0})});var s=this.scroll.scroller.scrollBehaviorY;s.hooks.on(s.hooks.eventTypes.computeBoundary,this.modifyBoundary,this),this.update({y:0})},F.prototype.modifyBoundary=function(t){t.maxScrollPos=-2e3},F.prototype.handleOptions=function(){var t=this.scroll.options.infinity;t&&("function"!=typeof t.fetch&&e("Infinity plugin need fetch Function to new data."),"function"!=typeof t.render&&e("Infinity plugin need render Function to render each item."),"function"!=typeof t.render&&e("Infinity plugin need createTombstone Function to create tombstone."),this.options=t),this.scroll.options.probeType=3},F.prototype.update=function(t){var e=Math.round(-t.y),o=this.indexCalculator.calculate(e,this.dataManager.getList()),n=o.start,i=o.end;this.start=n,this.end=i,this.dataManager.update(i),this.updateDom(this.dataManager.getList())},F.prototype.onFetchFinish=function(t,e){var o=this.updateDom(t).end;return e||(this.domManager.removeTombstone(),this.scroll.scroller.animater.stop(),this.scroll.resetPosition()),o},F.prototype.updateDom=function(t){var e=this.domManager.update(t,this.start,this.end),o=e.end,n=e.startPos,i=e.endPos,s=e.startDelta;return s&&(this.scroll.minScrollY=s),i>this.scroll.maxScrollY&&(this.scroll.maxScrollY=-(i-this.scroll.scroller.scrollBehaviorY.wrapperSize)),{end:o,startPos:n,endPos:i}},F.prototype.destroy=function(){for(var t=this.scroll.scroller,e=t.content,o=t.scrollBehaviorY;e.firstChild;)e.removeChild(e.firstChild);this.domManager.destroy(),this.scroll.off("scroll",this.update),this.scroll.off("destroy",this.destroy),o.hooks.off(o.hooks.eventTypes.computeBoundary)},F.pluginName="infinity",F});
  