移动端 触屏滑动条菜单(完善版)
1 |
惯性滚动
关于惯性滚动速度
方法一
1 2 | //speed = ( 结束时候手的位置 - 起点的位置 ) / ( 结束时候的时间 - 开始时的时间 ) speed = (endY - startY) / (endTime - startTime); |
方法二
1 2 | iSpeedX = touchs.pageX - prevX;//获取出手一瞬间的速度 prevX = touchs.pageX;//当前的始终覆盖上一个 |
出手一瞬间的速度,上图红色的小点,是用户出手一瞬间形成轨迹,用户 touchmove的触摸的点不是连续的;
<! doctype html> < html > < head > < meta charset="utf-8"> < title >无标题文档</ title > </ head > < body > < style > #div1{ width:90px; height:90px; border:3px solid #666; background:#903; background:url(../../images/1.jpg) no-repeat center center; position:absolute; cursor:move; position:absolute;} .box{ border:2px solid #C00; position:absolute;} </ style > < div id="div1" style="display:block; ">啊实打实大阿达撒阿达撒爱上爱的</ div > <!--<img id="div2" src="../../images/1.jpg">--> < script > window.onload=function(){ var oDiv=document.getElementById("div1"); //var oDiv=document.getElementById("div2"); var disX=0; var disY=0; oDiv.onmousedown=function(event){ var event = event || window.event || arguments.callee.caller.arguments[0]; disX=event.clientX-oDiv.offsetLeft; disY=event.clientY-oDiv.offsetTop; if(oDiv.setCapture){ oDiv.setCapture(); } //oDiv.onmousemove=function(ev){ //odiv移动过快 存在问题 document.onmousemove=function(event){ var event = event || window.event || arguments.callee.caller.arguments[0]; oDiv.style.left=event.clientX-disX+'px'; oDiv.style.top=event.clientY-disY +'px'; var oBox=document.createElement('div'); oBox.className='box'; oBox.style.left=event.clientX+'px'; oBox.style.top=event.clientY+'px'; document.body.appendChild(oBox); }; document.onmouseup=function(){ document.onmousemove=null; document.onmouseup=null;//可能遇到的问题 }; return false;//解决图片拖拽问题 冒泡 };// onmousedown end }; </ script > </ body > </ html > |
关于惯性滚动开启条件
惯性滚动的启动需要有足够的动量。我们可以简单地认为,当用户滚动的距离足够大(大于 15px)和持续时间足够短(小于 300ms)时,即可产生惯性滚动。
换成编程语言就是,最后一次 touchmove 事件触发的时间和 touchend 事件触发的时间间隔小于 300ms,且两者产生的距离差大于 15px 时认为可启动惯性滚动。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | //mouseWheelSpeed 设置鼠标滚轮滚动的速度值。 120 //momentum 快速在屏幕上滑动一段距离的时候,会根据滑动的距离和时间计算出动量,并生成滚动动画。设置为 true 则开启动画 //只有在屏幕上快速滑动的时间小于 momentumLimitTime 300(单位ms,才能开启 momentum 动画 //只有在屏幕上快速滑动的距离大于 momentumLimitDistance 15(单位px),才能开启 momentum 动画 //只有用户在屏幕上滑动的时间小于 flickLimitTime 200 (单位ms) ,才算一次轻拂 //只有用户在屏幕上滑动的距离小于 flickLimitDistance 100(单位px,才算一次轻拂 // better-scroll. // var distance = current - start; // var speed = Math.abs(distance) / time; // //deceleration 0.0015 //这个值可以改变改变动画的势头持续时间/速度。更高的数字使动画更短。 // var deceleration = options.deceleration, swipeBounceTime = options.swipeBounceTime, swipeTime = options.swipeTime; // var duration = Math.min(swipeTime, (speed * 2) / deceleration); |
关于惯性滚动 获取速度 方法二 伪代码
1 2 3 4 5 6 7 8 9 10 | oUl.ontouchstart = function(ev){ var touchs = ev.changedTouches[0]; prevY = touchs.pageY; oUl.ontouchmove = function(ev){ var touchs = ev.changedTouches[0]; iSpeedY = touchs.pageY - prevY; prevY = touchs.pageY; |
关于惯性滚动 获取速度 方法一 伪代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 速度*时间=路程 滑动的速度=( 路程 / ( 离开时的时间 - 触摸时的时间 ) ) var content = document.querySelector('.s-content') , body = document.querySelector('.s-body') body.ontouchstart = function (event) { // 手触摸下去那一刻 // 需要存几个东西 // 起点的位置、这时的时间、.s-content 的起点位置 body.ontouchmove = function (event) { // 手在屏幕上移动 // 需要计算 .s-content 的当前位置,并赋值,计算公式是: // 获取到手当前的位置 - 起点的位置 + .s-content 的起点位置 } body.ontouchend = function (event) { // 手离开屏幕 // 计算初始 speed // speed = ( 结束时候手的位置 - 起点的位置 ) / ( 结束时候的时间 - 开始时的时间 ) // 打开定时器,根据 speed 让 .s-content 进行运动,然后 speed 进行减速运动 speed = speed - a ; a = g( speed ) ; 根据这两个公式进行运算即可 } } |
例子:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | <! doctype html> < html > < head > < meta charset="utf-8"> < meta name="viewport" content="width=320,user-scalable=no" /> < title >菜单条</ title > </ head > < body > < style style='display:none' contentEditable> *{ margin:0; padding:0;} ul,li{ margin:0; padding:0; list-style:none;} #outer{ border:1px solid red; width:300px; height:46px; margin:20px auto; text-align:center; vertical-align:middle; line-height:46px; position:relative; overflow:hidden; background:#eee;} #outer:hover{ border-color:#333; cursor:pointer;} #inner{ position:absolute; left:0; top:1px; height:44px; line-height:44px; width:300px; background:#666; text-align:left; clear:both; overflow:hidden;} #inner li{ width:auto; height:44px; float:left; display:inline; padding:0 15px; text-align:center; } #inner li:hover{ background:#333;} #inner li a{font-size:14px; color:#fff; display:inline;width:auto; height:44px; line-height:44px; text-decoration:none;} .translateZ{ -webkit-transform:translateZ(0);transform:translateZ(0);-webkit-backface-visibility: hidden;backface-visibility: hidden;} .classtest{ background:#333;} </ style > < div id="outer"> < ul id="inner" > < li >< a href="">首页start</ a ></ li > < li >< a href="">美剧1</ a ></ li > < li >< a href="">电影1</ a ></ li > < li >< a href="">购物1</ a ></ li > < li >< a href="">时尚1</ a ></ li > < li >< a href="">新闻1</ a ></ li > < li >< a href="">其他1</ a ></ li > < li >< a href="">热点1</ a ></ li > < li >< a href="">电视1</ a ></ li > < li >< a href="">历史1</ a ></ li > < li >< a href="">首页2</ a ></ li > < li >< a href="">美剧2</ a ></ li > < li >< a href="">电影2</ a ></ li > < li >< a href="">购物2</ a ></ li > < li >< a href="">时尚2</ a ></ li > < li >< a href="">新闻2</ a ></ li > < li >< a href="">其他2</ a ></ li > < li >< a href="">热点2</ a ></ li > < li >< a href="">电视2</ a ></ li > < li >< a href="">结尾end</ a ></ li > </ ul > </ div > touches:当前屏幕上所有手指的列表 targetTouches:当前dom元素上手指的列表,尽量使用这个代替touches changedTouches:涉及当前事件的手指的列表,尽量使用这个代替touches < script src="../js/jquery-1.9.1.min.js"></ script > < script > window.onload=function(){ function getStyle(obj,attr){ return obj.currentStyle? obj.currentStyle[attr]:getComputedStyle(obj,false)[attr]; } var support = document.body.classList==undefined ? false : true ; var outer=document.getElementById("outer"); var inner=document.getElementById("inner"); var li=inner.getElementsByTagName("li"); var innerWd=0,i=0; for(;i< li.length ;i++){ innerWd+=li[i].offsetWidth; } inner.style.width=innerWd+'px'; var startX=0; var alls=0; var moveLeft=0; var iSpeedX = 0; var prevX = 0; var timer = null; var resetStartX=true; var maxDistance=parseInt(outer.offsetWidth-innerWd); //最大滑动距离 inner.addEventListener("touchstart",start,false); function start(e){ if(inner.offsetWidth<outer.offsetWidth)return;//如果内部元素小于外框 不需要滑动 var e=e||window.event; e.preventDefault(); var touchs=e.touches[0], resetStartX=true;; //startX=prevX=touchs.pageX; startX=touchs.pageX; prevX=touchs.pageX; alls=this.offsetLeft; inner.addEventListener("touchmove",move,false); inner.addEventListener("touchend",end,false); } function move(e){ var e=e||window.event; if (e.touches.length > 1 || e.scale && e.scale !== 1) return; // 当屏幕有多个touch或者页面被缩放过,就不执行move操作 var touchs=e.changedTouches[0]; iSpeedX = touchs.pageX - prevX;//获取出手一瞬间的速度 prevX = touchs.pageX;//当前的始终覆盖上一个 moveLeft=touchs.pageX-startX; var that=this; if(that.offsetLeft>=0){ if(resetStartX){ startX=touchs.pageX; resetStartX=false; } that.style.left=moveLeft/3+alls+'px'; }else if(that.offsetLeft<=maxDistance){ if(resetStartX){ startX=touchs.pageX; resetStartX=false; } that.style.left=moveLeft/3+alls+'px'; }else{ that.style.left=moveLeft+alls+'px'; } //this.style.webkitTransform='translateZ(0)'; //移动时候 缓存到GPU层 that.classList.add('translateZ'); //classList 对已经增加的样式 不在判断是否添加 GPU缓存hack e.preventDefault(); } function end(){ var self=this; clearInterval(timer); timer=setInterval(function(){ if(Math.abs(iSpeedX)<=1||self.offsetLeft>50||self.offsetLeft< maxDistance-50 ){ clearInterval(timer); //if(self.classList.contains('translateZ')){ //滚动停止 结束时候回收GPU 垃圾 // // self.classList.remove('translateZ'); //不知道怎么删除这样样式 // // self.setAttribute("class",''); // } if(self.offsetLeft>=0){ $(inner).animate({left:0},300,function(){ self.classList.remove('translateZ'); //移除PGU hack }); } if(self.offsetLeft< maxDistance ){ $(inner).animate({left:maxDistance+'px'},300,function(){ self.classList.remove('translateZ'); //移除PGU hack }); } }else{ iSpeedX *= 0.95; self.style.left = parseInt(self.offsetLeft + iSpeedX) + 'px'; } },20); self.removeEventListener("touchmove",move,false); self.removeEventListener("touchend",end,false); //self.style.webkitTransform=''; } } </script> </ body > </ html > |
1 |
1 |
优化滑动 setTimeout 相对减少时间计数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | function end(){ var self= this ; clearTimeout(timer); timer=setTimeout( function (){ if (Math.abs(iSpeedX)<=1||self.offsetLeft>50||self.offsetLeft<maxDistance-50){ clearTimeout(timer); //if(self.classList.contains('translateZ')){ //滚动停止 结束时候回收GPU 垃圾 // // self.classList.remove('translateZ'); //不知道怎么删除这样样式 // // self.setAttribute("class",''); // } if (self.offsetLeft>=0){ $(inner).animate({left:0},300, function (){ self.classList.remove( 'translateZ' ); //移除PGU hack }); } if (self.offsetLeft<maxDistance){ $(inner).animate({left:maxDistance+ 'px' },300, function (){ self.classList.remove( 'translateZ' ); //移除PGU hack }); } } else { iSpeedX *= 0.95; self.style.left = parseInt(self.offsetLeft + iSpeedX) + 'px' ; console.log( 'setTimeoutsss' ); setTimeout(arguments.callee,16) } },16); self.removeEventListener( "touchmove" ,move, false ); self.removeEventListener( "touchend" ,end, false ); //self.style.webkitTransform=''; } |
优化滑动 requestAnimationFrame 大幅减少时间计数
function end(){ var self=this, stopFlag=null; function sliderMove(){ if(Math.abs(iSpeedX)<=1||self.offsetLeft>50||self.offsetLeft<maxDistance-50){ if(self.offsetLeft>=0){ $(inner).animate({left:0},300,function(){ self.classList.remove('translateZ'); //移除PGU hack }); } if(self.offsetLeft<maxDistance){ $(inner).animate({left:maxDistance+'px'},300,function(){ self.classList.remove('translateZ'); //移除PGU hack }); } window.cancelAnimationFrame(stopFlag);//可以取消该次动画 stopFlag=null; sliderMove=null; //清空对象 console.log('requestAnimationFramessss'+sliderMove); }else{ iSpeedX *= 0.95; self.style.left = parseInt(self.offsetLeft + iSpeedX) + 'px'; console.log('滑动时候requestAnimationFrame次数'); stopFlag=requestAnimationFrame(arguments.callee); } } sliderMove(); self.removeEventListener("touchmove",move,false); self.removeEventListener("touchend",end,false); //self.style.webkitTransform=''; }
requestAnimationFrame兼容处理:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | ;( function () { var lastTime = 0; var vendors = [ 'ms' , 'moz' , 'webkit' , 'o' ]; for ( var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame' ]; window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame' ] || window[vendors[x] + 'CancelRequestAnimationFrame' ]; } if (!window.requestAnimationFrame) window.requestAnimationFrame = function (callback, element) { var currTime = new Date().getTime(); var timeToCall = Math.max(0, 16 - (currTime - lastTime)); var id = window.setTimeout( function () { callback(currTime + timeToCall); }, timeToCall); lastTime = currTime + timeToCall; return id; }; if (!window.cancelAnimationFrame) window.cancelAnimationFrame = function (id) { clearTimeout(id); }; }()); // requestAnimationFrame polyfill by Erik Möller. // Fixes from Paul Irish, Tino Zijdel, Andrew Mao, Klemen Slavič, Darius Bacon // MIT license if (!Date.now) Date.now = function () { return new Date().getTime(); }; ( function () { 'use strict' ; var vendors = [ 'webkit' , 'moz' ]; for ( var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i) { var vp = vendors[i]; window.requestAnimationFrame = window[vp+ 'RequestAnimationFrame' ]; window.cancelAnimationFrame = (window[vp+ 'CancelAnimationFrame' ] || window[vp+ 'CancelRequestAnimationFrame' ]); } if (/iP(ad|hone|od).*OS 6/.test(window.navigator.userAgent) // iOS6 is buggy || !window.requestAnimationFrame || !window.cancelAnimationFrame) { var lastTime = 0; window.requestAnimationFrame = function (callback) { var now = Date.now(); var nextTime = Math.max(lastTime + 16, now); return setTimeout( function () { callback(lastTime = nextTime); }, nextTime - now); }; window.cancelAnimationFrame = clearTimeout; } }()); |
其他问题 用户误触, css3持续时间 translate位移性能, touchmove 以及快速滑动 gpu的 合理调度
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | $(document).ready( function (e) { function getStyle(obj,attr){ return obj.currentStyle? obj.currentStyle[attr]:getComputedStyle(obj, false )[attr]; } var support = document.body.classList==undefined ? false : true ; var outer=document.getElementById( "outer" ); var inner=document.getElementById( "inner" ); var li=inner.getElementsByTagName( "li" ); var innerWd=0,i=0; for (;i<li.length;i++){ innerWd+=li[i].offsetWidth; } inner.style.width=innerWd+ 'px' ; var startX=0; var alls=0; var moveLeft=0; var iSpeedX = 0; var prevX = 0; var timer = null ; var resetStartX= true ; var maxDistance=parseInt(outer.offsetWidth-innerWd); //最大滑动距离 var stopFlag= null ; inner.addEventListener( "touchstart" ,start, false ); function start(e){ if (inner.offsetWidth<outer.offsetWidth) return ; //如果内部元素小于外框 不需要滑动 var e=e||window.event; e.preventDefault(); var touchs=e.touches[0]; resetStartX= true ;; //startX=prevX=touchs.pageX; startX=touchs.pageX; prevX=touchs.pageX; alls= this .offsetLeft; inner.classList.add( 'translateZ' ); //classList 对已经增加的样式 不在判断是否添加 GPU缓存hack inner.addEventListener( "touchmove" ,move, false ); inner.addEventListener( "touchend" ,end, false ); } function move(e){ var e=e||window.event; e.preventDefault(); if (e.touches.length > 1 || e.scale && e.scale !== 1) return ; // 当屏幕有多个touch或者页面被缩放过,就不执行move操作 var touchs=e.changedTouches[0]; iSpeedX = touchs.pageX - prevX; //获取出手一瞬间的速度 prevX = touchs.pageX; //当前的始终覆盖上一个 moveLeft=touchs.pageX-startX; var that= this ; if (that.offsetLeft>=0){ if (resetStartX){ startX=touchs.pageX; resetStartX= false ; } var topNum=(touchs.pageX - startX)/3; that.style.left =topNum + 'px' ; } else if (that.offsetLeft<=maxDistance){ if (resetStartX){ startX=touchs.pageX; resetStartX= false ; } var midNum= (touchs.pageX - startX)/3 + (maxDistance); that.style.left = midNum+ 'px' ; } else { var botNum=touchs.pageX - startX + alls; that.style.left =botNum + 'px' ; } //this.style.webkitTransform='translateZ(0)'; //移动时候 缓存到GPU层 } function end(e){ var e=e||window.event; e.preventDefault(); var self= this ; var touchs=e.changedTouches[0]; var minDis= touchs.pageX-startX; function sliderMove(){ if (Math.abs(iSpeedX)<=1||self.offsetLeft>50||self.offsetLeft<maxDistance-50){ if (self.offsetLeft>=0){ console.log( 'llllllllllllllll' ); $(inner).animate({left:0},300, function (){ self.classList.remove( 'translateZ' ); //移除PGU hack }); } if (self.offsetLeft<maxDistance){ $(inner).animate({left:maxDistance+ 'px' },300, function (){ self.classList.remove( 'translateZ' ); //移除PGU hack }); } window.cancelAnimationFrame(stopFlag); //可以取消该次动画 stopFlag= null ; sliderMove= null ; //清空对象 console.log( 'requestAnimationFramessss' +sliderMove); } else { iSpeedX *= 0.95; self.style.left = parseInt(self.offsetLeft + iSpeedX) + 'px' ; console.log( '滑动时候requestAnimationFrame次数' ); stopFlag=requestAnimationFrame(arguments.callee); } } if (Math.abs(minDis)>5) { //减少tap时候 bug 有时候轻轻一碰带来的问题 用户事项tap 时候 sliderMove(); } self.removeEventListener( "touchmove" ,move, false ); self.removeEventListener( "touchend" ,end, false ); //self.style.webkitTransform=''; } //} }); |
1 | 其他参考 <br>better-scroll |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 | /*! * better-scroll / better-scroll * (c) 2016-2023 ustbhuangyi * Released under the MIT License. */ ( function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define([ 'exports' ], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.BetterScroll = {})); })( this , ( function (exports) { 'use strict' ; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for ( var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { extendStatics(d, b); function __() { this .constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } var __assign = function () { __assign = Object.assign || function __assign(t) { for ( var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for ( var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply( this , arguments); }; function __awaiter(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P( function (resolve) { resolve(value); }); } return new (P || (P = Promise))( function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator[ "throw" ](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } function __generator(thisArg, body) { var _ = { label: 0, sent: function () { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw" : verb(1), "return" : verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this ; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError( "Generator is already executing." ); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y[ "return" ] : op[0] ? y[ "throw" ] || ((t = y[ "return" ]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break ; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue ; case 7: op = _.ops.pop(); _.trys.pop(); continue ; default : if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue ; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break ; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break ; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break ; } if (t[2]) _.ops.pop(); _.trys.pop(); continue ; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } } function __spreadArrays() { for ( var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; for ( var r = Array(s), k = 0, i = 0; i < il; i++) for ( var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; return r; } var propertiesConfig$7 = [ { 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 warn(msg) { console.error( "[BScroll warn]: " + msg); } function assert(condition, msg) { if (!condition) { throw new Error( '[BScroll] ' + msg); } } // ssr support var inBrowser = typeof window !== 'undefined' ; var ua = inBrowser && navigator.userAgent.toLowerCase(); var isWeChatDevTools = !!(ua && /wechatdevtools/.test(ua)); var isAndroid = ua && ua.indexOf( 'android' ) > 0; /* istanbul ignore next */ var isIOSBadVersion = ( function () { if ( typeof ua === 'string' ) { var regex = /os (\d\d?_\d(_\d)?)/; var matches = regex.exec(ua); if (!matches) return false ; var parts = matches[1].split( '_' ).map( function (item) { return parseInt(item, 10); }); // ios version >= 13.4 issue 982 return !!(parts[0] === 13 && parts[1] >= 4); } return false ; })(); /* istanbul ignore next */ var supportsPassive = false ; /* istanbul ignore next */ if (inBrowser) { var EventName = 'test-passive' ; try { var opts = {}; Object.defineProperty(opts, 'passive' , { get: function () { supportsPassive = true ; }, }); // https://github.com/facebook/flow/issues/285 window.addEventListener(EventName, function () { }, opts); } catch (e) { } } function getNow() { return window.performance && window.performance.now && window.performance.timing ? window.performance.now() + window.performance.timing.navigationStart : + new Date(); } var extend = function (target, source) { for ( var key in source) { target[key] = source[key]; } return target; }; function isUndef(v) { return v === undefined || v === null ; } function getDistance(x, y) { return Math.sqrt(x * x + y * y); } function between(x, min, max) { if (x < min) { return min; } if (x > max) { return max; } return x; } function findIndex(ary, fn) { if (ary.findIndex) { return ary.findIndex(fn); } var index = -1; ary.some( function (item, i, ary) { var ret = fn(item, i, ary); if (ret) { index = i; return ret; } }); return index; } var elementStyle = (inBrowser && document.createElement( 'div' ).style); var vendor = ( function () { /* istanbul ignore if */ if (!inBrowser) { return false ; } var transformNames = [ { key: 'standard' , value: 'transform' , }, { key: 'webkit' , value: 'webkitTransform' , }, { key: 'Moz' , value: 'MozTransform' , }, { key: 'O' , value: 'OTransform' , }, { key: 'ms' , value: 'msTransform' , }, ]; for ( var _i = 0, transformNames_1 = transformNames; _i < transformNames_1.length; _i++) { var obj = transformNames_1[_i]; if (elementStyle[obj.value] !== undefined) { return obj.key; } } /* istanbul ignore next */ return false ; })(); /* istanbul ignore next */ function prefixStyle(style) { if (vendor === false ) { return style; } if (vendor === 'standard' ) { if (style === 'transitionEnd' ) { return 'transitionend' ; } return style; } return vendor + style.charAt(0).toUpperCase() + style.substr(1); } function getElement(el) { return ( typeof el === 'string' ? document.querySelector(el) : el); } function addEvent(el, type, fn, capture) { var useCapture = supportsPassive ? { passive: false , capture: !!capture, } : !!capture; el.addEventListener(type, fn, useCapture); } function removeEvent(el, type, fn, capture) { el.removeEventListener(type, fn, { capture: !!capture, }); } function maybePrevent(e) { if (e.cancelable) { e.preventDefault(); } } function offset(el) { var left = 0; var top = 0; while (el) { left -= el.offsetLeft; top -= el.offsetTop; el = el.offsetParent; } return { left: left, top: top, }; } function offsetToBody(el) { var rect = el.getBoundingClientRect(); return { left: -(rect.left + window.pageXOffset), top: -(rect.top + window.pageYOffset), }; } var cssVendor = vendor && vendor !== 'standard' ? '-' + vendor.toLowerCase() + '-' : '' ; var transform = prefixStyle( 'transform' ); var transition = prefixStyle( 'transition' ); var hasPerspective = inBrowser && prefixStyle( 'perspective' ) in elementStyle; // fix issue #361 var hasTouch = inBrowser && ( 'ontouchstart' in window || isWeChatDevTools); var hasTransition = inBrowser && transition in elementStyle; var style = { transform: transform, transition: transition, transitionTimingFunction: prefixStyle( 'transitionTimingFunction' ), transitionDuration: prefixStyle( 'transitionDuration' ), transitionDelay: prefixStyle( 'transitionDelay' ), transformOrigin: prefixStyle( 'transformOrigin' ), transitionEnd: prefixStyle( 'transitionEnd' ), transitionProperty: prefixStyle( 'transitionProperty' ), }; var eventTypeMap = { touchstart: 1, touchmove: 1, touchend: 1, touchcancel: 1, mousedown: 2, mousemove: 2, mouseup: 2, }; function getRect(el) { /* istanbul ignore if */ if (el instanceof window.SVGElement) { var rect = el.getBoundingClientRect(); return { top: rect.top, left: rect.left, width: rect.width, height: rect.height, }; } else { return { top: el.offsetTop, left: el.offsetLeft, width: el.offsetWidth, height: el.offsetHeight, }; } } function preventDefaultExceptionFn(el, exceptions) { for ( var i in exceptions) { if (exceptions[i].test(el[i])) { return true ; } } return false ; } var tagExceptionFn = preventDefaultExceptionFn; function tap(e, eventName) { var ev = document.createEvent( 'Event' ); ev.initEvent(eventName, true , true ); ev.pageX = e.pageX; ev.pageY = e.pageY; e.target.dispatchEvent(ev); } function click(e, event) { if (event === void 0) { event = 'click' ; } var eventSource; if (e.type === 'mouseup' ) { eventSource = e; } else if (e.type === 'touchend' || e.type === 'touchcancel' ) { eventSource = e.changedTouches[0]; } var posSrc = {}; if (eventSource) { posSrc.screenX = eventSource.screenX || 0; posSrc.screenY = eventSource.screenY || 0; posSrc.clientX = eventSource.clientX || 0; posSrc.clientY = eventSource.clientY || 0; } var ev; var bubbles = true ; var cancelable = true ; var ctrlKey = e.ctrlKey, shiftKey = e.shiftKey, altKey = e.altKey, metaKey = e.metaKey; var pressedKeysMap = { ctrlKey: ctrlKey, shiftKey: shiftKey, altKey: altKey, metaKey: metaKey, }; if ( typeof MouseEvent !== 'undefined' ) { try { ev = new MouseEvent(event, extend(__assign({ bubbles: bubbles, cancelable: cancelable }, pressedKeysMap), posSrc)); } catch (e) { /* istanbul ignore next */ createEvent(); } } else { createEvent(); } function createEvent() { ev = document.createEvent( 'Event' ); ev.initEvent(event, bubbles, cancelable); extend(ev, posSrc); } // forwardedTouchEvent set to true in case of the conflict with fastclick ev.forwardedTouchEvent = true ; ev._constructed = true ; e.target.dispatchEvent(ev); } function dblclick(e) { click(e, 'dblclick' ); } function prepend(el, target) { var firstChild = target.firstChild; if (firstChild) { before(el, firstChild); } else { target.appendChild(el); } } function before(el, target) { var parentNode = target.parentNode; parentNode.insertBefore(el, target); } function removeChild(el, child) { el.removeChild(child); } function hasClass(el, className) { var reg = new RegExp( '(^|\\s)' + className + '(\\s|$)' ); return reg.test(el.className); } function HTMLCollectionToArray(el) { return Array.prototype.slice.call(el, 0); } function getClientSize(el) { return { width: el.clientWidth, height: el.clientHeight, }; } var ease = { // easeOutQuint swipe: { style: 'cubic-bezier(0.23, 1, 0.32, 1)' , fn: function (t) { return 1 + --t * t * t * t * t; } }, // easeOutQuard swipeBounce: { style: 'cubic-bezier(0.25, 0.46, 0.45, 0.94)' , fn: function (t) { return t * (2 - t); } }, // easeOutQuart bounce: { style: 'cubic-bezier(0.165, 0.84, 0.44, 1)' , fn: function (t) { return 1 - --t * t * t * t; } } }; var DEFAULT_INTERVAL = 1000 / 60; var windowCompat = inBrowser && window; /* istanbul ignore next */ function noop$1() { } var requestAnimationFrame = ( function () { /* istanbul ignore if */ if (!inBrowser) { return noop$1; } return (windowCompat.requestAnimationFrame || windowCompat.webkitRequestAnimationFrame || windowCompat.mozRequestAnimationFrame || windowCompat.oRequestAnimationFrame || // if all else fails, use setTimeout function (callback) { return window.setTimeout(callback, callback.interval || DEFAULT_INTERVAL); // make interval as precise as possible. }); })(); var cancelAnimationFrame = ( function () { /* istanbul ignore if */ if (!inBrowser) { return noop$1; } return (windowCompat.cancelAnimationFrame || windowCompat.webkitCancelAnimationFrame || windowCompat.mozCancelAnimationFrame || windowCompat.oCancelAnimationFrame || function (id) { window.clearTimeout(id); }); })(); /* istanbul ignore next */ var noop = function (val) { }; var sharedPropertyDefinition = { enumerable: true , configurable: true , get: noop, set: noop, }; var getProperty = function (obj, key) { var keys = key.split( '.' ); for ( var i = 0; i < keys.length - 1; i++) { obj = obj[keys[i]]; if ( typeof obj !== 'object' || !obj) return ; } var lastKey = keys.pop(); if ( typeof obj[lastKey] === 'function' ) { return function () { return obj[lastKey].apply(obj, arguments); }; } else { return obj[lastKey]; } }; var setProperty = function (obj, key, value) { var keys = key.split( '.' ); var temp; for ( var i = 0; i < keys.length - 1; i++) { temp = keys[i]; if (!obj[temp]) obj[temp] = {}; obj = obj[temp]; } obj[keys.pop()] = value; }; function propertiesProxy(target, sourceKey, key) { sharedPropertyDefinition.get = function proxyGetter() { return getProperty( this , sourceKey); }; sharedPropertyDefinition.set = function proxySetter(val) { setProperty( this , sourceKey, val); }; Object.defineProperty(target, key, sharedPropertyDefinition); } var EventEmitter = /** @class */ ( function () { function EventEmitter(names) { this .events = {}; this .eventTypes = {}; this .registerType(names); } EventEmitter.prototype.on = function (type, fn, context) { if (context === void 0) { context = this ; } this .hasType(type); if (! this .events[type]) { this .events[type] = []; } this .events[type].push([fn, context]); return this ; }; EventEmitter.prototype.once = function (type, fn, context) { var _this = this ; if (context === void 0) { context = this ; } this .hasType(type); var magic = function () { var args = []; for ( var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } _this.off(type, magic); var ret = fn.apply(context, args); if (ret === true ) { return ret; } }; magic.fn = fn; this .on(type, magic); return this ; }; EventEmitter.prototype.off = function (type, fn) { if (!type && !fn) { this .events = {}; return this ; } if (type) { this .hasType(type); if (!fn) { this .events[type] = []; return this ; } var events = this .events[type]; if (!events) { return this ; } var count = events.length; while (count--) { if (events[count][0] === fn || (events[count][0] && events[count][0].fn === fn)) { events.splice(count, 1); } } return this ; } }; EventEmitter.prototype.trigger = function (type) { var args = []; for ( var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } this .hasType(type); var events = this .events[type]; if (!events) { return ; } var len = events.length; var eventsCopy = __spreadArrays(events); var ret; for ( var i = 0; i < len; i++) { var event_1 = eventsCopy[i]; var fn = event_1[0], context = event_1[1]; if (fn) { ret = fn.apply(context, args); if (ret === true ) { return ret; } } } }; EventEmitter.prototype.registerType = function (names) { var _this = this ; names.forEach( function (type) { _this.eventTypes[type] = type; }); }; EventEmitter.prototype.destroy = function () { this .events = {}; this .eventTypes = {}; }; EventEmitter.prototype.hasType = function (type) { var types = this .eventTypes; var isType = types[type] === type; if (!isType) { warn( "EventEmitter has used unknown event type: \"" + type + "\", should be oneof [" + ( "" + Object.keys(types).map( function (_) { return JSON.stringify(_); })) + "]" ); } }; return EventEmitter; }()); var EventRegister = /** @class */ ( function () { function EventRegister(wrapper, events) { this .wrapper = wrapper; this .events = events; this .addDOMEvents(); } EventRegister.prototype.destroy = function () { this .removeDOMEvents(); this .events = []; }; EventRegister.prototype.addDOMEvents = function () { this .handleDOMEvents(addEvent); }; EventRegister.prototype.removeDOMEvents = function () { this .handleDOMEvents(removeEvent); }; EventRegister.prototype.handleDOMEvents = function (eventOperation) { var _this = this ; var wrapper = this .wrapper; this .events.forEach( function (event) { eventOperation(wrapper, event.name, _this, !!event.capture); }); }; EventRegister.prototype.handleEvent = function (e) { var eventType = e.type; this .events.some( function (event) { if (event.name === eventType) { event.handler(e); return true ; } return false ; }); }; return EventRegister; }()); var CustomOptions = /** @class */ ( function () { function CustomOptions() { } return CustomOptions; }()); var OptionsConstructor = /** @class */ ( function (_super) { __extends(OptionsConstructor, _super); function OptionsConstructor() { var _this = _super.call( this ) || this ; _this.startX = 0; _this.startY = 0; _this.scrollX = false ; _this.scrollY = true ; _this.freeScroll = false ; _this.directionLockThreshold = 0; _this.eventPassthrough = "" /* None */ ; _this.click = false ; _this.dblclick = false ; _this.tap = '' ; _this.bounce = { top: true , bottom: true , left: true , right: true , }; _this.bounceTime = 800; _this.momentum = true ; _this.momentumLimitTime = 300; _this.momentumLimitDistance = 15; _this.swipeTime = 2500; _this.swipeBounceTime = 500; _this.deceleration = 0.0015; _this.flickLimitTime = 200; _this.flickLimitDistance = 100; _this.resizePolling = 60; _this.probeType = 0 /* Default */ ; _this.stopPropagation = false ; _this.preventDefault = true ; _this.preventDefaultException = { tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT|AUDIO)$/, }; _this.tagException = { tagName: /^TEXTAREA$/, }; _this.HWCompositing = true ; _this.useTransition = true ; _this.bindToWrapper = false ; _this.bindToTarget = false ; _this.disableMouse = hasTouch; _this.disableTouch = !hasTouch; _this.autoBlur = true ; _this.autoEndDistance = 5; _this.outOfBoundaryDampingFactor = 1 / 3; _this.specifiedIndexAsContent = 0; _this.quadrant = 1 /* First */ ; return _this; } OptionsConstructor.prototype.merge = function (options) { if (!options) return this ; for ( var key in options) { if (key === 'bounce' ) { this .bounce = this .resolveBounce(options[key]); continue ; } this [key] = options[key]; } return this ; }; OptionsConstructor.prototype.process = function () { this .translateZ = this .HWCompositing && hasPerspective ? ' translateZ(1px)' : '' ; this .useTransition = this .useTransition && hasTransition; this .preventDefault = ! this .eventPassthrough && this .preventDefault; // If you want eventPassthrough I have to lock one of the axes this .scrollX = this .eventPassthrough === "horizontal" /* Horizontal */ ? false : this .scrollX; this .scrollY = this .eventPassthrough === "vertical" /* Vertical */ ? false : this .scrollY; // With eventPassthrough we also need lockDirection mechanism this .freeScroll = this .freeScroll && ! this .eventPassthrough; // force true when freeScroll is true this .scrollX = this .freeScroll ? true : this .scrollX; this .scrollY = this .freeScroll ? true : this .scrollY; this .directionLockThreshold = this .eventPassthrough ? 0 : this .directionLockThreshold; return this ; }; OptionsConstructor.prototype.resolveBounce = function (bounceOptions) { var DEFAULT_BOUNCE = { top: true , right: true , bottom: true , left: true , }; var NEGATED_BOUNCE = { top: false , right: false , bottom: false , left: false , }; var ret; if ( typeof bounceOptions === 'object' ) { ret = extend(DEFAULT_BOUNCE, bounceOptions); } else { ret = bounceOptions ? DEFAULT_BOUNCE : NEGATED_BOUNCE; } return ret; }; return OptionsConstructor; }(CustomOptions)); var ActionsHandler = /** @class */ ( function () { function ActionsHandler(wrapper, options) { this .wrapper = wrapper; this .options = options; this .hooks = new EventEmitter([ 'beforeStart' , 'start' , 'move' , 'end' , 'click' , ]); this .handleDOMEvents(); } ActionsHandler.prototype.handleDOMEvents = function () { var _a = this .options, bindToWrapper = _a.bindToWrapper, disableMouse = _a.disableMouse, disableTouch = _a.disableTouch, click = _a.click; var wrapper = this .wrapper; var target = bindToWrapper ? wrapper : window; var wrapperEvents = []; var targetEvents = []; var shouldRegisterTouch = !disableTouch; var shouldRegisterMouse = !disableMouse; if (click) { wrapperEvents.push({ name: 'click' , handler: this .click.bind( this ), capture: true , }); } if (shouldRegisterTouch) { wrapperEvents.push({ name: 'touchstart' , handler: this .start.bind( this ), }); targetEvents.push({ name: 'touchmove' , handler: this .move.bind( this ), }, { name: 'touchend' , handler: this .end.bind( this ), }, { name: 'touchcancel' , handler: this .end.bind( this ), }); } if (shouldRegisterMouse) { wrapperEvents.push({ name: 'mousedown' , handler: this .start.bind( this ), }); targetEvents.push({ name: 'mousemove' , handler: this .move.bind( this ), }, { name: 'mouseup' , handler: this .end.bind( this ), }); } this .wrapperEventRegister = new EventRegister(wrapper, wrapperEvents); this .targetEventRegister = new EventRegister(target, targetEvents); }; ActionsHandler.prototype.beforeHandler = function (e, type) { var _a = this .options, preventDefault = _a.preventDefault, stopPropagation = _a.stopPropagation, preventDefaultException = _a.preventDefaultException; var preventDefaultConditions = { start: function () { return (preventDefault && !preventDefaultExceptionFn(e.target, preventDefaultException)); }, end: function () { return (preventDefault && !preventDefaultExceptionFn(e.target, preventDefaultException)); }, move: function () { return preventDefault; }, }; if (preventDefaultConditions[type]()) { e.preventDefault(); } if (stopPropagation) { e.stopPropagation(); } }; ActionsHandler.prototype.setInitiated = function (type) { if (type === void 0) { type = 0; } this .initiated = type; }; ActionsHandler.prototype.start = function (e) { var _eventType = eventTypeMap[e.type]; if ( this .initiated && this .initiated !== _eventType) { return ; } this .setInitiated(_eventType); // if textarea or other html tags in options.tagException is manipulated // do not make bs scroll if (tagExceptionFn(e.target, this .options.tagException)) { this .setInitiated(); return ; } // only allow mouse left button if (_eventType === 2 /* Mouse */ && e.button !== 0 /* Left */ ) return ; if ( this .hooks.trigger( this .hooks.eventTypes.beforeStart, e)) { return ; } this .beforeHandler(e, 'start' ); var point = (e.touches ? e.touches[0] : e); this .pointX = point.pageX; this .pointY = point.pageY; this .hooks.trigger( this .hooks.eventTypes.start, e); }; ActionsHandler.prototype.move = function (e) { if (eventTypeMap[e.type] !== this .initiated) { return ; } this .beforeHandler(e, 'move' ); var point = (e.touches ? e.touches[0] : e); var deltaX = point.pageX - this .pointX; var deltaY = point.pageY - this .pointY; this .pointX = point.pageX; this .pointY = point.pageY; if ( this .hooks.trigger( this .hooks.eventTypes.move, { deltaX: deltaX, deltaY: deltaY, e: e, })) { return ; } // auto end when out of viewport var scrollLeft = document.documentElement.scrollLeft || window.pageXOffset || document.body.scrollLeft; var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop; var pX = this .pointX - scrollLeft; var pY = this .pointY - scrollTop; var autoEndDistance = this .options.autoEndDistance; if (pX > document.documentElement.clientWidth - autoEndDistance || pY > document.documentElement.clientHeight - autoEndDistance || pX < autoEndDistance || pY < autoEndDistance) { this .end(e); } }; ActionsHandler.prototype.end = function (e) { if (eventTypeMap[e.type] !== this .initiated) { return ; } this .setInitiated(); this .beforeHandler(e, 'end' ); this .hooks.trigger( this .hooks.eventTypes.end, e); }; ActionsHandler.prototype.click = function (e) { this .hooks.trigger( this .hooks.eventTypes.click, e); }; ActionsHandler.prototype.setContent = function (content) { if (content !== this .wrapper) { this .wrapper = content; this .rebindDOMEvents(); } }; ActionsHandler.prototype.rebindDOMEvents = function () { this .wrapperEventRegister.destroy(); this .targetEventRegister.destroy(); this .handleDOMEvents(); }; ActionsHandler.prototype.destroy = function () { this .wrapperEventRegister.destroy(); this .targetEventRegister.destroy(); this .hooks.destroy(); }; return ActionsHandler; }()); var translaterMetaData = { x: [ 'translateX' , 'px' ], y: [ 'translateY' , 'px' ], }; var Translater = /** @class */ ( function () { function Translater(content) { this .setContent(content); this .hooks = new EventEmitter([ 'beforeTranslate' , 'translate' ]); } Translater.prototype.getComputedPosition = function () { var cssStyle = window.getComputedStyle( this .content, null ); var matrix = cssStyle[style.transform].split( ')' )[0].split( ', ' ); var x = +(matrix[12] || matrix[4]) || 0; var y = +(matrix[13] || matrix[5]) || 0; return { x: x, y: y, }; }; Translater.prototype.translate = function (point) { var transformStyle = []; Object.keys(point).forEach( function (key) { if (!translaterMetaData[key]) { return ; } var transformFnName = translaterMetaData[key][0]; if (transformFnName) { var transformFnArgUnit = translaterMetaData[key][1]; var transformFnArg = point[key]; transformStyle.push(transformFnName + "(" + transformFnArg + transformFnArgUnit + ")" ); } }); this .hooks.trigger( this .hooks.eventTypes.beforeTranslate, transformStyle, point); this .style[style.transform] = transformStyle.join( ' ' ); this .hooks.trigger( this .hooks.eventTypes.translate, point); }; Translater.prototype.setContent = function (content) { if ( this .content !== content) { this .content = content; this .style = content.style; } }; Translater.prototype.destroy = function () { this .hooks.destroy(); }; return Translater; }()); var Base = /** @class */ ( function () { function Base(content, translater, options) { this .translater = translater; this .options = options; this .timer = 0; this .hooks = new EventEmitter([ 'move' , 'end' , 'beforeForceStop' , 'forceStop' , 'callStop' , 'time' , 'timeFunction' , ]); this .setContent(content); } Base.prototype.translate = function (endPoint) { this .translater.translate(endPoint); }; Base.prototype.setPending = function (pending) { this .pending = pending; }; Base.prototype.setForceStopped = function (forceStopped) { this .forceStopped = forceStopped; }; Base.prototype.setCallStop = function (called) { this .callStopWhenPending = called; }; Base.prototype.setContent = function (content) { if ( this .content !== content) { this .content = content; this .style = content.style; this .stop(); } }; Base.prototype.clearTimer = function () { if ( this .timer) { cancelAnimationFrame( this .timer); this .timer = 0; } }; Base.prototype.destroy = function () { this .hooks.destroy(); cancelAnimationFrame( this .timer); }; return Base; }()); // iOS 13.6 - 14.x, window.getComputedStyle sometimes will get wrong transform value // when bs use transition mode // eg: translateY -100px -> -200px, when the last frame which is about to scroll to -200px // window.getComputedStyle(this.content) will calculate transformY to be -100px(startPoint) // it is weird // so we should validate position caculated by 'window.getComputedStyle' var isValidPostion = function (startPoint, endPoint, currentPos, prePos) { var computeDirection = function (endValue, startValue) { var delta = endValue - startValue; var direction = delta > 0 ? -1 /* Negative */ : delta < 0 ? 1 /* Positive */ : 0 /* Default */ ; return direction; }; var directionX = computeDirection(endPoint.x, startPoint.x); var directionY = computeDirection(endPoint.y, startPoint.y); var deltaX = currentPos.x - prePos.x; var deltaY = currentPos.y - prePos.y; return directionX * deltaX <= 0 && directionY * deltaY <= 0; }; var Transition = /** @class */ ( function (_super) { __extends(Transition, _super); function Transition() { return _super !== null && _super.apply( this , arguments) || this ; } Transition.prototype.startProbe = function (startPoint, endPoint) { var _this = this ; var prePos = startPoint; var probe = function () { var pos = _this.translater.getComputedPosition(); if (isValidPostion(startPoint, endPoint, pos, prePos)) { _this.hooks.trigger(_this.hooks.eventTypes.move, pos); } // call bs.stop() should not dispatch end hook again. // forceStop hook will do this. /* istanbul ignore if */ if (!_this.pending) { if (_this.callStopWhenPending) { _this.callStopWhenPending = false ; } else { // transition ends should dispatch end hook. _this.hooks.trigger(_this.hooks.eventTypes.end, pos); } } prePos = pos; if (_this.pending) { _this.timer = requestAnimationFrame(probe); } }; // when manually call bs.stop(), then bs.scrollTo() // we should reset callStopWhenPending to dispatch end hook if ( this .callStopWhenPending) { this .setCallStop( false ); } cancelAnimationFrame( this .timer); probe(); }; Transition.prototype.transitionTime = function (time) { if (time === void 0) { time = 0; } this .style[style.transitionDuration] = time + 'ms' ; this .hooks.trigger( this .hooks.eventTypes.time, time); }; Transition.prototype.transitionTimingFunction = function (easing) { this .style[style.transitionTimingFunction] = easing; this .hooks.trigger( this .hooks.eventTypes.timeFunction, easing); }; Transition.prototype.transitionProperty = function () { this .style[style.transitionProperty] = style.transform; }; Transition.prototype.move = function (startPoint, endPoint, time, easingFn) { this .setPending(time > 0); this .transitionTimingFunction(easingFn); this .transitionProperty(); this .transitionTime(time); this .translate(endPoint); var isRealtimeProbeType = this .options.probeType === 3 /* Realtime */ ; if (time && isRealtimeProbeType) { this .startProbe(startPoint, endPoint); } // if we change content's transformY in a tick // such as: 0 -> 50px -> 0 // transitionend will not be triggered // so we forceupdate by reflow if (!time) { this ._reflow = this .content.offsetHeight; if (isRealtimeProbeType) { this .hooks.trigger( this .hooks.eventTypes.move, endPoint); } this .hooks.trigger( this .hooks.eventTypes.end, endPoint); } }; Transition.prototype.doStop = function () { var pending = this .pending; this .setForceStopped( false ); this .setCallStop( false ); // still in transition if (pending) { this .setPending( false ); cancelAnimationFrame( this .timer); var _a = this .translater.getComputedPosition(), x = _a.x, y = _a.y; this .transitionTime(); this .translate({ x: x, y: y }); this .setForceStopped( true ); this .setCallStop( true ); this .hooks.trigger( this .hooks.eventTypes.forceStop, { x: x, y: y }); } return pending; }; Transition.prototype.stop = function () { var stopFromTransition = this .doStop(); if (stopFromTransition) { this .hooks.trigger( this .hooks.eventTypes.callStop); } }; return Transition; }(Base)); var Animation = /** @class */ ( function (_super) { __extends(Animation, _super); function Animation() { return _super !== null && _super.apply( this , arguments) || this ; } Animation.prototype.move = function (startPoint, endPoint, time, easingFn) { // time is 0 if (!time) { this .translate(endPoint); if ( this .options.probeType === 3 /* Realtime */ ) { this .hooks.trigger( this .hooks.eventTypes.move, endPoint); } this .hooks.trigger( this .hooks.eventTypes.end, endPoint); return ; } this .animate(startPoint, endPoint, time, easingFn); }; Animation.prototype.animate = function (startPoint, endPoint, duration, easingFn) { var _this = this ; var startTime = getNow(); var destTime = startTime + duration; var isRealtimeProbeType = this .options.probeType === 3 /* Realtime */ ; var step = function () { var now = getNow(); // js animation end if (now >= destTime) { _this.translate(endPoint); if (isRealtimeProbeType) { _this.hooks.trigger(_this.hooks.eventTypes.move, endPoint); } _this.hooks.trigger(_this.hooks.eventTypes.end, endPoint); return ; } now = (now - startTime) / duration; var easing = easingFn(now); var newPoint = {}; Object.keys(endPoint).forEach( function (key) { var startValue = startPoint[key]; var endValue = endPoint[key]; newPoint[key] = (endValue - startValue) * easing + startValue; }); _this.translate(newPoint); if (isRealtimeProbeType) { _this.hooks.trigger(_this.hooks.eventTypes.move, newPoint); } if (_this.pending) { _this.timer = requestAnimationFrame(step); } // call bs.stop() should not dispatch end hook again. // forceStop hook will do this. /* istanbul ignore if */ if (!_this.pending) { if (_this.callStopWhenPending) { _this.callStopWhenPending = false ; } else { // raf ends should dispatch end hook. _this.hooks.trigger(_this.hooks.eventTypes.end, endPoint); } } }; this .setPending( true ); // when manually call bs.stop(), then bs.scrollTo() // we should reset callStopWhenPending to dispatch end hook if ( this .callStopWhenPending) { this .setCallStop( false ); } cancelAnimationFrame( this .timer); step(); }; Animation.prototype.doStop = function () { var pending = this .pending; this .setForceStopped( false ); this .setCallStop( false ); // still in requestFrameAnimation if (pending) { this .setPending( false ); cancelAnimationFrame( this .timer); var pos = this .translater.getComputedPosition(); this .setForceStopped( true ); this .setCallStop( true ); this .hooks.trigger( this .hooks.eventTypes.forceStop, pos); } return pending; }; Animation.prototype.stop = function () { var stopFromAnimation = this .doStop(); if (stopFromAnimation) { this .hooks.trigger( this .hooks.eventTypes.callStop); } }; return Animation; }(Base)); function createAnimater(element, translater, options) { var useTransition = options.useTransition; var animaterOptions = {}; Object.defineProperty(animaterOptions, 'probeType ', { enumerable: true, configurable: false, get: function () { return options.probeType; }, }); if (useTransition) { return new Transition(element, translater, animaterOptions); } else { return new Animation(element, translater, animaterOptions); } } var Behavior = /** @class */ (function () { function Behavior(wrapper, content, options) { this.wrapper = wrapper; this.options = options; this.hooks = new EventEmitter([ ' beforeComputeBoundary ', ' computeBoundary ', ' momentum ', ' end ', ' ignoreHasScroll ' ]); this.refresh(content); } Behavior.prototype.start = function () { this.dist = 0; this.setMovingDirection(0 /* Default */); this.setDirection(0 /* Default */); }; Behavior.prototype.move = function (delta) { delta = this.hasScroll ? delta : 0; this.setMovingDirection(delta); return this.performDampingAlgorithm(delta, this.options.outOfBoundaryDampingFactor); }; Behavior.prototype.setMovingDirection = function (delta) { this.movingDirection = delta > 0 ? -1 /* Negative */ : delta < 0 ? 1 /* Positive */ : 0 /* Default */; }; Behavior.prototype.setDirection = function (delta) { this.direction = delta > 0 ? -1 /* Negative */ : delta < 0 ? 1 /* Positive */ : 0 /* Default */; }; Behavior.prototype.performDampingAlgorithm = function (delta, dampingFactor) { var newPos = this.currentPos + delta; // Slow down or stop if outside of the boundaries if (newPos > this.minScrollPos || newPos < this.maxScrollPos) { if ((newPos > this.minScrollPos && this.options.bounces[0]) || (newPos < this.maxScrollPos && this.options.bounces[1])) { newPos = this.currentPos + delta * dampingFactor; } else { newPos = newPos > this.minScrollPos ? this.minScrollPos : this.maxScrollPos; } } return newPos; }; Behavior.prototype.end = function (duration) { var momentumInfo = { duration: 0 }; var absDist = Math.abs(this.currentPos - this.startPos); // start momentum animation if needed if (this.options.momentum && duration < this.options.momentumLimitTime && absDist > this.options.momentumLimitDistance) { var wrapperSize = (this.direction === -1 /* Negative */ && this.options.bounces[0]) || (this.direction === 1 /* Positive */ && this.options.bounces[1]) ? this.wrapperSize : 0; momentumInfo = this.hasScroll ? this.momentum(this.currentPos, this.startPos, duration, this.maxScrollPos, this.minScrollPos, wrapperSize, this.options) : { destination: this.currentPos, duration: 0 }; } else { this.hooks.trigger(this.hooks.eventTypes.end, momentumInfo); } return momentumInfo; }; Behavior.prototype.momentum = function (current, start, time, lowerMargin, upperMargin, wrapperSize, options) { if (options === void 0) { options = this.options; } var distance = current - start; var speed = Math.abs(distance) / time; var deceleration = options.deceleration, swipeBounceTime = options.swipeBounceTime, swipeTime = options.swipeTime; var duration = Math.min(swipeTime, (speed * 2) / deceleration); var momentumData = { destination: current + ((speed * speed) / deceleration) * (distance < 0 ? -1 : 1), duration: duration, rate: 15 }; this.hooks.trigger(this.hooks.eventTypes.momentum, momentumData, distance); if (momentumData.destination < lowerMargin) { momentumData.destination = wrapperSize ? Math.max(lowerMargin - wrapperSize / 4, lowerMargin - (wrapperSize / momentumData.rate) * speed) : lowerMargin; momentumData.duration = swipeBounceTime; } else if (momentumData.destination > upperMargin) { momentumData.destination = wrapperSize ? Math.min(upperMargin + wrapperSize / 4, upperMargin + (wrapperSize / momentumData.rate) * speed) : upperMargin; momentumData.duration = swipeBounceTime; } momentumData.destination = Math.round(momentumData.destination); return momentumData; }; Behavior.prototype.updateDirection = function () { var absDist = this.currentPos - this.absStartPos; this.setDirection(absDist); }; Behavior.prototype.refresh = function (content) { var _a = this.options.rect, size = _a.size, position = _a.position; var isWrapperStatic = window.getComputedStyle(this.wrapper, null).position === ' static '; // Force reflow var wrapperRect = getRect(this.wrapper); // use client is more fair than offset this.wrapperSize = this.wrapper[size === ' width ' ? ' clientWidth ' : ' clientHeight ']; this.setContent(content); var contentRect = getRect(this.content); this.contentSize = contentRect[size]; this.relativeOffset = contentRect[position]; /* istanbul ignore if */ if (isWrapperStatic) { this.relativeOffset -= wrapperRect[position]; } this.computeBoundary(); this.setDirection(0 /* Default */); }; Behavior.prototype.setContent = function (content) { if (content !== this.content) { this.content = content; this.resetState(); } }; Behavior.prototype.resetState = function () { this.currentPos = 0; this.startPos = 0; this.dist = 0; this.setDirection(0 /* Default */); this.setMovingDirection(0 /* Default */); this.resetStartPos(); }; Behavior.prototype.computeBoundary = function () { this.hooks.trigger(this.hooks.eventTypes.beforeComputeBoundary); var boundary = { minScrollPos: 0, maxScrollPos: this.wrapperSize - this.contentSize }; if (boundary.maxScrollPos < 0) { boundary.maxScrollPos -= this.relativeOffset; if (this.options.specifiedIndexAsContent === 0) { boundary.minScrollPos = -this.relativeOffset; } } this.hooks.trigger(this.hooks.eventTypes.computeBoundary, boundary); this.minScrollPos = boundary.minScrollPos; this.maxScrollPos = boundary.maxScrollPos; this.hasScroll = this.options.scrollable && this.maxScrollPos < this.minScrollPos; if (!this.hasScroll && this.minScrollPos < this.maxScrollPos) { this.maxScrollPos = this.minScrollPos; this.contentSize = this.wrapperSize; } }; Behavior.prototype.updatePosition = function (pos) { this.currentPos = pos; }; Behavior.prototype.getCurrentPos = function () { return this.currentPos; }; Behavior.prototype.checkInBoundary = function () { var position = this.adjustPosition(this.currentPos); var inBoundary = position === this.getCurrentPos(); return { position: position, inBoundary: inBoundary }; }; // adjust position when out of boundary Behavior.prototype.adjustPosition = function (pos) { if (!this.hasScroll && !this.hooks.trigger(this.hooks.eventTypes.ignoreHasScroll)) { pos = this.minScrollPos; } else if (pos > this.minScrollPos) { pos = this.minScrollPos; } else if (pos < this.maxScrollPos) { pos = this.maxScrollPos; } return pos; }; Behavior.prototype.updateStartPos = function () { this.startPos = this.currentPos; }; Behavior.prototype.updateAbsStartPos = function () { this.absStartPos = this.currentPos; }; Behavior.prototype.resetStartPos = function () { this.updateStartPos(); this.updateAbsStartPos(); }; Behavior.prototype.getAbsDist = function (delta) { this.dist += delta; return Math.abs(this.dist); }; Behavior.prototype.destroy = function () { this.hooks.destroy(); }; return Behavior; }()); var _a, _b, _c, _d; var PassthroughHandlers = (_a = {}, _a["yes" /* Yes */] = function (e) { return true; }, _a["no" /* No */] = function (e) { maybePrevent(e); return false; }, _a); var DirectionMap = (_b = {}, _b["horizontal" /* Horizontal */] = (_c = {}, _c["yes" /* Yes */] = "horizontal" /* Horizontal */, _c["no" /* No */] = "vertical" /* Vertical */, _c), _b["vertical" /* Vertical */] = (_d = {}, _d["yes" /* Yes */] = "vertical" /* Vertical */, _d["no" /* No */] = "horizontal" /* Horizontal */, _d), _b); var DirectionLockAction = /** @class */ (function () { function DirectionLockAction(directionLockThreshold, freeScroll, eventPassthrough) { this.directionLockThreshold = directionLockThreshold; this.freeScroll = freeScroll; this.eventPassthrough = eventPassthrough; this.reset(); } DirectionLockAction.prototype.reset = function () { this.directionLocked = "" /* Default */; }; DirectionLockAction.prototype.checkMovingDirection = function (absDistX, absDistY, e) { this.computeDirectionLock(absDistX, absDistY); return this.handleEventPassthrough(e); }; DirectionLockAction.prototype.adjustDelta = function (deltaX, deltaY) { if (this.directionLocked === "horizontal" /* Horizontal */) { deltaY = 0; } else if (this.directionLocked === "vertical" /* Vertical */) { deltaX = 0; } return { deltaX: deltaX, deltaY: deltaY, }; }; DirectionLockAction.prototype.computeDirectionLock = function (absDistX, absDistY) { // If you are scrolling in one direction, lock it if (this.directionLocked === "" /* Default */ && !this.freeScroll) { if (absDistX > absDistY + this.directionLockThreshold) { this.directionLocked = "horizontal" /* Horizontal */; // lock horizontally } else if (absDistY >= absDistX + this.directionLockThreshold) { this.directionLocked = "vertical" /* Vertical */; // lock vertically } else { this.directionLocked = "none" /* None */; // no lock } } }; DirectionLockAction.prototype.handleEventPassthrough = function (e) { var handleMap = DirectionMap[this.directionLocked]; if (handleMap) { if (this.eventPassthrough === handleMap["yes" /* Yes */]) { return PassthroughHandlers["yes" /* Yes */](e); } else if (this.eventPassthrough === handleMap["no" /* No */]) { return PassthroughHandlers["no" /* No */](e); } } return false; }; return DirectionLockAction; }()); var applyQuadrantTransformation = function (deltaX, deltaY, quadrant) { if (quadrant === 2 /* Second */) { return [deltaY, -deltaX]; } else if (quadrant === 3 /* Third */) { return [-deltaX, -deltaY]; } else if (quadrant === 4 /* Forth */) { return [-deltaY, deltaX]; } else { return [deltaX, deltaY]; } }; var ScrollerActions = /** @class */ (function () { function ScrollerActions(scrollBehaviorX, scrollBehaviorY, actionsHandler, animater, options) { this.hooks = new EventEmitter([ ' start ', ' beforeMove ', ' scrollStart ', ' scroll ', ' beforeEnd ', ' end ', ' scrollEnd ', ' contentNotMoved ', ' detectMovingDirection ', ' coordinateTransformation ', ]); this.scrollBehaviorX = scrollBehaviorX; this.scrollBehaviorY = scrollBehaviorY; this.actionsHandler = actionsHandler; this.animater = animater; this.options = options; this.directionLockAction = new DirectionLockAction(options.directionLockThreshold, options.freeScroll, options.eventPassthrough); this.enabled = true; this.bindActionsHandler(); } ScrollerActions.prototype.bindActionsHandler = function () { var _this = this; // [mouse|touch]start event this.actionsHandler.hooks.on(this.actionsHandler.hooks.eventTypes.start, function (e) { if (!_this.enabled) return true; return _this.handleStart(e); }); // [mouse|touch]move event this.actionsHandler.hooks.on(this.actionsHandler.hooks.eventTypes.move, function (_a) { var deltaX = _a.deltaX, deltaY = _a.deltaY, e = _a.e; if (!_this.enabled) return true; var _b = applyQuadrantTransformation(deltaX, deltaY, _this.options.quadrant), transformateDeltaX = _b[0], transformateDeltaY = _b[1]; var transformateDeltaData = { deltaX: transformateDeltaX, deltaY: transformateDeltaY, }; _this.hooks.trigger(_this.hooks.eventTypes.coordinateTransformation, transformateDeltaData); return _this.handleMove(transformateDeltaData.deltaX, transformateDeltaData.deltaY, e); }); // [mouse|touch]end event this.actionsHandler.hooks.on(this.actionsHandler.hooks.eventTypes.end, function (e) { if (!_this.enabled) return true; return _this.handleEnd(e); }); // click this.actionsHandler.hooks.on(this.actionsHandler.hooks.eventTypes.click, function (e) { // handle native click event if (_this.enabled && !e._constructed) { _this.handleClick(e); } }); }; ScrollerActions.prototype.handleStart = function (e) { var timestamp = getNow(); this.fingerMoved = false; this.contentMoved = false; this.startTime = timestamp; this.directionLockAction.reset(); this.scrollBehaviorX.start(); this.scrollBehaviorY.start(); // force stopping last transition or animation this.animater.doStop(); this.scrollBehaviorX.resetStartPos(); this.scrollBehaviorY.resetStartPos(); this.hooks.trigger(this.hooks.eventTypes.start, e); }; ScrollerActions.prototype.handleMove = function (deltaX, deltaY, e) { if (this.hooks.trigger(this.hooks.eventTypes.beforeMove, e)) { return; } var absDistX = this.scrollBehaviorX.getAbsDist(deltaX); var absDistY = this.scrollBehaviorY.getAbsDist(deltaY); var timestamp = getNow(); // We need to move at least momentumLimitDistance pixels // for the scrolling to initiate if (this.checkMomentum(absDistX, absDistY, timestamp)) { return true; } if (this.directionLockAction.checkMovingDirection(absDistX, absDistY, e)) { this.actionsHandler.setInitiated(); return true; } var delta = this.directionLockAction.adjustDelta(deltaX, deltaY); var prevX = this.scrollBehaviorX.getCurrentPos(); var newX = this.scrollBehaviorX.move(delta.deltaX); var prevY = this.scrollBehaviorY.getCurrentPos(); var newY = this.scrollBehaviorY.move(delta.deltaY); if (this.hooks.trigger(this.hooks.eventTypes.detectMovingDirection)) { return; } if (!this.fingerMoved) { this.fingerMoved = true; } var positionChanged = newX !== prevX || newY !== prevY; if (!this.contentMoved && !positionChanged) { this.hooks.trigger(this.hooks.eventTypes.contentNotMoved); } if (!this.contentMoved && positionChanged) { this.contentMoved = true; this.hooks.trigger(this.hooks.eventTypes.scrollStart); } if (this.contentMoved && positionChanged) { this.animater.translate({ x: newX, y: newY, }); this.dispatchScroll(timestamp); } }; ScrollerActions.prototype.dispatchScroll = function (timestamp) { // dispatch scroll in interval time if (timestamp - this.startTime > this.options.momentumLimitTime) { // refresh time and starting position to initiate a momentum this.startTime = timestamp; this.scrollBehaviorX.updateStartPos(); this.scrollBehaviorY.updateStartPos(); if (this.options.probeType === 1 /* Throttle */) { this.hooks.trigger(this.hooks.eventTypes.scroll, this.getCurrentPos()); } } // dispatch scroll all the time if (this.options.probeType > 1 /* Throttle */) { this.hooks.trigger(this.hooks.eventTypes.scroll, this.getCurrentPos()); } }; ScrollerActions.prototype.checkMomentum = function (absDistX, absDistY, timestamp) { return (timestamp - this.endTime > this.options.momentumLimitTime && absDistY < this.options.momentumLimitDistance && absDistX < this.options.momentumLimitDistance); }; ScrollerActions.prototype.handleEnd = function (e) { if (this.hooks.trigger(this.hooks.eventTypes.beforeEnd, e)) { return; } var currentPos = this.getCurrentPos(); this.scrollBehaviorX.updateDirection(); this.scrollBehaviorY.updateDirection(); if (this.hooks.trigger(this.hooks.eventTypes.end, e, currentPos)) { return true; } currentPos = this.ensureIntegerPos(currentPos); this.animater.translate(currentPos); this.endTime = getNow(); var duration = this.endTime - this.startTime; this.hooks.trigger(this.hooks.eventTypes.scrollEnd, currentPos, duration); }; ScrollerActions.prototype.ensureIntegerPos = function (currentPos) { this.ensuringInteger = true; var x = currentPos.x, y = currentPos.y; var _a = this.scrollBehaviorX, minScrollPosX = _a.minScrollPos, maxScrollPosX = _a.maxScrollPos; var _b = this.scrollBehaviorY, minScrollPosY = _b.minScrollPos, maxScrollPosY = _b.maxScrollPos; x = x > 0 ? Math.ceil(x) : Math.floor(x); y = y > 0 ? Math.ceil(y) : Math.floor(y); x = between(x, maxScrollPosX, minScrollPosX); y = between(y, maxScrollPosY, minScrollPosY); return { x: x, y: y }; }; ScrollerActions.prototype.handleClick = function (e) { if (!preventDefaultExceptionFn(e.target, this.options.preventDefaultException)) { maybePrevent(e); e.stopPropagation(); } }; ScrollerActions.prototype.getCurrentPos = function () { return { x: this.scrollBehaviorX.getCurrentPos(), y: this.scrollBehaviorY.getCurrentPos(), }; }; ScrollerActions.prototype.refresh = function () { this.endTime = 0; }; ScrollerActions.prototype.destroy = function () { this.hooks.destroy(); }; return ScrollerActions; }()); function createActionsHandlerOptions(bsOptions) { var options = [ ' click ', ' bindToWrapper ', ' disableMouse ', ' disableTouch ', ' preventDefault ', ' stopPropagation ', ' tagException ', ' preventDefaultException ', ' autoEndDistance ', ].reduce(function (prev, cur) { prev[cur] = bsOptions[cur]; return prev; }, {}); return options; } function createBehaviorOptions(bsOptions, extraProp, bounces, rect) { var options = [ ' momentum ', ' momentumLimitTime ', ' momentumLimitDistance ', ' deceleration ', ' swipeBounceTime ', ' swipeTime ', ' outOfBoundaryDampingFactor ', ' specifiedIndexAsContent ', ].reduce(function (prev, cur) { prev[cur] = bsOptions[cur]; return prev; }, {}); // add extra property options.scrollable = !!bsOptions[extraProp]; options.bounces = bounces; options.rect = rect; return options; } function bubbling(source, target, events) { events.forEach(function (event) { var sourceEvent; var targetEvent; if (typeof event === ' string ') { sourceEvent = targetEvent = event; } else { sourceEvent = event.source; targetEvent = event.target; } source.on(sourceEvent, function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } return target.trigger.apply(target, __spreadArrays([targetEvent], args)); }); }); } function isSamePoint(startPoint, endPoint) { // keys of startPoint and endPoint should be equal var keys = Object.keys(startPoint); for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) { var key = keys_1[_i]; if (startPoint[key] !== endPoint[key]) return false; } return true; } var MIN_SCROLL_DISTANCE = 1; var Scroller = /** @class */ (function () { function Scroller(wrapper, content, options) { this.wrapper = wrapper; this.content = content; this.resizeTimeout = 0; this.hooks = new EventEmitter([ ' beforeStart ', ' beforeMove ', ' beforeScrollStart ', ' scrollStart ', ' scroll ', ' beforeEnd ', ' scrollEnd ', ' resize ', ' touchEnd ', ' end ', ' flick ', ' scrollCancel ', ' momentum ', ' scrollTo ', ' minDistanceScroll ', ' scrollToElement ', ' beforeRefresh ', ]); this.options = options; var _a = this.options.bounce, left = _a.left, right = _a.right, top = _a.top, bottom = _a.bottom; // direction X this.scrollBehaviorX = new Behavior(wrapper, content, createBehaviorOptions(options, ' scrollX ', [left, right], { size: ' width ', position: ' left ', })); // direction Y this.scrollBehaviorY = new Behavior(wrapper, content, createBehaviorOptions(options, ' scrollY ', [top, bottom], { size: ' height ', position: ' top ', })); this.translater = new Translater(this.content); this.animater = createAnimater(this.content, this.translater, this.options); this.actionsHandler = new ActionsHandler(this.options.bindToTarget ? this.content : wrapper, createActionsHandlerOptions(this.options)); this.actions = new ScrollerActions(this.scrollBehaviorX, this.scrollBehaviorY, this.actionsHandler, this.animater, this.options); var resizeHandler = this.resize.bind(this); this.resizeRegister = new EventRegister(window, [ { name: ' orientationchange ', handler: resizeHandler, }, { name: ' resize ', handler: resizeHandler, }, ]); this.registerTransitionEnd(); this.init(); } Scroller.prototype.init = function () { var _this = this; this.bindTranslater(); this.bindAnimater(); this.bindActions(); // enable pointer events when scrolling ends this.hooks.on(this.hooks.eventTypes.scrollEnd, function () { _this.togglePointerEvents(true); }); }; Scroller.prototype.registerTransitionEnd = function () { this.transitionEndRegister = new EventRegister(this.content, [ { name: style.transitionEnd, handler: this.transitionEnd.bind(this), }, ]); }; Scroller.prototype.bindTranslater = function () { var _this = this; var hooks = this.translater.hooks; hooks.on(hooks.eventTypes.beforeTranslate, function (transformStyle) { if (_this.options.translateZ) { transformStyle.push(_this.options.translateZ); } }); // disable pointer events when scrolling hooks.on(hooks.eventTypes.translate, function (pos) { var prevPos = _this.getCurrentPos(); _this.updatePositions(pos); // scrollEnd will dispatch when scroll is force stopping in touchstart handler // so in touchend handler, don' t toggle pointer-events if (_this.actions.ensuringInteger === true ) { _this.actions.ensuringInteger = false ; return ; } // a valid translate if (pos.x !== prevPos.x || pos.y !== prevPos.y) { _this.togglePointerEvents( false ); } }); }; Scroller.prototype.bindAnimater = function () { var _this = this ; // reset position this .animater.hooks.on( this .animater.hooks.eventTypes.end, function (pos) { if (!_this.resetPosition(_this.options.bounceTime)) { _this.animater.setPending( false ); _this.hooks.trigger(_this.hooks.eventTypes.scrollEnd, pos); } }); bubbling( 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, }, ]); }; Scroller.prototype.bindActions = function () { var _this = this ; var actions = this .actions; bubbling(actions.hooks, this .hooks, [ { source: actions.hooks.eventTypes.start, target: this .hooks.eventTypes.beforeStart, }, { source: actions.hooks.eventTypes.start, target: this .hooks.eventTypes.beforeScrollStart, }, { source: actions.hooks.eventTypes.beforeMove, target: this .hooks.eventTypes.beforeMove, }, { source: actions.hooks.eventTypes.scrollStart, target: this .hooks.eventTypes.scrollStart, }, { source: actions.hooks.eventTypes.scroll, target: this .hooks.eventTypes.scroll, }, { source: actions.hooks.eventTypes.beforeEnd, target: this .hooks.eventTypes.beforeEnd, }, ]); actions.hooks.on(actions.hooks.eventTypes.end, function (e, pos) { _this.hooks.trigger(_this.hooks.eventTypes.touchEnd, pos); if (_this.hooks.trigger(_this.hooks.eventTypes.end, pos)) { return true ; } // check if it is a click operation if (!actions.fingerMoved) { _this.hooks.trigger(_this.hooks.eventTypes.scrollCancel); if (_this.checkClick(e)) { return true ; } } // reset if we are outside of the boundaries if (_this.resetPosition(_this.options.bounceTime, ease.bounce)) { _this.animater.setForceStopped( false ); return true ; } }); actions.hooks.on(actions.hooks.eventTypes.scrollEnd, function (pos, duration) { var deltaX = Math.abs(pos.x - _this.scrollBehaviorX.startPos); var deltaY = Math.abs(pos.y - _this.scrollBehaviorY.startPos); if (_this.checkFlick(duration, deltaX, deltaY)) { _this.animater.setForceStopped( false ); _this.hooks.trigger(_this.hooks.eventTypes.flick); return ; } if (_this.momentum(pos, duration)) { _this.animater.setForceStopped( false ); return ; } if (actions.contentMoved) { _this.hooks.trigger(_this.hooks.eventTypes.scrollEnd, pos); } if (_this.animater.forceStopped) { _this.animater.setForceStopped( false ); } }); }; Scroller.prototype.checkFlick = function (duration, deltaX, deltaY) { var flickMinMovingDistance = 1; // distinguish flick from click if ( this .hooks.events.flick.length > 1 && duration < this .options.flickLimitTime && deltaX < this .options.flickLimitDistance && deltaY < this .options.flickLimitDistance && (deltaY > flickMinMovingDistance || deltaX > flickMinMovingDistance)) { return true ; } }; Scroller.prototype.momentum = function (pos, duration) { var meta = { time: 0, easing: ease.swiper, newX: pos.x, newY: pos.y, }; // start momentum animation if needed var momentumX = this .scrollBehaviorX.end(duration); var momentumY = this .scrollBehaviorY.end(duration); meta.newX = isUndef(momentumX.destination) ? meta.newX : momentumX.destination; meta.newY = isUndef(momentumY.destination) ? meta.newY : momentumY.destination; meta.time = Math.max(momentumX.duration, momentumY.duration); this .hooks.trigger( this .hooks.eventTypes.momentum, meta, this ); // when x or y changed, do momentum animation now! if (meta.newX !== pos.x || meta.newY !== pos.y) { // change easing function when scroller goes out of the boundaries if (meta.newX > this .scrollBehaviorX.minScrollPos || meta.newX < this .scrollBehaviorX.maxScrollPos || meta.newY > this .scrollBehaviorY.minScrollPos || meta.newY < this .scrollBehaviorY.maxScrollPos) { meta.easing = ease.swipeBounce; } this .scrollTo(meta.newX, meta.newY, meta.time, meta.easing); return true ; } }; Scroller.prototype.checkClick = function (e) { var cancelable = { preventClick: this .animater.forceStopped, }; // we scrolled less than momentumLimitDistance pixels if ( this .hooks.trigger( this .hooks.eventTypes.checkClick)) { this .animater.setForceStopped( false ); return true ; } if (!cancelable.preventClick) { var _dblclick = this .options.dblclick; var dblclickTrigged = false ; if (_dblclick && this .lastClickTime) { var _a = _dblclick.delay, delay = _a === void 0 ? 300 : _a; if (getNow() - this .lastClickTime < delay) { dblclickTrigged = true ; dblclick(e); } } if ( this .options.tap) { tap(e, this .options.tap); } if ( this .options.click && !preventDefaultExceptionFn(e.target, this .options.preventDefaultException)) { click(e); } this .lastClickTime = dblclickTrigged ? null : getNow(); return true ; } return false ; }; Scroller.prototype.resize = function () { var _this = this ; if (! this .actions.enabled) { return ; } // fix a scroll problem under Android condition /* istanbul ignore if */ if (isAndroid) { this .wrapper.scrollTop = 0; } clearTimeout( this .resizeTimeout); this .resizeTimeout = window.setTimeout( function () { _this.hooks.trigger(_this.hooks.eventTypes.resize); }, this .options.resizePolling); }; /* istanbul ignore next */ Scroller.prototype.transitionEnd = function (e) { if (e.target !== this .content || ! this .animater.pending) { return ; } var animater = this .animater; animater.transitionTime(); if (! this .resetPosition( this .options.bounceTime, ease.bounce)) { this .animater.setPending( false ); if ( this .options.probeType !== 3 /* Realtime */ ) { this .hooks.trigger( this .hooks.eventTypes.scrollEnd, this .getCurrentPos()); } } }; Scroller.prototype.togglePointerEvents = function (enabled) { if (enabled === void 0) { enabled = true ; } var el = this .content.children.length ? this .content.children : [ this .content]; var pointerEvents = enabled ? 'auto' : 'none' ; for ( var i = 0; i < el.length; i++) { var node = el[i]; // ignore BetterScroll instance's wrapper DOM /* istanbul ignore if */ if (node.isBScrollContainer) { continue ; } node.style.pointerEvents = pointerEvents; } }; Scroller.prototype.refresh = function (content) { var contentChanged = this .setContent(content); this .hooks.trigger( this .hooks.eventTypes.beforeRefresh); this .scrollBehaviorX.refresh(content); this .scrollBehaviorY.refresh(content); if (contentChanged) { this .translater.setContent(content); this .animater.setContent(content); this .transitionEndRegister.destroy(); this .registerTransitionEnd(); if ( this .options.bindToTarget) { this .actionsHandler.setContent(content); } } this .actions.refresh(); this .wrapperOffset = offset( this .wrapper); }; Scroller.prototype.setContent = function (content) { var contentChanged = content !== this .content; if (contentChanged) { this .content = content; } return contentChanged; }; Scroller.prototype.scrollBy = function (deltaX, deltaY, time, easing) { if (time === void 0) { time = 0; } var _a = this .getCurrentPos(), x = _a.x, y = _a.y; easing = !easing ? ease.bounce : easing; deltaX += x; deltaY += y; this .scrollTo(deltaX, deltaY, time, easing); }; Scroller.prototype.scrollTo = function (x, y, time, easing, extraTransform) { if (time === void 0) { time = 0; } if (easing === void 0) { easing = ease.bounce; } if (extraTransform === void 0) { extraTransform = { start: {}, end: {}, }; } var easingFn = this .options.useTransition ? easing.style : easing.fn; var currentPos = this .getCurrentPos(); var startPoint = __assign({ x: currentPos.x, y: currentPos.y }, extraTransform.start); var endPoint = __assign({ x: x, y: y }, extraTransform.end); this .hooks.trigger( this .hooks.eventTypes.scrollTo, endPoint); // it is an useless move if (isSamePoint(startPoint, endPoint)) return ; var deltaX = Math.abs(endPoint.x - startPoint.x); var deltaY = Math.abs(endPoint.y - startPoint.y); // considering of browser compatibility for decimal transform value // force translating immediately if (deltaX < MIN_SCROLL_DISTANCE && deltaY < MIN_SCROLL_DISTANCE) { time = 0; this .hooks.trigger( this .hooks.eventTypes.minDistanceScroll); } this .animater.move(startPoint, endPoint, time, easingFn); }; Scroller.prototype.scrollToElement = function (el, time, offsetX, offsetY, easing) { var targetEle = getElement(el); var pos = offset(targetEle); var getOffset = function (offset, size, wrapperSize) { if ( typeof offset === 'number ') { return offset; } // if offsetX/Y are true we center the element to the screen return offset ? Math.round(size / 2 - wrapperSize / 2) : 0; }; offsetX = getOffset(offsetX, targetEle.offsetWidth, this.wrapper.offsetWidth); offsetY = getOffset(offsetY, targetEle.offsetHeight, this.wrapper.offsetHeight); var getPos = function (pos, wrapperPos, offset, scrollBehavior) { pos -= wrapperPos; pos = scrollBehavior.adjustPosition(pos - offset); return pos; }; pos.left = getPos(pos.left, this.wrapperOffset.left, offsetX, this.scrollBehaviorX); pos.top = getPos(pos.top, this.wrapperOffset.top, offsetY, this.scrollBehaviorY); if (this.hooks.trigger(this.hooks.eventTypes.scrollToElement, targetEle, pos)) { return; } this.scrollTo(pos.left, pos.top, time, easing); }; Scroller.prototype.resetPosition = function (time, easing) { if (time === void 0) { time = 0; } if (easing === void 0) { easing = ease.bounce; } var _a = this.scrollBehaviorX.checkInBoundary(), x = _a.position, xInBoundary = _a.inBoundary; var _b = this.scrollBehaviorY.checkInBoundary(), y = _b.position, yInBoundary = _b.inBoundary; if (xInBoundary && yInBoundary) { return false; } /* istanbul ignore if */ if (isIOSBadVersion) { // fix ios 13.4 bouncing // see it in issues 982 this.reflow(); } // out of boundary this.scrollTo(x, y, time, easing); return true; }; /* istanbul ignore next */ Scroller.prototype.reflow = function () { this._reflow = this.content.offsetHeight; }; Scroller.prototype.updatePositions = function (pos) { this.scrollBehaviorX.updatePosition(pos.x); this.scrollBehaviorY.updatePosition(pos.y); }; Scroller.prototype.getCurrentPos = function () { return this.actions.getCurrentPos(); }; Scroller.prototype.enable = function () { this.actions.enabled = true; }; Scroller.prototype.disable = function () { cancelAnimationFrame(this.animater.timer); this.actions.enabled = false; }; Scroller.prototype.destroy = function () { var _this = this; var keys = [ ' resizeRegister ', ' transitionEndRegister ', ' actionsHandler ', ' actions ', ' hooks ', ' animater ', ' translater ', ' scrollBehaviorX ', ' scrollBehaviorY ', ]; keys.forEach(function (key) { return _this[key].destroy(); }); }; return Scroller; }()); var BScrollConstructor = /** @class */ (function (_super) { __extends(BScrollConstructor, _super); function BScrollConstructor(el, options) { var _this = _super.call(this, [ ' refresh ', ' contentChanged ', ' enable ', ' disable ', ' beforeScrollStart ', ' scrollStart ', ' scroll ', ' scrollEnd ', ' scrollCancel ', ' touchEnd ', ' flick ', ' destroy ' ]) || this; var wrapper = getElement(el); if (!wrapper) { warn(' Can not resolve the wrapper DOM. '); return _this; } _this.plugins = {}; _this.options = new OptionsConstructor().merge(options).process(); if (!_this.setContent(wrapper).valid) { return _this; } _this.hooks = new EventEmitter([ ' refresh ', ' enable ', ' disable ', ' destroy ', ' beforeInitialScrollTo ', ' contentChanged ' ]); _this.init(wrapper); return _this; } BScrollConstructor.use = function (ctor) { var name = ctor.pluginName; var installed = BScrollConstructor.plugins.some(function (plugin) { return ctor === plugin.ctor; }); if (installed) return BScrollConstructor; if (isUndef(name)) { warn("Plugin Class must specify plugin' s name in static property by 'pluginName' field."); return BScrollConstructor; } BScrollConstructor.pluginsMap[name] = true ; BScrollConstructor.plugins.push({ name: name, applyOrder: ctor.applyOrder, ctor: ctor }); return BScrollConstructor; }; BScrollConstructor.prototype.setContent = function (wrapper) { var contentChanged = false ; var valid = true ; var content = wrapper.children[ this .options.specifiedIndexAsContent]; if (!content) { warn( 'The wrapper need at least one child element to be content element to scroll.' ); valid = false ; } else { contentChanged = this .content !== content; if (contentChanged) { this .content = content; } } return { valid: valid, contentChanged: contentChanged }; }; BScrollConstructor.prototype.init = function (wrapper) { var _this = this ; this .wrapper = wrapper; // mark wrapper to recognize bs instance by DOM attribute wrapper.isBScrollContainer = true ; this .scroller = new Scroller(wrapper, this .content, this .options); this .scroller.hooks.on( this .scroller.hooks.eventTypes.resize, function () { _this.refresh(); }); this .eventBubbling(); this .handleAutoBlur(); this .enable(); this .proxy(propertiesConfig$7); this .applyPlugins(); // maybe boundary has changed, should refresh this .refreshWithoutReset( this .content); var _a = this .options, startX = _a.startX, startY = _a.startY; var position = { x: startX, y: startY }; // maybe plugins want to control scroll position if ( this .hooks.trigger( this .hooks.eventTypes.beforeInitialScrollTo, position)) { return ; } this .scroller.scrollTo(position.x, position.y); }; BScrollConstructor.prototype.applyPlugins = function () { var _this = this ; var options = this .options; BScrollConstructor.plugins .sort( function (a, b) { var _a; var applyOrderMap = (_a = {}, _a[ "pre" /* Pre */ ] = -1, _a[ "post" /* Post */ ] = 1, _a); var aOrder = a.applyOrder ? applyOrderMap[a.applyOrder] : 0; var bOrder = b.applyOrder ? applyOrderMap[b.applyOrder] : 0; return aOrder - bOrder; }) .forEach( function (item) { var ctor = item.ctor; if (options[item.name] && typeof ctor === 'function' ) { _this.plugins[item.name] = new ctor(_this); } }); }; BScrollConstructor.prototype.handleAutoBlur = function () { /* istanbul ignore if */ if ( this .options.autoBlur) { this .on( this .eventTypes.beforeScrollStart, function () { var activeElement = document.activeElement; if (activeElement && (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA' )) { activeElement.blur(); } }); } }; BScrollConstructor.prototype.eventBubbling = function () { bubbling( 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 ]); }; BScrollConstructor.prototype.refreshWithoutReset = function (content) { this .scroller.refresh(content); this .hooks.trigger( this .hooks.eventTypes.refresh, content); this .trigger( this .eventTypes.refresh, content); }; BScrollConstructor.prototype.proxy = function (propertiesConfig) { var _this = this ; propertiesConfig.forEach( function (_a) { var key = _a.key, sourceKey = _a.sourceKey; propertiesProxy(_this, sourceKey, key); }); }; BScrollConstructor.prototype.refresh = function () { var _a = this .setContent( this .wrapper), contentChanged = _a.contentChanged, valid = _a.valid; if (valid) { var content = this .content; this .refreshWithoutReset(content); if (contentChanged) { this .hooks.trigger( this .hooks.eventTypes.contentChanged, content); this .trigger( this .eventTypes.contentChanged, content); } this .scroller.resetPosition(); } }; BScrollConstructor.prototype.enable = function () { this .scroller.enable(); this .hooks.trigger( this .hooks.eventTypes.enable); this .trigger( this .eventTypes.enable); }; BScrollConstructor.prototype.disable = function () { this .scroller.disable(); this .hooks.trigger( this .hooks.eventTypes.disable); this .trigger( this .eventTypes.disable); }; BScrollConstructor.prototype.destroy = function () { this .hooks.trigger( this .hooks.eventTypes.destroy); this .trigger( this .eventTypes.destroy); this .scroller.destroy(); }; BScrollConstructor.prototype.eventRegister = function (names) { this .registerType(names); }; BScrollConstructor.plugins = []; BScrollConstructor.pluginsMap = {}; return BScrollConstructor; }(EventEmitter)); function createBScroll(el, options) { var bs = new BScrollConstructor(el, options); return bs; } createBScroll.use = BScrollConstructor.use; createBScroll.plugins = BScrollConstructor.plugins; createBScroll.pluginsMap = BScrollConstructor.pluginsMap; var BScroll = createBScroll; var MouseWheel = /** @class */ ( function () { function MouseWheel(scroll) { this .scroll = scroll; this .wheelEndTimer = 0; this .wheelMoveTimer = 0; this .wheelStart = false ; this .init(); } MouseWheel.prototype.init = function () { this .handleBScroll(); this .handleOptions(); this .handleHooks(); this .registerEvent(); }; MouseWheel.prototype.handleBScroll = function () { this .scroll.registerType([ 'alterOptions' , 'mousewheelStart' , 'mousewheelMove' , 'mousewheelEnd' , ]); }; MouseWheel.prototype.handleOptions = function () { var userOptions = ( this .scroll.options.mouseWheel === true ? {} : this .scroll.options.mouseWheel); var defaultOptions = { speed: 20, invert: false , easeTime: 300, discreteTime: 400, throttleTime: 0, dampingFactor: 0.1, }; this .mouseWheelOpt = extend(defaultOptions, userOptions); }; MouseWheel.prototype.handleHooks = function () { this .hooksFn = []; this .registerHooks( this .scroll.hooks, 'destroy' , this .destroy); }; MouseWheel.prototype.registerEvent = function () { this .eventRegister = new EventRegister( this .scroll.scroller.wrapper, [ { name: 'wheel' , handler: this .wheelHandler.bind( this ), }, { name: 'mousewheel' , handler: this .wheelHandler.bind( this ), }, { name: 'DOMMouseScroll' , handler: this .wheelHandler.bind( this ), }, ]); }; MouseWheel.prototype.registerHooks = function (hooks, name, handler) { hooks.on(name, handler, this ); this .hooksFn.push([hooks, name, handler]); }; MouseWheel.prototype.wheelHandler = function (e) { if (! this .scroll.enabled) { return ; } this .beforeHandler(e); // start if (! this .wheelStart) { this .wheelStartHandler(e); this .wheelStart = true ; } // move var delta = this .getWheelDelta(e); this .wheelMoveHandler(delta); // end this .wheelEndDetector(delta); }; MouseWheel.prototype.wheelStartHandler = function (e) { this .cleanCache(); var _a = this .scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY; scrollBehaviorX.setMovingDirection(0 /* Default */ ); scrollBehaviorY.setMovingDirection(0 /* Default */ ); scrollBehaviorX.setDirection(0 /* Default */ ); scrollBehaviorY.setDirection(0 /* Default */ ); this .scroll.trigger( this .scroll.eventTypes.alterOptions, this .mouseWheelOpt); this .scroll.trigger( this .scroll.eventTypes.mousewheelStart); }; MouseWheel.prototype.cleanCache = function () { this .deltaCache = []; }; MouseWheel.prototype.wheelMoveHandler = function (delta) { var _this = this ; var _a = this .mouseWheelOpt, throttleTime = _a.throttleTime, dampingFactor = _a.dampingFactor; if (throttleTime && this .wheelMoveTimer) { this .deltaCache.push(delta); } else { var cachedDelta = this .deltaCache.reduce( function (prev, current) { return { x: prev.x + current.x, y: prev.y + current.y, }; }, { x: 0, y: 0 }); this .cleanCache(); var _b = this .scroll.scroller, scrollBehaviorX = _b.scrollBehaviorX, scrollBehaviorY = _b.scrollBehaviorY; scrollBehaviorX.setMovingDirection(-delta.directionX); scrollBehaviorY.setMovingDirection(-delta.directionY); scrollBehaviorX.setDirection(delta.x); scrollBehaviorY.setDirection(delta.y); // when out of boundary, perform a damping scroll var newX = scrollBehaviorX.performDampingAlgorithm(Math.round(delta.x) + cachedDelta.x, dampingFactor); var newY = scrollBehaviorY.performDampingAlgorithm(Math.round(delta.y) + cachedDelta.x, dampingFactor); if (! this .scroll.trigger( this .scroll.eventTypes.mousewheelMove, { x: newX, y: newY, })) { var easeTime = this .getEaseTime(); if (newX !== this .scroll.x || newY !== this .scroll.y) { this .scroll.scrollTo(newX, newY, easeTime); } } if (throttleTime) { this .wheelMoveTimer = window.setTimeout( function () { _this.wheelMoveTimer = 0; }, throttleTime); } } }; MouseWheel.prototype.wheelEndDetector = function (delta) { var _this = this ; window.clearTimeout( this .wheelEndTimer); this .wheelEndTimer = window.setTimeout( function () { _this.wheelStart = false ; window.clearTimeout(_this.wheelMoveTimer); _this.wheelMoveTimer = 0; _this.scroll.trigger(_this.scroll.eventTypes.mousewheelEnd, delta); }, this .mouseWheelOpt.discreteTime); }; MouseWheel.prototype.getWheelDelta = function (e) { var _a = this .mouseWheelOpt, speed = _a.speed, invert = _a.invert; var wheelDeltaX = 0; var wheelDeltaY = 0; var direction = invert ? -1 /* Negative */ : 1 /* Positive */ ; switch ( true ) { case 'deltaX' in e: if (e.deltaMode === 1) { wheelDeltaX = -e.deltaX * speed; wheelDeltaY = -e.deltaY * speed; } else { wheelDeltaX = -e.deltaX; wheelDeltaY = -e.deltaY; } break ; case 'wheelDeltaX' in e: wheelDeltaX = (e.wheelDeltaX / 120) * speed; wheelDeltaY = (e.wheelDeltaY / 120) * speed; break ; case 'wheelDelta' in e: wheelDeltaX = wheelDeltaY = (e.wheelDelta / 120) * speed; break ; case 'detail' in e: wheelDeltaX = wheelDeltaY = (-e.detail / 3) * speed; break ; } wheelDeltaX *= direction; wheelDeltaY *= direction; if (! this .scroll.hasVerticalScroll) { if (Math.abs(wheelDeltaY) > Math.abs(wheelDeltaX)) { wheelDeltaX = wheelDeltaY; } wheelDeltaY = 0; } if (! this .scroll.hasHorizontalScroll) { wheelDeltaX = 0; } var directionX = wheelDeltaX > 0 ? -1 /* Negative */ : wheelDeltaX < 0 ? 1 /* Positive */ : 0 /* Default */ ; var directionY = wheelDeltaY > 0 ? -1 /* Negative */ : wheelDeltaY < 0 ? 1 /* Positive */ : 0 /* Default */ ; return { x: wheelDeltaX, y: wheelDeltaY, directionX: directionX, directionY: directionY, }; }; MouseWheel.prototype.beforeHandler = function (e) { var _a = this .scroll.options, preventDefault = _a.preventDefault, stopPropagation = _a.stopPropagation, preventDefaultException = _a.preventDefaultException; if (preventDefault && !preventDefaultExceptionFn(e.target, preventDefaultException)) { maybePrevent(e); } if (stopPropagation) { e.stopPropagation(); } }; MouseWheel.prototype.getEaseTime = function () { var SAFE_EASETIME = 100; var easeTime = this .mouseWheelOpt.easeTime; // scrollEnd event will be triggered in every calling of scrollTo when easeTime is too small // easeTime needs to be greater than 100 if (easeTime < SAFE_EASETIME) { warn( "easeTime should be greater than 100." + "If mouseWheel easeTime is too small," + "scrollEnd will be triggered many times." ); } return Math.max(easeTime, SAFE_EASETIME); }; MouseWheel.prototype.destroy = function () { this .eventRegister.destroy(); window.clearTimeout( this .wheelEndTimer); window.clearTimeout( this .wheelMoveTimer); this .hooksFn.forEach( function (item) { var hooks = item[0]; var hooksName = item[1]; var handlerFn = item[2]; hooks.off(hooksName, handlerFn); }); }; MouseWheel.pluginName = 'mouseWheel' ; MouseWheel.applyOrder = "pre" /* Pre */ ; return MouseWheel; }()); var ObserveDOM = /** @class */ ( function () { function ObserveDOM(scroll) { this .scroll = scroll; this .stopObserver = false ; this .init(); } ObserveDOM.prototype.init = function () { this .handleMutationObserver(); this .handleHooks(); }; ObserveDOM.prototype.handleMutationObserver = function () { var _this = this ; if ( typeof MutationObserver !== 'undefined' ) { var timer_1 = 0; this .observer = new MutationObserver( function (mutations) { _this.mutationObserverHandler(mutations, timer_1); }); this .startObserve( this .observer); } else { this .checkDOMUpdate(); } }; ObserveDOM.prototype.handleHooks = function () { var _this = this ; this .hooksFn = []; this .registerHooks( this .scroll.hooks, this .scroll.hooks.eventTypes.contentChanged, function () { _this.stopObserve(); // launch a new mutationObserver _this.handleMutationObserver(); }); this .registerHooks( this .scroll.hooks, this .scroll.hooks.eventTypes.enable, function () { if (_this.stopObserver) { _this.handleMutationObserver(); } }); this .registerHooks( this .scroll.hooks, this .scroll.hooks.eventTypes.disable, function () { _this.stopObserve(); }); this .registerHooks( this .scroll.hooks, this .scroll.hooks.eventTypes.destroy, function () { _this.destroy(); }); }; ObserveDOM.prototype.mutationObserverHandler = function (mutations, timer) { var _this = this ; if ( this .shouldNotRefresh()) { return ; } var immediateRefresh = false ; var deferredRefresh = false ; for ( var i = 0; i < mutations.length; i++) { var mutation = mutations[i]; if (mutation.type !== 'attributes' ) { immediateRefresh = true ; break ; } else { if (mutation.target !== this .scroll.scroller.content) { deferredRefresh = true ; break ; } } } if (immediateRefresh) { this .scroll.refresh(); } else if (deferredRefresh) { // attributes changes too often clearTimeout(timer); timer = window.setTimeout( function () { if (!_this.shouldNotRefresh()) { _this.scroll.refresh(); } }, 60); } }; ObserveDOM.prototype.startObserve = function (observer) { var config = { attributes: true , childList: true , subtree: true , }; observer.observe( this .scroll.scroller.content, config); }; ObserveDOM.prototype.shouldNotRefresh = function () { var scroller = this .scroll.scroller; var scrollBehaviorX = scroller.scrollBehaviorX, scrollBehaviorY = scroller.scrollBehaviorY; var outsideBoundaries = scrollBehaviorX.currentPos > scrollBehaviorX.minScrollPos || scrollBehaviorX.currentPos < scrollBehaviorX.maxScrollPos || scrollBehaviorY.currentPos > scrollBehaviorY.minScrollPos || scrollBehaviorY.currentPos < scrollBehaviorY.maxScrollPos; return scroller.animater.pending || outsideBoundaries; }; ObserveDOM.prototype.checkDOMUpdate = function () { var _this = this ; var content = this .scroll.scroller.content; var contentRect = getRect(content); var oldWidth = contentRect.width; var oldHeight = contentRect.height; var check = function () { if (_this.stopObserver) { return ; } contentRect = getRect(content); var newWidth = contentRect.width; var newHeight = contentRect.height; if (oldWidth !== newWidth || oldHeight !== newHeight) { _this.scroll.refresh(); } oldWidth = newWidth; oldHeight = newHeight; next(); }; var next = function () { setTimeout( function () { check(); }, 1000); }; next(); }; ObserveDOM.prototype.registerHooks = function (hooks, name, handler) { hooks.on(name, handler, this ); this .hooksFn.push([hooks, name, handler]); }; ObserveDOM.prototype.stopObserve = function () { this .stopObserver = true ; if ( this .observer) { this .observer.disconnect(); } }; ObserveDOM.prototype.destroy = function () { this .stopObserve(); this .hooksFn.forEach( function (item) { var hooks = item[0]; var hooksName = item[1]; var handlerFn = item[2]; hooks.off(hooksName, handlerFn); }); this .hooksFn.length = 0; }; ObserveDOM.pluginName = 'observeDOM' ; return ObserveDOM; }()); var sourcePrefix$6 = 'plugins.pullDownRefresh' ; var propertiesMap$6 = [ { key: 'finishPullDown' , name: 'finishPullDown' }, { key: 'openPullDown' , name: 'openPullDown' }, { key: 'closePullDown' , name: 'closePullDown' }, { key: 'autoPullDownRefresh' , name: 'autoPullDownRefresh' } ]; var propertiesConfig$6 = propertiesMap$6.map( function (item) { return { key: item.key, sourceKey: sourcePrefix$6 + "." + item.name }; }); var PULLING_DOWN_EVENT = 'pullingDown' ; var ENTER_THRESHOLD_EVENT = 'enterThreshold' ; var LEAVE_THRESHOLD_EVENT = 'leaveThreshold' ; var PullDown = /** @class */ ( function () { function PullDown(scroll) { this .scroll = scroll; this .pulling = 0 /* DEFAULT */ ; this .thresholdBoundary = 0 /* DEFAULT */ ; this .init(); } PullDown.prototype.setPulling = function (status) { this .pulling = status; }; PullDown.prototype.setThresholdBoundary = function (boundary) { this .thresholdBoundary = boundary; }; PullDown.prototype.init = function () { this .handleBScroll(); this .handleOptions( this .scroll.options.pullDownRefresh); this .handleHooks(); this .watch(); }; PullDown.prototype.handleBScroll = function () { this .scroll.registerType([ PULLING_DOWN_EVENT, ENTER_THRESHOLD_EVENT, LEAVE_THRESHOLD_EVENT, ]); this .scroll.proxy(propertiesConfig$6); }; PullDown.prototype.handleOptions = function (userOptions) { if (userOptions === void 0) { userOptions = {}; } userOptions = (userOptions === true ? {} : userOptions); var defaultOptions = { threshold: 90, stop: 40, }; this .options = extend(defaultOptions, userOptions); this .scroll.options.probeType = 3 /* Realtime */ ; }; PullDown.prototype.handleHooks = function () { var _this = this ; this .hooksFn = []; var scroller = this .scroll.scroller; var scrollBehaviorY = scroller.scrollBehaviorY; this .currentMinScrollY = this .cachedOriginanMinScrollY = scrollBehaviorY.minScrollPos; this .registerHooks( this .scroll.hooks, this .scroll.hooks.eventTypes.contentChanged, function () { _this.finishPullDown(); }); this .registerHooks(scrollBehaviorY.hooks, scrollBehaviorY.hooks.eventTypes.computeBoundary, function (boundary) { // content is smaller than wrapper if (boundary.maxScrollPos > 0) { // allow scrolling when content is not full of wrapper boundary.maxScrollPos = -1; } boundary.minScrollPos = _this.currentMinScrollY; }); // integrate with mousewheel if ( this .hasMouseWheelPlugin()) { this .registerHooks( this .scroll, this .scroll.eventTypes.alterOptions, function (mouseWheelOptions) { var SANE_DISCRETE_TIME = 300; var SANE_EASE_TIME = 350; mouseWheelOptions.discreteTime = SANE_DISCRETE_TIME; // easeTime > discreteTime ensure goInto checkPullDown function mouseWheelOptions.easeTime = SANE_EASE_TIME; }); this .registerHooks( this .scroll, this .scroll.eventTypes.mousewheelEnd, function () { // mouseWheel need trigger checkPullDown manually scroller.hooks.trigger(scroller.hooks.eventTypes.end); }); } }; PullDown.prototype.registerHooks = function (hooks, name, handler) { hooks.on(name, handler, this ); this .hooksFn.push([hooks, name, handler]); }; PullDown.prototype.hasMouseWheelPlugin = function () { return !! this .scroll.eventTypes.alterOptions; }; PullDown.prototype.watch = function () { var scroller = this .scroll.scroller; this .watching = true ; this .registerHooks(scroller.hooks, scroller.hooks.eventTypes.end, this .checkPullDown); this .registerHooks( this .scroll, this .scroll.eventTypes.scrollStart, this .resetStateBeforeScrollStart); this .registerHooks( this .scroll, this .scroll.eventTypes.scroll, this .checkLocationOfThresholdBoundary); if ( this .hasMouseWheelPlugin()) { this .registerHooks( this .scroll, this .scroll.eventTypes.mousewheelStart, this .resetStateBeforeScrollStart); } }; PullDown.prototype.resetStateBeforeScrollStart = function () { // current fetching pulldownRefresh has ended if (! this .isFetchingStatus()) { this .setPulling(1 /* MOVING */ ); this .setThresholdBoundary(0 /* DEFAULT */ ); } }; PullDown.prototype.checkLocationOfThresholdBoundary = function () { // pulldownRefresh is in the phase of Moving if ( this .pulling === 1 /* MOVING */ ) { var scroll_1 = this .scroll; // enter threshold boundary var enteredThresholdBoundary = this .thresholdBoundary !== 1 /* INSIDE */ && this .locateInsideThresholdBoundary(); // leave threshold boundary var leftThresholdBoundary = this .thresholdBoundary !== 2 /* OUTSIDE */ && ! this .locateInsideThresholdBoundary(); if (enteredThresholdBoundary) { this .setThresholdBoundary(1 /* INSIDE */ ); scroll_1.trigger(ENTER_THRESHOLD_EVENT); } if (leftThresholdBoundary) { this .setThresholdBoundary(2 /* OUTSIDE */ ); scroll_1.trigger(LEAVE_THRESHOLD_EVENT); } } }; PullDown.prototype.locateInsideThresholdBoundary = function () { return this .scroll.y <= this .options.threshold; }; PullDown.prototype.unwatch = function () { var scroll = this .scroll; var scroller = scroll.scroller; this .watching = false ; scroller.hooks.off(scroller.hooks.eventTypes.end, this .checkPullDown); scroll.off(scroll.eventTypes.scrollStart, this .resetStateBeforeScrollStart); scroll.off(scroll.eventTypes.scroll, this .checkLocationOfThresholdBoundary); if ( this .hasMouseWheelPlugin()) { scroll.off(scroll.eventTypes.mousewheelStart, this .resetStateBeforeScrollStart); } }; PullDown.prototype.checkPullDown = function () { var _a = this .options, threshold = _a.threshold, stop = _a.stop; // check if a real pull down action if ( this .scroll.y < threshold) { return false ; } if ( this .pulling === 1 /* MOVING */ ) { this .modifyBehaviorYBoundary(stop); this .setPulling(2 /* FETCHING */ ); this .scroll.trigger(PULLING_DOWN_EVENT); } this .scroll.scrollTo( this .scroll.x, stop, this .scroll.options.bounceTime, ease.bounce); return this .isFetchingStatus(); }; PullDown.prototype.isFetchingStatus = function () { return this .pulling === 2 /* FETCHING */ ; }; PullDown.prototype.modifyBehaviorYBoundary = function (stopDistance) { var scrollBehaviorY = this .scroll.scroller.scrollBehaviorY; // manually modify minScrollPos for a hang animation // to prevent from resetPosition this .cachedOriginanMinScrollY = scrollBehaviorY.minScrollPos; this .currentMinScrollY = stopDistance; scrollBehaviorY.computeBoundary(); }; PullDown.prototype.finishPullDown = function () { if ( this .isFetchingStatus()) { var scrollBehaviorY = this .scroll.scroller.scrollBehaviorY; // restore minScrollY since the hang animation has ended this .currentMinScrollY = this .cachedOriginanMinScrollY; scrollBehaviorY.computeBoundary(); this .setPulling(0 /* DEFAULT */ ); this .scroll.resetPosition( this .scroll.options.bounceTime, ease.bounce); } }; // allow 'true' type is compat for beta version implements PullDown.prototype.openPullDown = function (config) { if (config === void 0) { config = {}; } this .handleOptions(config); if (! this .watching) { this .watch(); } }; PullDown.prototype.closePullDown = function () { this .unwatch(); }; PullDown.prototype.autoPullDownRefresh = function () { var _a = this .options, threshold = _a.threshold, stop = _a.stop; if ( this .isFetchingStatus() || ! this .watching) { return ; } this .modifyBehaviorYBoundary(stop); this .scroll.trigger( this .scroll.eventTypes.scrollStart); this .scroll.scrollTo( this .scroll.x, threshold); this .setPulling(2 /* FETCHING */ ); this .scroll.trigger(PULLING_DOWN_EVENT); this .scroll.scrollTo( this .scroll.x, stop, this .scroll.options.bounceTime, ease.bounce); }; PullDown.pluginName = 'pullDownRefresh' ; return PullDown; }()); var sourcePrefix$5 = 'plugins.pullUpLoad' ; var propertiesMap$5 = [ { key: 'finishPullUp' , name: 'finishPullUp' }, { key: 'openPullUp' , name: 'openPullUp' }, { key: 'closePullUp' , name: 'closePullUp' }, { key: 'autoPullUpLoad' , name: 'autoPullUpLoad' } ]; var propertiesConfig$5 = propertiesMap$5.map( function (item) { return { key: item.key, sourceKey: sourcePrefix$5 + "." + item.name }; }); var PULL_UP_HOOKS_NAME = 'pullingUp' ; var PullUp = /** @class */ ( function () { function PullUp(scroll) { this .scroll = scroll; this .pulling = false ; this .watching = false ; this .init(); } PullUp.prototype.init = function () { this .handleBScroll(); this .handleOptions( this .scroll.options.pullUpLoad); this .handleHooks(); this .watch(); }; PullUp.prototype.handleBScroll = function () { this .scroll.registerType([PULL_UP_HOOKS_NAME]); this .scroll.proxy(propertiesConfig$5); }; PullUp.prototype.handleOptions = function (userOptions) { if (userOptions === void 0) { userOptions = {}; } userOptions = (userOptions === true ? {} : userOptions); var defaultOptions = { threshold: 0, }; this .options = extend(defaultOptions, userOptions); this .scroll.options.probeType = 3 /* Realtime */ ; }; PullUp.prototype.handleHooks = function () { var _this = this ; this .hooksFn = []; var scrollBehaviorY = this .scroll.scroller.scrollBehaviorY; this .registerHooks( this .scroll.hooks, this .scroll.hooks.eventTypes.contentChanged, function () { _this.finishPullUp(); }); this .registerHooks(scrollBehaviorY.hooks, scrollBehaviorY.hooks.eventTypes.computeBoundary, function (boundary) { // content is smaller than wrapper if (boundary.maxScrollPos > 0) { // allow scrolling when content is not full of wrapper boundary.maxScrollPos = -1; } }); }; PullUp.prototype.registerHooks = function (hooks, name, handler) { hooks.on(name, handler, this ); this .hooksFn.push([hooks, name, handler]); }; PullUp.prototype.watch = function () { if ( this .watching) { return ; } this .watching = true ; this .registerHooks( this .scroll, this .scroll.eventTypes.scroll, this .checkPullUp); }; PullUp.prototype.unwatch = function () { this .watching = false ; this .scroll.off( this .scroll.eventTypes.scroll, this .checkPullUp); }; PullUp.prototype.checkPullUp = function (pos) { var _this = this ; var threshold = this .options.threshold; if ( this .scroll.movingDirectionY === 1 /* Positive */ && pos.y <= this .scroll.maxScrollY + threshold) { this .pulling = true ; // must reset pulling after scrollEnd this .scroll.once( this .scroll.eventTypes.scrollEnd, function () { _this.pulling = false ; }); this .unwatch(); this .scroll.trigger(PULL_UP_HOOKS_NAME); } }; PullUp.prototype.finishPullUp = function () { var _this = this ; // reset Direction, fix #936 this .scroll.scroller.scrollBehaviorY.setMovingDirection(0 /* Default */ ); if ( this .pulling) { this .scroll.once( this .scroll.eventTypes.scrollEnd, function () { _this.watch(); }); } else { this .watch(); } }; // allow 'true' type is compat for beta version implements PullUp.prototype.openPullUp = function (config) { if (config === void 0) { config = {}; } this .handleOptions(config); this .watch(); }; PullUp.prototype.closePullUp = function () { this .unwatch(); }; PullUp.prototype.autoPullUpLoad = function () { var threshold = this .options.threshold; var scrollBehaviorY = this .scroll.scroller.scrollBehaviorY; if ( this .pulling || ! this .watching) { return ; } // simulate a pullUp action var NEGATIVE_VALUE = -1; var outOfBoundaryPos = scrollBehaviorY.maxScrollPos + threshold + NEGATIVE_VALUE; this .scroll.scroller.scrollBehaviorY.setMovingDirection(NEGATIVE_VALUE); this .scroll.scrollTo( this .scroll.x, outOfBoundaryPos, this .scroll.options.bounceTime); }; PullUp.pluginName = 'pullUpLoad' ; return PullUp; }()); var EventHandler = /** @class */ ( function () { function EventHandler(indicator, options) { this .indicator = indicator; this .options = options; this .hooks = new EventEmitter([ 'touchStart' , 'touchMove' , 'touchEnd' ]); this .registerEvents(); } EventHandler.prototype.registerEvents = function () { var _a = this .options, disableMouse = _a.disableMouse, disableTouch = _a.disableTouch; var startEvents = []; var moveEvents = []; var endEvents = []; if (!disableMouse) { startEvents.push({ name: 'mousedown' , handler: this .start.bind( this ), }); moveEvents.push({ name: 'mousemove' , handler: this .move.bind( this ), }); endEvents.push({ name: 'mouseup' , handler: this .end.bind( this ), }); } if (!disableTouch) { startEvents.push({ name: 'touchstart' , handler: this .start.bind( this ), }); moveEvents.push({ name: 'touchmove' , handler: this .move.bind( this ), }); endEvents.push({ name: 'touchend' , handler: this .end.bind( this ), }, { name: 'touchcancel' , handler: this .end.bind( this ), }); } this .startEventRegister = new EventRegister( this .indicator.indicatorEl, startEvents); this .moveEventRegister = new EventRegister(window, moveEvents); this .endEventRegister = new EventRegister(window, endEvents); }; EventHandler.prototype.BScrollIsDisabled = function () { return ! this .indicator.scroll.enabled; }; EventHandler.prototype.start = function (e) { if ( this .BScrollIsDisabled()) { return ; } var point = (e.touches ? e.touches[0] : e); maybePrevent(e); e.stopPropagation(); this .initiated = true ; this .lastPoint = point[ this .indicator.keysMap.point]; this .hooks.trigger( this .hooks.eventTypes.touchStart); }; EventHandler.prototype.move = function (e) { if (! this .initiated) { return ; } var point = (e.touches ? e.touches[0] : e); var pointPos = point[ this .indicator.keysMap.point]; maybePrevent(e); e.stopPropagation(); var delta = pointPos - this .lastPoint; this .lastPoint = pointPos; this .hooks.trigger( this .hooks.eventTypes.touchMove, delta); }; EventHandler.prototype.end = function (e) { if (! this .initiated) { return ; } this .initiated = false ; maybePrevent(e); e.stopPropagation(); this .hooks.trigger( this .hooks.eventTypes.touchEnd); }; EventHandler.prototype.destroy = function () { this .startEventRegister.destroy(); this .moveEventRegister.destroy(); this .endEventRegister.destroy(); }; return EventHandler; }()); var Indicator$1 = /** @class */ ( function () { function Indicator(scroll, options) { this .scroll = scroll; this .options = options; this .hooksFn = []; this .wrapper = options.wrapper; this .direction = options.direction; this .indicatorEl = this .wrapper.children[0]; this .keysMap = this .getKeysMap(); this .handleFade(); this .handleHooks(); } Indicator.prototype.handleFade = function () { if ( this .options.fade) { this .wrapper.style.opacity = '0' ; } }; Indicator.prototype.handleHooks = function () { var _this = this ; var _a = this .options, fade = _a.fade, interactive = _a.interactive, scrollbarTrackClickable = _a.scrollbarTrackClickable; var scroll = this .scroll; var scrollHooks = scroll.hooks; var translaterHooks = scroll.scroller.translater.hooks; var animaterHooks = scroll.scroller.animater.hooks; this .registerHooks(scrollHooks, scrollHooks.eventTypes.refresh, this .refresh); this .registerHooks(translaterHooks, translaterHooks.eventTypes.translate, function (pos) { var hasScrollKey = _this.keysMap.hasScroll; if (_this.scroll[hasScrollKey]) { _this.updatePosition(pos); } }); this .registerHooks(animaterHooks, animaterHooks.eventTypes.time, this .transitionTime); this .registerHooks(animaterHooks, animaterHooks.eventTypes.timeFunction, this .transitionTimingFunction); if (fade) { this .registerHooks(scroll, scroll.eventTypes.scrollEnd, function () { _this.fade(); }); this .registerHooks(scroll, scroll.eventTypes.scrollStart, function () { _this.fade( true ); }); // for mousewheel event if (scroll.eventTypes.mousewheelStart && scroll.eventTypes.mousewheelEnd) { this .registerHooks(scroll, scroll.eventTypes.mousewheelStart, function () { _this.fade( true ); }); this .registerHooks(scroll, scroll.eventTypes.mousewheelMove, function () { _this.fade( true ); }); this .registerHooks(scroll, scroll.eventTypes.mousewheelEnd, function () { _this.fade(); }); } } if (interactive) { var _b = this .scroll.options, disableMouse = _b.disableMouse, disableTouch = _b.disableTouch; this .eventHandler = new EventHandler( this , { disableMouse: disableMouse, disableTouch: disableTouch, }); var eventHandlerHooks = this .eventHandler.hooks; this .registerHooks(eventHandlerHooks, eventHandlerHooks.eventTypes.touchStart, this .startHandler); this .registerHooks(eventHandlerHooks, eventHandlerHooks.eventTypes.touchMove, this .moveHandler); this .registerHooks(eventHandlerHooks, eventHandlerHooks.eventTypes.touchEnd, this .endHandler); } if (scrollbarTrackClickable) { this .bindClick(); } }; Indicator.prototype.registerHooks = function (hooks, name, handler) { hooks.on(name, handler, this ); this .hooksFn.push([hooks, name, handler]); }; Indicator.prototype.bindClick = function () { var wrapper = this .wrapper; this .clickEventRegister = new EventRegister(wrapper, [ { name: 'click' , handler: this .handleClick.bind( this ), }, ]); }; Indicator.prototype.handleClick = function (e) { var newPos = this .calculateclickOffsetPos(e); var _a = this .scroll, x = _a.x, y = _a.y; x = this .direction === "horizontal" /* Horizontal */ ? newPos : x; y = this .direction === "vertical" /* Vertical */ ? newPos : y; this .scroll.scrollTo(x, y, this .options.scrollbarTrackOffsetTime); }; Indicator.prototype.calculateclickOffsetPos = function (e) { var _a = this .keysMap, poinKey = _a.point, domRectKey = _a.domRect; var scrollbarTrackOffsetType = this .options.scrollbarTrackOffsetType; var clickPointOffset = e[poinKey] - this .wrapperRect[domRectKey]; var scrollToWhere = clickPointOffset < this .currentPos ? -1 /* Up */ : 1 /* Down */ ; var delta = 0; var currentPos = this .currentPos; if (scrollbarTrackOffsetType === "step" /* Step */ ) { delta = this .scrollInfo.baseSize * scrollToWhere; } else { delta = 0; currentPos = clickPointOffset; } return this .newPos(currentPos, delta, this .scrollInfo); }; Indicator.prototype.getKeysMap = function () { if ( this .direction === "vertical" /* Vertical */ ) { return { hasScroll: 'hasVerticalScroll' , size: 'height' , wrapperSize: 'clientHeight' , scrollerSize: 'scrollerHeight' , maxScrollPos: 'maxScrollY' , pos: 'y' , point: 'pageY' , translateProperty: 'translateY' , domRect: 'top' , }; } return { hasScroll: 'hasHorizontalScroll' , size: 'width' , wrapperSize: 'clientWidth' , scrollerSize: 'scrollerWidth' , maxScrollPos: 'maxScrollX' , pos: 'x' , point: 'pageX' , translateProperty: 'translateX' , domRect: 'left' , }; }; Indicator.prototype.fade = function (visible) { var _a = this .options, fadeInTime = _a.fadeInTime, fadeOutTime = _a.fadeOutTime; var time = visible ? fadeInTime : fadeOutTime; var wrapper = this .wrapper; wrapper.style[style.transitionDuration] = time + 'ms' ; wrapper.style.opacity = visible ? '1' : '0' ; }; Indicator.prototype.refresh = function () { var hasScrollKey = this .keysMap.hasScroll; var scroll = this .scroll; var x = scroll.x, y = scroll.y; this .wrapperRect = this .wrapper.getBoundingClientRect(); if ( this .canScroll(scroll[hasScrollKey])) { var _a = this .keysMap, wrapperSizeKey = _a.wrapperSize, scrollerSizeKey = _a.scrollerSize, maxScrollPosKey = _a.maxScrollPos; this .scrollInfo = this .refreshScrollInfo( this .wrapper[wrapperSizeKey], scroll[scrollerSizeKey], scroll[maxScrollPosKey], this .indicatorEl[wrapperSizeKey]); this .updatePosition({ x: x, y: y, }); } }; Indicator.prototype.transitionTime = function (time) { if (time === void 0) { time = 0; } this .indicatorEl.style[style.transitionDuration] = time + 'ms' ; }; Indicator.prototype.transitionTimingFunction = function (easing) { this .indicatorEl.style[style.transitionTimingFunction] = easing; }; Indicator.prototype.canScroll = function (hasScroll) { this .wrapper.style.display = hasScroll ? 'block' : 'none' ; return hasScroll; }; Indicator.prototype.refreshScrollInfo = function (wrapperSize, scrollerSize, maxScrollPos, indicatorElSize) { var baseSize = Math.max(Math.round((wrapperSize * wrapperSize) / (scrollerSize || wrapperSize || 1)), this .options.minSize); if ( this .options.isCustom) { baseSize = indicatorElSize; } var maxIndicatorScrollPos = wrapperSize - baseSize; // sizeRatio is negative var sizeRatio = maxIndicatorScrollPos / maxScrollPos; return { baseSize: baseSize, maxScrollPos: maxIndicatorScrollPos, minScrollPos: 0, sizeRatio: sizeRatio, }; }; Indicator.prototype.updatePosition = function (point) { var _a = this .caculatePosAndSize(point, this .scrollInfo), pos = _a.pos, size = _a.size; this .refreshStyle(size, pos); this .currentPos = pos; }; Indicator.prototype.caculatePosAndSize = function (point, scrollInfo) { var posKey = this .keysMap.pos; var sizeRatio = scrollInfo.sizeRatio, baseSize = scrollInfo.baseSize, maxScrollPos = scrollInfo.maxScrollPos, minScrollPos = scrollInfo.minScrollPos; var minSize = this .options.minSize; var pos = Math.round(sizeRatio * point[posKey]); var size; // when out of boundary, slow down size reduction if (pos < minScrollPos) { size = Math.max(baseSize + pos * 3, minSize); pos = minScrollPos; } else if (pos > maxScrollPos) { size = Math.max(baseSize - (pos - maxScrollPos) * 3, minSize); pos = maxScrollPos + baseSize - size; } else { size = baseSize; } return { pos: pos, size: size, }; }; Indicator.prototype.refreshStyle = function (size, pos) { var _a = this .keysMap, translatePropertyKey = _a.translateProperty, sizeKey = _a.size; var translateZ = this .scroll.options.translateZ; this .indicatorEl.style[sizeKey] = size + "px" ; this .indicatorEl.style[style.transform] = translatePropertyKey + "(" + pos + "px)" + translateZ; }; Indicator.prototype.startHandler = function () { this .moved = false ; this .startTime = getNow(); this .transitionTime(); this .scroll.scroller.hooks.trigger( this .scroll.scroller.hooks.eventTypes.beforeScrollStart); }; Indicator.prototype.moveHandler = function (delta) { if (! this .moved && ! this .indicatorNotMoved(delta)) { this .moved = true ; this .scroll.scroller.hooks.trigger( this .scroll.scroller.hooks.eventTypes.scrollStart); } if ( this .moved) { var newPos = this .newPos( this .currentPos, delta, this .scrollInfo); this .syncBScroll(newPos); } }; Indicator.prototype.endHandler = function () { if ( this .moved) { var _a = this .scroll, x = _a.x, y = _a.y; this .scroll.scroller.hooks.trigger( this .scroll.scroller.hooks.eventTypes.scrollEnd, { x: x, y: y, }); } }; Indicator.prototype.indicatorNotMoved = function (delta) { var currentPos = this .currentPos; var _a = this .scrollInfo, maxScrollPos = _a.maxScrollPos, minScrollPos = _a.minScrollPos; var notMoved = (currentPos === minScrollPos && delta <= 0) || (currentPos === maxScrollPos && delta >= 0); return notMoved; }; Indicator.prototype.syncBScroll = function (newPos) { var timestamp = getNow(); var _a = this .scroll, x = _a.x, y = _a.y, options = _a.options, scroller = _a.scroller, maxScrollY = _a.maxScrollY, minScrollY = _a.minScrollY, maxScrollX = _a.maxScrollX, minScrollX = _a.minScrollX; var probeType = options.probeType, momentumLimitTime = options.momentumLimitTime; var position = { x: x, y: y }; if ( this .direction === "vertical" /* Vertical */ ) { position.y = between(newPos, maxScrollY, minScrollY); } else { position.x = between(newPos, maxScrollX, minScrollX); } scroller.translater.translate(position); // dispatch scroll in interval time if (timestamp - this .startTime > momentumLimitTime) { this .startTime = timestamp; if (probeType === 1 /* Throttle */ ) { scroller.hooks.trigger(scroller.hooks.eventTypes.scroll, position); } } // dispatch scroll all the time if (probeType > 1 /* Throttle */ ) { scroller.hooks.trigger(scroller.hooks.eventTypes.scroll, position); } }; Indicator.prototype.newPos = function (currentPos, delta, scrollInfo) { var maxScrollPos = scrollInfo.maxScrollPos, sizeRatio = scrollInfo.sizeRatio, minScrollPos = scrollInfo.minScrollPos; var newPos = currentPos + delta; newPos = between(newPos, minScrollPos, maxScrollPos); return Math.round(newPos / sizeRatio); }; Indicator.prototype.destroy = function () { var _a = this .options, interactive = _a.interactive, scrollbarTrackClickable = _a.scrollbarTrackClickable, isCustom = _a.isCustom; if (interactive) { this .eventHandler.destroy(); } if (scrollbarTrackClickable) { this .clickEventRegister.destroy(); } if (!isCustom) { this .wrapper.parentNode.removeChild( this .wrapper); } this .hooksFn.forEach( function (item) { var hooks = item[0]; var hooksName = item[1]; var handlerFn = item[2]; hooks.off(hooksName, handlerFn); }); this .hooksFn.length = 0; }; return Indicator; }()); var ScrollBar = /** @class */ ( function () { function ScrollBar(scroll) { this .scroll = scroll; this .handleOptions(); this .createIndicators(); this .handleHooks(); } ScrollBar.prototype.handleHooks = function () { var _this = this ; var scroll = this .scroll; scroll.hooks.on(scroll.hooks.eventTypes.destroy, function () { for ( var _i = 0, _a = _this.indicators; _i < _a.length; _i++) { var indicator = _a[_i]; indicator.destroy(); } }); }; ScrollBar.prototype.handleOptions = function () { var userOptions = ( this .scroll.options.scrollbar === true ? {} : this .scroll.options.scrollbar); var defaultOptions = { fade: true , fadeInTime: 250, fadeOutTime: 500, interactive: false , customElements: [], minSize: 8, scrollbarTrackClickable: false , scrollbarTrackOffsetType: "step" /* Step */ , scrollbarTrackOffsetTime: 300, }; this .options = extend(defaultOptions, userOptions); }; ScrollBar.prototype.createIndicators = function () { var indicatorOptions; var scroll = this .scroll; var indicators = []; var scrollDirectionConfigKeys = [ 'scrollX' , 'scrollY' ]; var indicatorDirections = [ "horizontal" /* Horizontal */ , "vertical" /* Vertical */ , ]; var customScrollbarEls = this .options.customElements; for ( var i = 0; i < scrollDirectionConfigKeys.length; i++) { var key = scrollDirectionConfigKeys[i]; // wanna scroll in specified direction if (scroll.options[key]) { var customElement = customScrollbarEls.shift(); var direction = indicatorDirections[i]; var isCustom = false ; var scrollbarWrapper = customElement ? customElement : this .createScrollbarElement(direction); // internal scrollbar if (scrollbarWrapper !== customElement) { scroll.wrapper.appendChild(scrollbarWrapper); } else { // custom scrollbar passed by users isCustom = true ; } indicatorOptions = __assign(__assign({ wrapper: scrollbarWrapper, direction: direction }, this .options), { isCustom: isCustom }); indicators.push( new Indicator$1(scroll, indicatorOptions)); } } this .indicators = indicators; }; ScrollBar.prototype.createScrollbarElement = function (direction, scrollbarTrackClickable) { if (scrollbarTrackClickable === void 0) { scrollbarTrackClickable = this .options.scrollbarTrackClickable; } var scrollbarWrapperEl = document.createElement( 'div' ); var scrollbarIndicatorEl = document.createElement( 'div' ); scrollbarWrapperEl.style.cssText = 'position:absolute;z-index:9999;overflow:hidden;' ; scrollbarIndicatorEl.style.cssText = 'box-sizing:border-box;position:absolute;background:rgba(0,0,0,0.5);border:1px solid rgba(255,255,255,0.9);border-radius:3px;' ; scrollbarIndicatorEl.className = 'bscroll-indicator' ; if (direction === "horizontal" /* Horizontal */ ) { scrollbarWrapperEl.style.cssText += 'height:7px;left:2px;right:2px;bottom:0;' ; scrollbarIndicatorEl.style.height = '100%' ; scrollbarWrapperEl.className = 'bscroll-horizontal-scrollbar' ; } else { scrollbarWrapperEl.style.cssText += 'width:7px;bottom:2px;top:2px;right:1px;' ; scrollbarIndicatorEl.style.width = '100%' ; scrollbarWrapperEl.className = 'bscroll-vertical-scrollbar' ; } if (!scrollbarTrackClickable) { scrollbarWrapperEl.style.cssText += 'pointer-events:none;' ; } scrollbarWrapperEl.appendChild(scrollbarIndicatorEl); return scrollbarWrapperEl; }; ScrollBar.pluginName = 'scrollbar' ; return ScrollBar; }()); var BASE_PAGE = { pageX: 0, pageY: 0, x: 0, y: 0, }; var DEFAULT_PAGE_STATS = { x: 0, y: 0, width: 0, height: 0, cx: 0, cy: 0, }; var PagesMatrix = /** @class */ ( function () { function PagesMatrix(scroll) { this .scroll = scroll; this .init(); } PagesMatrix.prototype.init = function () { var scroller = this .scroll.scroller; var scrollBehaviorX = scroller.scrollBehaviorX, scrollBehaviorY = scroller.scrollBehaviorY; this .wrapperWidth = scrollBehaviorX.wrapperSize; this .wrapperHeight = scrollBehaviorY.wrapperSize; this .scrollerHeight = scrollBehaviorY.contentSize; this .scrollerWidth = scrollBehaviorX.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; }; PagesMatrix.prototype.getPageStats = function (pageX, pageY) { // Returns the default Stats when no Stats are retrieved // Scene: When the `content` element is an empty bounding box, the return value of the `width/height` function of el.getBoundingClientRect is 0 and pages will be calculated as an empty array. // https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect return this .pages[pageX] && this .pages[pageX][pageY] ? this .pages[pageX][pageY] : DEFAULT_PAGE_STATS; }; PagesMatrix.prototype.getNearestPageIndex = function (x, y) { var pageX = 0; var pageY = 0; var l = this .pages.length; for (; pageX < l - 1; pageX++) { if (x >= this .pages[pageX][0].cx) { break ; } } l = this .pages[pageX] ? this .pages[pageX].length : 0; for (; pageY < l - 1; pageY++) { if (y >= this .pages[0][pageY].cy) { break ; } } return { pageX: pageX, pageY: pageY, }; }; // (n x 1) matrix for horizontal scroll or // (1 * n) matrix for vertical scroll PagesMatrix.prototype.buildPagesMatrix = function (stepX, stepY) { var pages = []; var x = 0; var y; var cx; var cy; var i = 0; var l; var maxScrollPosX = this .scroll.scroller.scrollBehaviorX.maxScrollPos; var maxScrollPosY = this .scroll.scroller.scrollBehaviorY.maxScrollPos; cx = Math.round(stepX / 2); cy = Math.round(stepY / 2); while (x > - this .scrollerWidth) { pages[i] = []; l = 0; y = 0; while (y > - this .scrollerHeight) { pages[i][l] = { x: Math.max(x, maxScrollPosX), y: Math.max(y, maxScrollPosY), width: stepX, height: stepY, cx: x - cx, cy: y - cy, }; y -= stepY; l++; } x -= stepX; i++; } return pages; }; return PagesMatrix; }()); var SlidePages = /** @class */ ( function () { function SlidePages(scroll, slideOptions) { this .scroll = scroll; this .slideOptions = slideOptions; this .slideX = false ; this .slideY = false ; this .currentPage = extend({}, BASE_PAGE); } SlidePages.prototype.refresh = function () { this .pagesMatrix = new PagesMatrix( this .scroll); this .checkSlideLoop(); this .currentPage = this .getAdjustedCurrentPage(); }; SlidePages.prototype.getAdjustedCurrentPage = function () { var _a = this .currentPage, pageX = _a.pageX, pageY = _a.pageY; // page index should be handled // because page counts may reduce pageX = Math.min(pageX, this .pagesMatrix.pageLengthOfX - 1); pageY = Math.min(pageY, this .pagesMatrix.pageLengthOfY - 1); // loop scene should also be respected // because clonedNode will cause pageLength increasing if ( this .loopX) { pageX = Math.min(pageX, this .pagesMatrix.pageLengthOfX - 2); } if ( this .loopY) { pageY = Math.min(pageY, this .pagesMatrix.pageLengthOfY - 2); } var _b = this .pagesMatrix.getPageStats(pageX, pageY), x = _b.x, y = _b.y; return { pageX: pageX, pageY: pageY, x: x, y: y }; }; SlidePages.prototype.setCurrentPage = function (newPage) { this .currentPage = newPage; }; SlidePages.prototype.getInternalPage = function (pageX, pageY) { if (pageX >= this .pagesMatrix.pageLengthOfX) { pageX = this .pagesMatrix.pageLengthOfX - 1; } else if (pageX < 0) { pageX = 0; } if (pageY >= this .pagesMatrix.pageLengthOfY) { pageY = this .pagesMatrix.pageLengthOfY - 1; } else if (pageY < 0) { pageY = 0; } var _a = this .pagesMatrix.getPageStats(pageX, pageY), x = _a.x, y = _a.y; return { pageX: pageX, pageY: pageY, x: x, y: y, }; }; SlidePages.prototype.getInitialPage = function (showFirstPage, firstInitialised) { if (showFirstPage === void 0) { showFirstPage = false ; } if (firstInitialised === void 0) { firstInitialised = false ; } var _a = this .slideOptions, startPageXIndex = _a.startPageXIndex, startPageYIndex = _a.startPageYIndex; var firstPageX = this .loopX ? 1 : 0; var firstPageY = this .loopY ? 1 : 0; var pageX = showFirstPage ? firstPageX : this .currentPage.pageX; var pageY = showFirstPage ? firstPageY : this .currentPage.pageY; if (firstInitialised) { pageX = this .loopX ? startPageXIndex + 1 : startPageXIndex; pageY = this .loopY ? startPageYIndex + 1 : startPageYIndex; } else { pageX = showFirstPage ? firstPageX : this .currentPage.pageX; pageY = showFirstPage ? firstPageY : this .currentPage.pageY; } var _b = this .pagesMatrix.getPageStats(pageX, pageY), x = _b.x, y = _b.y; return { pageX: pageX, pageY: pageY, x: x, y: y, }; }; SlidePages.prototype.getExposedPage = function (page) { var exposedPage = extend({}, page); // only pageX or pageY need fix if ( this .loopX) { exposedPage.pageX = this .fixedPage(exposedPage.pageX, this .pagesMatrix.pageLengthOfX - 2); } if ( this .loopY) { exposedPage.pageY = this .fixedPage(exposedPage.pageY, this .pagesMatrix.pageLengthOfY - 2); } return exposedPage; }; SlidePages.prototype.getExposedPageByPageIndex = function (pageIndexX, pageIndexY) { var page = { pageX: pageIndexX, pageY: pageIndexY, }; if ( this .loopX) { page.pageX = pageIndexX + 1; } if ( this .loopY) { page.pageY = pageIndexY + 1; } var _a = this .pagesMatrix.getPageStats(page.pageX, page.pageY), x = _a.x, y = _a.y; return { x: x, y: y, pageX: pageIndexX, pageY: pageIndexY, }; }; SlidePages.prototype.getWillChangedPage = function (page) { page = extend({}, page); // Page need fix if ( this .loopX) { page.pageX = this .fixedPage(page.pageX, this .pagesMatrix.pageLengthOfX - 2); page.x = this .pagesMatrix.getPageStats(page.pageX + 1, 0).x; } if ( this .loopY) { page.pageY = this .fixedPage(page.pageY, this .pagesMatrix.pageLengthOfY - 2); page.y = this .pagesMatrix.getPageStats(0, page.pageY + 1).y; } return page; }; SlidePages.prototype.fixedPage = function (page, realPageLen) { var pageIndex = []; for ( var i = 0; i < realPageLen; i++) { pageIndex.push(i); } pageIndex.unshift(realPageLen - 1); pageIndex.push(0); return pageIndex[page]; }; SlidePages.prototype.getPageStats = function () { return this .pagesMatrix.getPageStats( this .currentPage.pageX, this .currentPage.pageY); }; SlidePages.prototype.getValidPageIndex = function (x, y) { var lastX = this .pagesMatrix.pageLengthOfX - 1; var lastY = this .pagesMatrix.pageLengthOfY - 1; var firstX = 0; var firstY = 0; if ( this .loopX) { x += 1; firstX = firstX + 1; lastX = lastX - 1; } if ( this .loopY) { y += 1; firstY = firstY + 1; lastY = lastY - 1; } x = between(x, firstX, lastX); y = between(y, firstY, lastY); return { pageX: x, pageY: y, }; }; SlidePages.prototype.nextPageIndex = function () { return this .getPageIndexByDirection( "positive" /* Positive */ ); }; SlidePages.prototype.prevPageIndex = function () { return this .getPageIndexByDirection( "negative" /* Negative */ ); }; SlidePages.prototype.getNearestPage = function (x, y) { var pageIndex = this .pagesMatrix.getNearestPageIndex(x, y); var pageX = pageIndex.pageX, pageY = pageIndex.pageY; var newX = this .pagesMatrix.getPageStats(pageX, 0).x; var newY = this .pagesMatrix.getPageStats(0, pageY).y; return { x: newX, y: newY, pageX: pageX, pageY: pageY, }; }; SlidePages.prototype.getPageByDirection = function (page, directionX, directionY) { var pageX = page.pageX, pageY = page.pageY; if (pageX === this .currentPage.pageX) { pageX = between(pageX + directionX, 0, this .pagesMatrix.pageLengthOfX - 1); } if (pageY === this .currentPage.pageY) { pageY = between(pageY + directionY, 0, this .pagesMatrix.pageLengthOfY - 1); } var x = this .pagesMatrix.getPageStats(pageX, 0).x; var y = this .pagesMatrix.getPageStats(0, pageY).y; return { x: x, y: y, pageX: pageX, pageY: pageY, }; }; SlidePages.prototype.resetLoopPage = function () { if ( this .loopX) { if ( this .currentPage.pageX === 0) { 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 ( this .currentPage.pageY === 0) { 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, }; } } }; SlidePages.prototype.getPageIndexByDirection = function (direction) { var x = this .currentPage.pageX; var y = this .currentPage.pageY; if ( this .slideX) { x = direction === "negative" /* Negative */ ? x - 1 : x + 1; } if ( this .slideY) { y = direction === "negative" /* Negative */ ? y - 1 : y + 1; } return { pageX: x, pageY: y, }; }; SlidePages.prototype.checkSlideLoop = function () { this .wannaLoop = this .slideOptions.loop; if ( this .pagesMatrix.pageLengthOfX > 1) { this .slideX = true ; } else { this .slideX = false ; } if ( this .pagesMatrix.pages[0] && this .pagesMatrix.pageLengthOfY > 1) { this .slideY = true ; } else { this .slideY = false ; } this .loopX = this .wannaLoop && this .slideX; this .loopY = this .wannaLoop && this .slideY; if ( this .slideX && this .slideY) { warn( 'slide does not support two direction at the same time.' ); } }; return SlidePages; }()); var sourcePrefix$4 = 'plugins.slide' ; var propertiesMap$4 = [ { key: 'next' , name: 'next' , }, { key: 'prev' , name: 'prev' , }, { key: 'goToPage' , name: 'goToPage' , }, { key: 'getCurrentPage' , name: 'getCurrentPage' , }, { key: 'startPlay' , name: 'startPlay' , }, { key: 'pausePlay' , name: 'pausePlay' , }, ]; var propertiesConfig$4 = propertiesMap$4.map( function (item) { return { key: item.key, sourceKey: sourcePrefix$4 + "." + item.name, }; }); var samePage = function (p1, p2) { return p1.pageX === p2.pageX && p1.pageY === p2.pageY; }; var Slide = /** @class */ ( function () { function Slide(scroll) { this .scroll = scroll; this .cachedClonedPageDOM = []; this .resetLooping = false ; this .autoplayTimer = 0; if (! this .satisfyInitialization()) { return ; } this .init(); } Slide.prototype.satisfyInitialization = function () { if ( this .scroll.scroller.content.children.length <= 0) { warn( "slide need at least one slide page to be initialised." + "please check your DOM layout." ); return false ; } return true ; }; Slide.prototype.init = function () { this .willChangeToPage = extend({}, BASE_PAGE); this .handleBScroll(); this .handleOptions(); this .handleHooks(); this .createPages(); }; Slide.prototype.createPages = function () { this .pages = new SlidePages( this .scroll, this .options); }; Slide.prototype.handleBScroll = function () { this .scroll.registerType([ 'slideWillChange' , 'slidePageChanged' ]); this .scroll.proxy(propertiesConfig$4); }; Slide.prototype.handleOptions = function () { var userOptions = ( this .scroll.options.slide === true ? {} : this .scroll.options.slide); var defaultOptions = { loop: true , threshold: 0.1, speed: 400, easing: ease.bounce, listenFlick: true , autoplay: true , interval: 3000, startPageXIndex: 0, startPageYIndex: 0, }; this .options = extend(defaultOptions, userOptions); }; Slide.prototype.handleLoop = function (prevSlideContent) { var loop = this .options.loop; var slideContent = this .scroll.scroller.content; var currentSlidePagesLength = slideContent.children.length; // only should respect loop scene if (loop) { if (slideContent !== prevSlideContent) { this .resetLoopChangedStatus(); this .removeClonedSlidePage(prevSlideContent); currentSlidePagesLength > 1 && this .cloneFirstAndLastSlidePage(slideContent); } else { // many pages reduce to one page if (currentSlidePagesLength === 3 && this .initialised) { this .removeClonedSlidePage(slideContent); this .moreToOnePageInLoop = true ; this .oneToMorePagesInLoop = false ; } else if (currentSlidePagesLength > 1) { // one page increases to many page if ( this .initialised && this .cachedClonedPageDOM.length === 0) { this .oneToMorePagesInLoop = true ; this .moreToOnePageInLoop = false ; } else { this .removeClonedSlidePage(slideContent); this .resetLoopChangedStatus(); } this .cloneFirstAndLastSlidePage(slideContent); } else { this .resetLoopChangedStatus(); } } } }; Slide.prototype.resetLoopChangedStatus = function () { this .moreToOnePageInLoop = false ; this .oneToMorePagesInLoop = false ; }; Slide.prototype.handleHooks = function () { var _this = this ; var scrollHooks = this .scroll.hooks; var scrollerHooks = this .scroll.scroller.hooks; var listenFlick = this .options.listenFlick; this .prevContent = this .scroll.scroller.content; this .hooksFn = []; // scroll 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); // for mousewheel event if ( this .scroll.eventTypes.mousewheelMove) { this .registerHooks( this .scroll, this .scroll.eventTypes.mousewheelMove, function () { // prevent default action of mousewheelMove return true ; }); this .registerHooks( this .scroll, this .scroll.eventTypes.mousewheelEnd, function (delta) { if (delta.directionX === 1 /* Positive */ || delta.directionY === 1 /* Positive */ ) { _this.next(); } if (delta.directionX === -1 /* Negative */ || delta.directionY === -1 /* Negative */ ) { _this.prev(); } }); } // scrollHooks this .registerHooks(scrollHooks, scrollHooks.eventTypes.refresh, this .refreshHandler); this .registerHooks(scrollHooks, scrollHooks.eventTypes.destroy, this .destroy); // scroller this .registerHooks(scrollerHooks, scrollerHooks.eventTypes.beforeRefresh, function () { _this.handleLoop(_this.prevContent); _this.setSlideInlineStyle(); }); this .registerHooks(scrollerHooks, scrollerHooks.eventTypes.momentum, this .modifyScrollMetaHandler); this .registerHooks(scrollerHooks, scrollerHooks.eventTypes.scroll, this .scrollHandler); // a click operation will clearTimer, so restart a new one this .registerHooks(scrollerHooks, scrollerHooks.eventTypes.checkClick, this .startPlay); if (listenFlick) { this .registerHooks(scrollerHooks, scrollerHooks.eventTypes.flick, this .flickHandler); } }; Slide.prototype.startPlay = function () { var _this = this ; var _a = this .options, interval = _a.interval, autoplay = _a.autoplay; if (autoplay) { clearTimeout( this .autoplayTimer); this .autoplayTimer = window.setTimeout( function () { _this.next(); }, interval); } }; Slide.prototype.pausePlay = function () { if ( this .options.autoplay) { clearTimeout( this .autoplayTimer); } }; Slide.prototype.setSlideInlineStyle = function () { var styleConfigurations = [ { direction: 'scrollX' , sizeType: 'offsetWidth' , styleType: 'width' , }, { direction: 'scrollY' , sizeType: 'offsetHeight' , styleType: 'height' , }, ]; var _a = this .scroll.scroller, slideContent = _a.content, slideWrapper = _a.wrapper; var scrollOptions = this .scroll.options; styleConfigurations.forEach( function (_a) { var direction = _a.direction, sizeType = _a.sizeType, styleType = _a.styleType; // wanna scroll in this direction if (scrollOptions[direction]) { var size = slideWrapper[sizeType]; var children = slideContent.children; var length_1 = children.length; for ( var i = 0; i < length_1; i++) { var slidePageDOM = children[i]; slidePageDOM.style[styleType] = size + 'px' ; } slideContent.style[styleType] = size * length_1 + 'px' ; } }); }; Slide.prototype.next = function (time, easing) { var _a = this .pages.nextPageIndex(), pageX = _a.pageX, pageY = _a.pageY; this .goTo(pageX, pageY, time, easing); }; Slide.prototype.prev = function (time, easing) { var _a = this .pages.prevPageIndex(), pageX = _a.pageX, pageY = _a.pageY; this .goTo(pageX, pageY, time, easing); }; Slide.prototype.goToPage = function (pageX, pageY, time, easing) { var pageIndex = this .pages.getValidPageIndex(pageX, pageY); this .goTo(pageIndex.pageX, pageIndex.pageY, time, easing); }; Slide.prototype.getCurrentPage = function () { return this .exposedPage || this .pages.getInitialPage( false , true ); }; Slide.prototype.setCurrentPage = function (page) { this .pages.setCurrentPage(page); this .exposedPage = this .pages.getExposedPage(page); }; Slide.prototype.nearestPage = function (x, y) { var _a = this .scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY; var maxScrollPosX = scrollBehaviorX.maxScrollPos, minScrollPosX = scrollBehaviorX.minScrollPos; var maxScrollPosY = scrollBehaviorY.maxScrollPos, minScrollPosY = scrollBehaviorY.minScrollPos; return this .pages.getNearestPage(between(x, maxScrollPosX, minScrollPosX), between(y, maxScrollPosY, minScrollPosY)); }; Slide.prototype.satisfyThreshold = function (x, y) { var _a = this .scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY; var satisfied = true ; if (Math.abs(x - scrollBehaviorX.absStartPos) <= this .thresholdX && Math.abs(y - scrollBehaviorY.absStartPos) <= this .thresholdY) { satisfied = false ; } return satisfied; }; Slide.prototype.refreshHandler = function (content) { var _this = this ; if (! this .satisfyInitialization()) { return ; } this .pages.refresh(); this .computeThreshold(); var contentChanged = ( this .contentChanged = this .prevContent !== content); if (contentChanged) { this .prevContent = content; } var initPage = this .pages.getInitialPage( this .oneToMorePagesInLoop || this .moreToOnePageInLoop, contentChanged || ! this .initialised); if ( this .initialised) { this .goTo(initPage.pageX, initPage.pageY, 0); } else { this .registerHooks( this .scroll.hooks, this .scroll.hooks.eventTypes.beforeInitialScrollTo, function (position) { _this.initialised = true ; position.x = initPage.x; position.y = initPage.y; }); } this .startPlay(); }; Slide.prototype.computeThreshold = function () { var threshold = this .options.threshold; // Integer if (threshold % 1 === 0) { this .thresholdX = threshold; this .thresholdY = threshold; } else { // decimal var _a = this .pages.getPageStats(), width = _a.width, height = _a.height; this .thresholdX = Math.round(width * threshold); this .thresholdY = Math.round(height * threshold); } }; Slide.prototype.cloneFirstAndLastSlidePage = function (slideContent) { var children = slideContent.children; var preprendDOM = children[children.length - 1].cloneNode( true ); var appendDOM = children[0].cloneNode( true ); prepend(preprendDOM, slideContent); slideContent.appendChild(appendDOM); this .cachedClonedPageDOM = [preprendDOM, appendDOM]; }; Slide.prototype.removeClonedSlidePage = function (slideContent) { // maybe slideContent has removed from DOM Tree var slidePages = (slideContent && slideContent.children) || []; if (slidePages.length) { this .cachedClonedPageDOM.forEach( function (el) { removeChild(slideContent, el); }); } this .cachedClonedPageDOM = []; }; Slide.prototype.modifyCurrentPage = function (point) { var _a = this .getCurrentPage(), prevExposedPageX = _a.pageX, prevExposedPageY = _a.pageY; var newPage = this .nearestPage(point.x, point.y); this .setCurrentPage(newPage); /* istanbul ignore if */ if ( this .contentChanged) { this .contentChanged = false ; return true ; } var _b = this .getCurrentPage(), currentExposedPageX = _b.pageX, currentExposedPageY = _b.pageY; this .pageWillChangeTo(newPage); // loop is true, and one page becomes many pages when call bs.refresh if ( this .oneToMorePagesInLoop) { this .oneToMorePagesInLoop = false ; return true ; } // loop is true, and many page becomes one page when call bs.refresh // if prevPage > 0, dispatch slidePageChanged and scrollEnd events /* istanbul ignore if */ if ( this .moreToOnePageInLoop && prevExposedPageX === 0 && prevExposedPageY === 0) { this .moreToOnePageInLoop = false ; return true ; } if (prevExposedPageX !== currentExposedPageX || prevExposedPageY !== currentExposedPageY) { // only trust pageX & pageY when loop is true var page = this .pages.getExposedPageByPageIndex(currentExposedPageX, currentExposedPageY); this .scroll.trigger( this .scroll.eventTypes.slidePageChanged, page); } // triggered by resetLoop if ( this .resetLooping) { this .resetLooping = false ; return ; } var changePage = this .pages.resetLoopPage(); if (changePage) { this .resetLooping = true ; this .goTo(changePage.pageX, changePage.pageY, 0); // stop user's scrollEnd // since it is a seamless scroll return true ; } }; Slide.prototype.goTo = function (pageX, pageY, time, easing) { var newPage = this .pages.getInternalPage(pageX, pageY); var scrollEasing = easing || this .options.easing || ease.bounce; var x = newPage.x, y = newPage.y; var deltaX = x - this .scroll.scroller.scrollBehaviorX.currentPos; var deltaY = y - this .scroll.scroller.scrollBehaviorY.currentPos; /* istanbul ignore if */ if (!deltaX && !deltaY) { this .scroll.scroller.togglePointerEvents( true ); return ; } time = time === undefined ? this .getEaseTime(deltaX, deltaY) : time; this .scroll.scroller.scrollTo(x, y, time, scrollEasing); }; Slide.prototype.flickHandler = function () { var _a = this .scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY; var currentPosX = scrollBehaviorX.currentPos, startPosX = scrollBehaviorX.startPos, directionX = scrollBehaviorX.direction; var currentPosY = scrollBehaviorY.currentPos, startPosY = scrollBehaviorY.startPos, directionY = scrollBehaviorY.direction; var _b = this .pages.currentPage, pageX = _b.pageX, pageY = _b.pageY; var time = this .getEaseTime(currentPosX - startPosX, currentPosY - startPosY); this .goTo(pageX + directionX, pageY + directionY, time); }; Slide.prototype.getEaseTime = function (deltaX, deltaY) { return ( this .options.speed || Math.max(Math.max(Math.min(Math.abs(deltaX), 1000), Math.min(Math.abs(deltaY), 1000)), 300)); }; Slide.prototype.modifyScrollMetaHandler = function (scrollMeta) { var _a = this .scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY, animater = _a.animater; var newX = scrollMeta.newX; var newY = scrollMeta.newY; var newPage = this .satisfyThreshold(newX, newY) || animater.forceStopped ? this .pages.getPageByDirection( this .nearestPage(newX, newY), scrollBehaviorX.direction, scrollBehaviorY.direction) : this .pages.currentPage; scrollMeta.time = this .getEaseTime(scrollMeta.newX - newPage.x, scrollMeta.newY - newPage.y); scrollMeta.newX = newPage.x; scrollMeta.newY = newPage.y; scrollMeta.easing = this .options.easing || ease.bounce; }; Slide.prototype.scrollHandler = function (_a) { var x = _a.x, y = _a.y; if ( this .satisfyThreshold(x, y)) { var newPage = this .nearestPage(x, y); this .pageWillChangeTo(newPage); } }; Slide.prototype.pageWillChangeTo = function (newPage) { var changeToPage = this .pages.getWillChangedPage(newPage); if (!samePage( this .willChangeToPage, changeToPage)) { this .willChangeToPage = changeToPage; this .scroll.trigger( this .scroll.eventTypes.slideWillChange, this .willChangeToPage); } }; Slide.prototype.registerHooks = function (hooks, name, handler) { hooks.on(name, handler, this ); this .hooksFn.push([hooks, name, handler]); }; Slide.prototype.destroy = function () { var slideContent = this .scroll.scroller.content; var _a = this .options, loop = _a.loop, autoplay = _a.autoplay; if (loop) { this .removeClonedSlidePage(slideContent); } if (autoplay) { clearTimeout( this .autoplayTimer); } this .hooksFn.forEach( function (item) { var hooks = item[0]; var hooksName = item[1]; var handlerFn = item[2]; if (hooks.eventTypes[hooksName]) { hooks.off(hooksName, handlerFn); } }); this .hooksFn.length = 0; }; Slide.pluginName = 'slide '; return Slide; }()); var sourcePrefix$3 = ' plugins.wheel '; var propertiesMap$3 = [ { key: ' wheelTo ', name: ' wheelTo ', }, { key: ' getSelectedIndex ', name: ' getSelectedIndex ', }, { key: ' restorePosition ', name: ' restorePosition ', }, ]; var propertiesConfig$3 = propertiesMap$3.map(function (item) { return { key: item.key, sourceKey: sourcePrefix$3 + "." + item.name, }; }); var WHEEL_INDEX_CHANGED_EVENT_NAME = ' wheelIndexChanged '; var CONSTANTS = { rate: 4 }; var Wheel = /** @class */ (function () { function Wheel(scroll) { this.scroll = scroll; this.init(); } Wheel.prototype.init = function () { this.handleBScroll(); this.handleOptions(); this.handleHooks(); // init boundary for Wheel this.refreshBoundary(); this.setSelectedIndex(this.options.selectedIndex); }; Wheel.prototype.handleBScroll = function () { this.scroll.proxy(propertiesConfig$3); this.scroll.registerType([WHEEL_INDEX_CHANGED_EVENT_NAME]); }; Wheel.prototype.handleOptions = function () { var userOptions = (this.scroll.options.wheel === true ? {} : this.scroll.options.wheel); var defaultOptions = { wheelWrapperClass: ' wheel-scroll ', wheelItemClass: ' wheel-item ', rotate: 25, adjustTime: 400, selectedIndex: 0, wheelDisabledItemClass: ' wheel-disabled-item ' }; this.options = extend(defaultOptions, userOptions); }; Wheel.prototype.handleHooks = function () { var _this = this; var scroll = this.scroll; var scroller = this.scroll.scroller; var actionsHandler = scroller.actionsHandler, scrollBehaviorX = scroller.scrollBehaviorX, scrollBehaviorY = scroller.scrollBehaviorY, animater = scroller.animater; var prevContent = scroller.content; // BScroll scroll.on(scroll.eventTypes.scrollEnd, function (position) { var index = _this.findNearestValidWheel(position.y).index; if (scroller.animater.forceStopped && !_this.isAdjustingPosition) { _this.target = _this.items[index]; // since stopped from an animation. // prevent user' s scrollEnd callback triggered twice return true ; } else { _this.setSelectedIndex(index); if (_this.isAdjustingPosition) { _this.isAdjustingPosition = false ; } } }); // BScroll.hooks this .scroll.hooks.on( this .scroll.hooks.eventTypes.refresh, function (content) { if (content !== prevContent) { prevContent = content; _this.setSelectedIndex(_this.options.selectedIndex, true ); } // rotate all wheel-items // because position may not change _this.rotateX(_this.scroll.y); // check we are stop at a disable item or not _this.wheelTo(_this.selectedIndex, 0); }); this .scroll.hooks.on( this .scroll.hooks.eventTypes.beforeInitialScrollTo, function (position) { // selectedIndex has higher priority than bs.options.startY position.x = 0; position.y = -(_this.selectedIndex * _this.itemHeight); }); // Scroller scroller.hooks.on(scroller.hooks.eventTypes.checkClick, function () { var index = HTMLCollectionToArray(_this.items).indexOf(_this.target); if (index === -1) return true ; _this.wheelTo(index, _this.options.adjustTime, ease.swipe); return true ; }); scroller.hooks.on(scroller.hooks.eventTypes.scrollTo, function (endPoint) { endPoint.y = _this.findNearestValidWheel(endPoint.y).y; }); // when content is scrolling // click wheel-item DOM repeatedly and crazily will cause scrollEnd not triggered // so reset forceStopped scroller.hooks.on(scroller.hooks.eventTypes.minDistanceScroll, function () { var animater = scroller.animater; if (animater.forceStopped === true ) { animater.forceStopped = false ; } }); scroller.hooks.on(scroller.hooks.eventTypes.scrollToElement, function (el, pos) { if (!hasClass(el, _this.options.wheelItemClass)) { return true ; } else { pos.top = _this.findNearestValidWheel(pos.top).y; } }); // ActionsHandler actionsHandler.hooks.on(actionsHandler.hooks.eventTypes.beforeStart, function (e) { _this.target = e.target; }); // ScrollBehaviorX // Wheel has no x direction now scrollBehaviorX.hooks.on(scrollBehaviorX.hooks.eventTypes.computeBoundary, function (boundary) { boundary.maxScrollPos = 0; boundary.minScrollPos = 0; }); // ScrollBehaviorY scrollBehaviorY.hooks.on(scrollBehaviorY.hooks.eventTypes.computeBoundary, function (boundary) { _this.items = _this.scroll.scroller.content.children; _this.checkWheelAllDisabled(); _this.itemHeight = _this.items.length > 0 ? scrollBehaviorY.contentSize / _this.items.length : 0; boundary.maxScrollPos = -_this.itemHeight * (_this.items.length - 1); boundary.minScrollPos = 0; }); scrollBehaviorY.hooks.on(scrollBehaviorY.hooks.eventTypes.momentum, function (momentumInfo) { momentumInfo.rate = CONSTANTS.rate; momentumInfo.destination = _this.findNearestValidWheel(momentumInfo.destination).y; }); scrollBehaviorY.hooks.on(scrollBehaviorY.hooks.eventTypes.end, function (momentumInfo) { var validWheel = _this.findNearestValidWheel(scrollBehaviorY.currentPos); momentumInfo.destination = validWheel.y; momentumInfo.duration = _this.options.adjustTime; }); // Animater animater.hooks.on(animater.hooks.eventTypes.time, function (time) { _this.transitionDuration(time); }); animater.hooks.on(animater.hooks.eventTypes.timeFunction, function (easing) { _this.timeFunction(easing); }); // bs.stop() to make wheel stop at a correct position when pending animater.hooks.on(animater.hooks.eventTypes.callStop, function () { var index = _this.findNearestValidWheel(_this.scroll.y).index; _this.isAdjustingPosition = true ; _this.wheelTo(index, 0); }); // Translater animater.translater.hooks.on(animater.translater.hooks.eventTypes.translate, function (endPoint) { _this.rotateX(endPoint.y); }); }; Wheel.prototype.refreshBoundary = function () { var _a = this .scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY, content = _a.content; scrollBehaviorX.refresh(content); scrollBehaviorY.refresh(content); }; Wheel.prototype.setSelectedIndex = function (index, contentChanged) { if (contentChanged === void 0) { contentChanged = false ; } var prevSelectedIndex = this .selectedIndex; this .selectedIndex = index; // if content DOM changed, should not trigger event if (prevSelectedIndex !== index && !contentChanged) { this .scroll.trigger(WHEEL_INDEX_CHANGED_EVENT_NAME, index); } }; Wheel.prototype.getSelectedIndex = function () { return this .selectedIndex; }; Wheel.prototype.wheelTo = function (index, time, ease) { if (index === void 0) { index = 0; } if (time === void 0) { time = 0; } var y = -index * this .itemHeight; this .scroll.scrollTo(0, y, time, ease); }; Wheel.prototype.restorePosition = function () { // bs is scrolling var isPending = this .scroll.pending; if (isPending) { var selectedIndex = this .getSelectedIndex(); this .scroll.scroller.animater.clearTimer(); this .wheelTo(selectedIndex, 0); } }; Wheel.prototype.transitionDuration = function (time) { for ( var i = 0; i < this .items.length; i++) { this .items[i].style[style.transitionDuration] = time + 'ms' ; } }; Wheel.prototype.timeFunction = function (easing) { for ( var i = 0; i < this .items.length; i++) { this .items[i].style[style.transitionTimingFunction] = easing; } }; Wheel.prototype.rotateX = function (y) { var _a = this .options.rotate, rotate = _a === void 0 ? 25 : _a; for ( var i = 0; i < this .items.length; i++) { var deg = rotate * (y / this .itemHeight + i); // Too small value is invalid in some phones, issue 1026 var SafeDeg = deg.toFixed(3); this .items[i].style[style.transform] = "rotateX(" + SafeDeg + "deg)" ; } }; Wheel.prototype.findNearestValidWheel = function (y) { y = y > 0 ? 0 : y < this .scroll.maxScrollY ? this .scroll.maxScrollY : y; var currentIndex = Math.abs(Math.round(-y / this .itemHeight)); var cacheIndex = currentIndex; var items = this .items; var wheelDisabledItemClassName = this .options .wheelDisabledItemClass; // implement web native select element // first, check whether there is a enable item whose index is smaller than currentIndex // then, check whether there is a enable item whose index is bigger than currentIndex // otherwise, there are all disabled items, just keep currentIndex unchange while (currentIndex >= 0) { if (!hasClass(items[currentIndex], wheelDisabledItemClassName)) { break ; } currentIndex--; } if (currentIndex < 0) { currentIndex = cacheIndex; while (currentIndex <= items.length - 1) { if (!hasClass(items[currentIndex], wheelDisabledItemClassName)) { break ; } currentIndex++; } } // keep it unchange when all the items are disabled if (currentIndex === items.length) { currentIndex = cacheIndex; } // when all the items are disabled, selectedIndex should always be -1 return { index: this .wheelItemsAllDisabled ? -1 : currentIndex, y: -currentIndex * this .itemHeight }; }; Wheel.prototype.checkWheelAllDisabled = function () { var wheelDisabledItemClassName = this .options.wheelDisabledItemClass; var items = this .items; this .wheelItemsAllDisabled = true ; for ( var i = 0; i < items.length; i++) { if (!hasClass(items[i], wheelDisabledItemClassName)) { this .wheelItemsAllDisabled = false ; break ; } } }; Wheel.pluginName = 'wheel' ; return Wheel; }()); var sourcePrefix$2 = 'plugins.zoom' ; var propertiesMap$2 = [ { key: 'zoomTo' , name: 'zoomTo' } ]; var propertiesConfig$2 = propertiesMap$2.map( function (item) { return { key: item.key, sourceKey: sourcePrefix$2 + "." + item.name }; }); var TWO_FINGERS = 2; var RAW_SCALE = 1; var Zoom = /** @class */ ( function () { function Zoom(scroll) { this .scroll = scroll; this .scale = RAW_SCALE; this .prevScale = 1; this .init(); } Zoom.prototype.init = function () { this .handleBScroll(); this .handleOptions(); this .handleHooks(); this .tryInitialZoomTo( this .zoomOpt); }; Zoom.prototype.zoomTo = function (scale, x, y, bounceTime) { var _a = this .resolveOrigin(x, y), originX = _a.originX, originY = _a.originY; var origin = { x: originX, y: originY, baseScale: this .scale, }; this ._doZoomTo(scale, origin, bounceTime, true ); }; Zoom.prototype.handleBScroll = function () { this .scroll.proxy(propertiesConfig$2); this .scroll.registerType([ 'beforeZoomStart' , 'zoomStart' , 'zooming' , 'zoomEnd' , ]); }; Zoom.prototype.handleOptions = function () { var userOptions = ( this .scroll.options.zoom === true ? {} : this .scroll.options.zoom); var defaultOptions = { start: 1, min: 1, max: 4, initialOrigin: [0, 0], minimalZoomDistance: 5, bounceTime: 800, }; this .zoomOpt = extend(defaultOptions, userOptions); }; Zoom.prototype.handleHooks = function () { var _this = this ; var scroll = this .scroll; var scroller = this .scroll.scroller; this .wrapper = this .scroll.scroller.wrapper; this .setTransformOrigin( this .scroll.scroller.content); var scrollBehaviorX = scroller.scrollBehaviorX; var scrollBehaviorY = scroller.scrollBehaviorY; this .hooksFn = []; // BScroll this .registerHooks(scroll.hooks, scroll.hooks.eventTypes.contentChanged, function (content) { _this.setTransformOrigin(content); _this.scale = RAW_SCALE; _this.tryInitialZoomTo(_this.zoomOpt); }); this .registerHooks(scroll.hooks, scroll.hooks.eventTypes.beforeInitialScrollTo, function () { // if perform a zoom action, we should prevent initial scroll when initialised if (_this.zoomOpt.start !== RAW_SCALE) { return true ; } }); // enlarge boundary this .registerHooks(scrollBehaviorX.hooks, scrollBehaviorX.hooks.eventTypes.beforeComputeBoundary, function () { // content may change, don't cache it's size var contentSize = getRect(_this.scroll.scroller.content); scrollBehaviorX.contentSize = Math.floor(contentSize.width * _this.scale); }); this .registerHooks(scrollBehaviorY.hooks, scrollBehaviorY.hooks.eventTypes.beforeComputeBoundary, function () { // content may change, don't cache it's size var contentSize = getRect(_this.scroll.scroller.content); scrollBehaviorY.contentSize = Math.floor(contentSize.height * _this.scale); }); // touch event this .registerHooks(scroller.actions.hooks, scroller.actions.hooks.eventTypes.start, function (e) { var numberOfFingers = (e.touches && e.touches.length) || 0; _this.fingersOperation(numberOfFingers); if (numberOfFingers === TWO_FINGERS) { _this.zoomStart(e); } }); this .registerHooks(scroller.actions.hooks, scroller.actions.hooks.eventTypes.beforeMove, function (e) { var numberOfFingers = (e.touches && e.touches.length) || 0; _this.fingersOperation(numberOfFingers); if (numberOfFingers === TWO_FINGERS) { _this.zoom(e); return true ; } }); this .registerHooks(scroller.actions.hooks, scroller.actions.hooks.eventTypes.beforeEnd, function (e) { var numberOfFingers = _this.fingersOperation(); if (numberOfFingers === TWO_FINGERS) { _this.zoomEnd(); return true ; } }); this .registerHooks(scroller.translater.hooks, scroller.translater.hooks.eventTypes.beforeTranslate, function (transformStyle, point) { var scale = point.scale ? point.scale : _this.prevScale; _this.prevScale = scale; transformStyle.push( "scale(" + scale + ")" ); }); this .registerHooks(scroller.hooks, scroller.hooks.eventTypes.scrollEnd, function () { if (_this.fingersOperation() === TWO_FINGERS) { _this.scroll.trigger(_this.scroll.eventTypes.zoomEnd, { scale: _this.scale, }); } }); this .registerHooks( this .scroll.hooks, 'destroy' , this .destroy); }; Zoom.prototype.setTransformOrigin = function (content) { content.style[style.transformOrigin] = '0 0' ; }; Zoom.prototype.tryInitialZoomTo = function (options) { var start = options.start, initialOrigin = options.initialOrigin; var _a = this .scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY; if (start !== RAW_SCALE) { // Movable plugin may wanna modify minScrollPos or maxScrollPos // so we force Movable to caculate them this .resetBoundaries([scrollBehaviorX, scrollBehaviorY]); this .zoomTo(start, initialOrigin[0], initialOrigin[1], 0); } }; // getter or setter operation Zoom.prototype.fingersOperation = function (amounts) { if ( typeof amounts === 'number' ) { this .numberOfFingers = amounts; } else { return this .numberOfFingers; } }; Zoom.prototype._doZoomTo = function (scale, origin, time, useCurrentPos) { var _this = this ; if (time === void 0) { time = this .zoomOpt.bounceTime; } if (useCurrentPos === void 0) { useCurrentPos = false ; } var _a = this .zoomOpt, min = _a.min, max = _a.max; var fromScale = this .scale; var toScale = between(scale, min, max); ( function () { if (time === 0) { _this.scroll.trigger(_this.scroll.eventTypes.zooming, { scale: toScale, }); return ; } if (time > 0) { var timer_1; var startTime_1 = getNow(); var endTime_1 = startTime_1 + time; var scheduler_1 = function () { var now = getNow(); if (now >= endTime_1) { _this.scroll.trigger(_this.scroll.eventTypes.zooming, { scale: toScale, }); cancelAnimationFrame(timer_1); return ; } var ratio = ease.bounce.fn((now - startTime_1) / time); var currentScale = ratio * (toScale - fromScale) + fromScale; _this.scroll.trigger(_this.scroll.eventTypes.zooming, { scale: currentScale, }); timer_1 = requestAnimationFrame(scheduler_1); }; // start scheduler job scheduler_1(); } })(); // suppose you are zooming by two fingers this .fingersOperation(2); this ._zoomTo(toScale, fromScale, origin, time, useCurrentPos); }; Zoom.prototype._zoomTo = function (toScale, fromScale, origin, time, useCurrentPos) { if (useCurrentPos === void 0) { useCurrentPos = false ; } var ratio = toScale / origin.baseScale; this .setScale(toScale); var scroller = this .scroll.scroller; var scrollBehaviorX = scroller.scrollBehaviorX, scrollBehaviorY = scroller.scrollBehaviorY; this .resetBoundaries([scrollBehaviorX, scrollBehaviorY]); // position is restrained in boundary var newX = this .getNewPos(origin.x, ratio, scrollBehaviorX, true , useCurrentPos); var newY = this .getNewPos(origin.y, ratio, scrollBehaviorY, true , useCurrentPos); if (scrollBehaviorX.currentPos !== Math.round(newX) || scrollBehaviorY.currentPos !== Math.round(newY) || toScale !== fromScale) { scroller.scrollTo(newX, newY, time, ease.bounce, { start: { scale: fromScale, }, end: { scale: toScale, }, }); } }; Zoom.prototype.resolveOrigin = function (x, y) { var _a = this .scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY; var resolveFormula = { left: function () { return 0; }, top: function () { return 0; }, right: function () { return scrollBehaviorX.contentSize; }, bottom: function () { return scrollBehaviorY.contentSize; }, center: function (index) { var baseSize = index === 0 ? scrollBehaviorX.contentSize : scrollBehaviorY.contentSize; return baseSize / 2; }, }; return { originX: typeof x === 'number' ? x : resolveFormula[x](0), originY: typeof y === 'number' ? y : resolveFormula[y](1), }; }; Zoom.prototype.zoomStart = function (e) { var firstFinger = e.touches[0]; var secondFinger = e.touches[1]; this .startDistance = this .getFingerDistance(e); this .startScale = this .scale; var _a = offsetToBody( this .wrapper), left = _a.left, top = _a.top; this .origin = { x: Math.abs(firstFinger.pageX + secondFinger.pageX) / 2 + left - this .scroll.x, y: Math.abs(firstFinger.pageY + secondFinger.pageY) / 2 + top - this .scroll.y, baseScale: this .startScale, }; this .scroll.trigger( this .scroll.eventTypes.beforeZoomStart); }; Zoom.prototype.zoom = function (e) { var currentDistance = this .getFingerDistance(e); // at least minimalZoomDistance pixels for the zoom to initiate if (! this .zoomed && Math.abs(currentDistance - this .startDistance) < this .zoomOpt.minimalZoomDistance) { return ; } // when out of boundary , perform a damping algorithm var endScale = this .dampingScale((currentDistance / this .startDistance) * this .startScale); var ratio = endScale / this .startScale; this .setScale(endScale); if (! this .zoomed) { this .zoomed = true ; this .scroll.trigger( this .scroll.eventTypes.zoomStart); } var scroller = this .scroll.scroller; var scrollBehaviorX = scroller.scrollBehaviorX, scrollBehaviorY = scroller.scrollBehaviorY; var x = this .getNewPos( this .origin.x, ratio, scrollBehaviorX, false , false ); var y = this .getNewPos( this .origin.y, ratio, scrollBehaviorY, false , false ); this .scroll.trigger( this .scroll.eventTypes.zooming, { scale: this .scale, }); scroller.translater.translate({ x: x, y: y, scale: endScale }); }; Zoom.prototype.zoomEnd = function () { if (! this .zoomed) return ; // if out of boundary, do rebound! if ( this .shouldRebound()) { this ._doZoomTo( this .scale, this .origin, this .zoomOpt.bounceTime); return ; } this .scroll.trigger( this .scroll.eventTypes.zoomEnd, { scale: this .scale }); }; Zoom.prototype.getFingerDistance = function (e) { var firstFinger = e.touches[0]; var secondFinger = e.touches[1]; var deltaX = Math.abs(firstFinger.pageX - secondFinger.pageX); var deltaY = Math.abs(firstFinger.pageY - secondFinger.pageY); return getDistance(deltaX, deltaY); }; Zoom.prototype.shouldRebound = function () { var _a = this .zoomOpt, min = _a.min, max = _a.max; var currentScale = this .scale; // scale exceeded! if (currentScale !== between(currentScale, min, max)) { return true ; } var _b = this .scroll.scroller, scrollBehaviorX = _b.scrollBehaviorX, scrollBehaviorY = _b.scrollBehaviorY; // enlarge boundaries manually when zoom is end this .resetBoundaries([scrollBehaviorX, scrollBehaviorY]); var xInBoundary = scrollBehaviorX.checkInBoundary().inBoundary; var yInBoundary = scrollBehaviorX.checkInBoundary().inBoundary; return !(xInBoundary && yInBoundary); }; Zoom.prototype.dampingScale = function (scale) { var _a = this .zoomOpt, min = _a.min, max = _a.max; if (scale < min) { scale = 0.5 * min * Math.pow(2.0, scale / min); } else if (scale > max) { scale = 2.0 * max * Math.pow(0.5, max / scale); } return scale; }; Zoom.prototype.setScale = function (scale) { this .scale = scale; }; Zoom.prototype.resetBoundaries = function (scrollBehaviorPairs) { scrollBehaviorPairs.forEach( function (behavior) { return behavior.computeBoundary(); }); }; Zoom.prototype.getNewPos = function (origin, lastScale, scrollBehavior, shouldInBoundary, useCurrentPos) { if (useCurrentPos === void 0) { useCurrentPos = false ; } var newPos = origin - origin * lastScale + (useCurrentPos ? scrollBehavior.currentPos : scrollBehavior.startPos); if (shouldInBoundary) { newPos = between(newPos, scrollBehavior.maxScrollPos, scrollBehavior.minScrollPos); } // maxScrollPos or minScrollPos maybe a negative or positive digital return newPos > 0 ? Math.floor(newPos) : Math.ceil(newPos); }; Zoom.prototype.registerHooks = function (hooks, name, handler) { hooks.on(name, handler, this ); this .hooksFn.push([hooks, name, handler]); }; Zoom.prototype.destroy = function () { this .hooksFn.forEach( function (item) { var hooks = item[0]; var hooksName = item[1]; var handlerFn = item[2]; hooks.off(hooksName, handlerFn); }); this .hooksFn.length = 0; }; Zoom.pluginName = 'zoom' ; return Zoom; }()); var BScrollFamily = /** @class */ ( function () { function BScrollFamily(scroll) { this .ancestors = []; this .descendants = []; this .hooksManager = []; this .analyzed = false ; this .selfScroll = scroll; } BScrollFamily.create = function (scroll) { return new BScrollFamily(scroll); }; BScrollFamily.prototype.hasAncestors = function (bscrollFamily) { var index = findIndex( this .ancestors, function (_a) { var item = _a[0]; return item === bscrollFamily; }); return index > -1; }; BScrollFamily.prototype.hasDescendants = function (bscrollFamily) { var index = findIndex( this .descendants, function (_a) { var item = _a[0]; return item === bscrollFamily; }); return index > -1; }; BScrollFamily.prototype.addAncestor = function (bscrollFamily, distance) { var ancestors = this .ancestors; ancestors.push([bscrollFamily, distance]); // by ascend ancestors.sort( function (a, b) { return a[1] - b[1]; }); }; BScrollFamily.prototype.addDescendant = function (bscrollFamily, distance) { var descendants = this .descendants; descendants.push([bscrollFamily, distance]); // by ascend descendants.sort( function (a, b) { return a[1] - b[1]; }); }; BScrollFamily.prototype.removeAncestor = function (bscrollFamily) { var ancestors = this .ancestors; if (ancestors.length) { var index = findIndex( this .ancestors, function (_a) { var item = _a[0]; return item === bscrollFamily; }); if (index > -1) { return ancestors.splice(index, 1); } } }; BScrollFamily.prototype.removeDescendant = function (bscrollFamily) { var descendants = this .descendants; if (descendants.length) { var index = findIndex( this .descendants, function (_a) { var item = _a[0]; return item === bscrollFamily; }); if (index > -1) { return descendants.splice(index, 1); } } }; BScrollFamily.prototype.registerHooks = function (hook, eventType, handler) { hook.on(eventType, handler); this .hooksManager.push([hook, eventType, handler]); }; BScrollFamily.prototype.setAnalyzed = function (flag) { if (flag === void 0) { flag = false ; } this .analyzed = flag; }; BScrollFamily.prototype.purge = function () { var _this = this ; // remove self from graph this .ancestors.forEach( function (_a) { var bscrollFamily = _a[0]; bscrollFamily.removeDescendant(_this); }); this .descendants.forEach( function (_a) { var bscrollFamily = _a[0]; bscrollFamily.removeAncestor(_this); }); // remove all hook handlers this .hooksManager.forEach( function (_a) { var hooks = _a[0], eventType = _a[1], handler = _a[2]; hooks.off(eventType, handler); }); this .hooksManager = []; }; return BScrollFamily; }()); var sourcePrefix$1 = 'plugins.nestedScroll' ; var propertiesMap$1 = [ { key: 'purgeNestedScroll' , name: 'purgeNestedScroll' , }, ]; var propertiesConfig$1 = propertiesMap$1.map( function (item) { return { key: item.key, sourceKey: sourcePrefix$1 + "." + item.name, }; }); var DEFAUL_GROUP_ID = 'INTERNAL_NESTED_SCROLL' ; var forceScrollStopHandler = function (scrolls) { scrolls.forEach( function (scroll) { if (scroll.pending) { scroll.stop(); scroll.resetPosition(); } }); }; var enableScrollHander = function (scrolls) { scrolls.forEach( function (scroll) { scroll.enable(); }); }; var disableScrollHander = function (scrolls, currentScroll) { scrolls.forEach( function (scroll) { if (scroll.hasHorizontalScroll === currentScroll.hasHorizontalScroll || scroll.hasVerticalScroll === currentScroll.hasVerticalScroll) { scroll.disable(); } }); }; var syncTouchstartData = function (scrolls) { scrolls.forEach( function (scroll) { var _a = scroll.scroller, actions = _a.actions, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY; // prevent click triggering many times actions.fingerMoved = true ; actions.contentMoved = false ; actions.directionLockAction.reset(); scrollBehaviorX.start(); scrollBehaviorY.start(); scrollBehaviorX.resetStartPos(); scrollBehaviorY.resetStartPos(); actions.startTime = + new Date(); }); }; var isOutOfBoundary = function (scroll) { var hasHorizontalScroll = scroll.hasHorizontalScroll, hasVerticalScroll = scroll.hasVerticalScroll, x = scroll.x, y = scroll.y, minScrollX = scroll.minScrollX, maxScrollX = scroll.maxScrollX, minScrollY = scroll.minScrollY, maxScrollY = scroll.maxScrollY, movingDirectionX = scroll.movingDirectionX, movingDirectionY = scroll.movingDirectionY; var ret = false ; var outOfLeftBoundary = x >= minScrollX && movingDirectionX === -1 /* Negative */ ; var outOfRightBoundary = x <= maxScrollX && movingDirectionX === 1 /* Positive */ ; var outOfTopBoundary = y >= minScrollY && movingDirectionY === -1 /* Negative */ ; var outOfBottomBoundary = y <= maxScrollY && movingDirectionY === 1 /* Positive */ ; if (hasVerticalScroll) { ret = outOfTopBoundary || outOfBottomBoundary; } else if (hasHorizontalScroll) { ret = outOfLeftBoundary || outOfRightBoundary; } return ret; }; var isResettingPosition = function (scroll) { var hasHorizontalScroll = scroll.hasHorizontalScroll, hasVerticalScroll = scroll.hasVerticalScroll, x = scroll.x, y = scroll.y, minScrollX = scroll.minScrollX, maxScrollX = scroll.maxScrollX, minScrollY = scroll.minScrollY, maxScrollY = scroll.maxScrollY; var ret = false ; var outOfLeftBoundary = x > minScrollX; var outOfRightBoundary = x < maxScrollX; var outOfTopBoundary = y > minScrollY; var outOfBottomBoundary = y < maxScrollY; if (hasVerticalScroll) { ret = outOfTopBoundary || outOfBottomBoundary; } else if (hasHorizontalScroll) { ret = outOfLeftBoundary || outOfRightBoundary; } return ret; }; var resetPositionHandler = function (scroll) { scroll.scroller.reflow(); scroll.resetPosition(0 /* Immediately */ ); }; var calculateDistance = function (childNode, parentNode) { var distance = 0; var parent = childNode.parentNode; while (parent && parent !== parentNode) { distance++; parent = parent.parentNode; } return distance; }; var NestedScroll = /** @class */ ( function () { function NestedScroll(scroll) { var groupId = this .handleOptions(scroll); var instance = NestedScroll.instancesMap[groupId]; if (!instance) { instance = NestedScroll.instancesMap[groupId] = this ; instance.store = []; instance.hooksFn = []; } instance.init(scroll); return instance; } NestedScroll.getAllNestedScrolls = function () { var instancesMap = NestedScroll.instancesMap; return Object.keys(instancesMap).map( function (key) { return instancesMap[key]; }); }; NestedScroll.purgeAllNestedScrolls = function () { var nestedScrolls = NestedScroll.getAllNestedScrolls(); nestedScrolls.forEach( function (ns) { return ns.purgeNestedScroll(); }); }; NestedScroll.prototype.handleOptions = function (scroll) { var userOptions = (scroll.options.nestedScroll === true ? {} : scroll.options.nestedScroll); var defaultOptions = { groupId: DEFAUL_GROUP_ID, }; this .options = extend(defaultOptions, userOptions); var groupIdType = typeof this .options.groupId; if (groupIdType !== 'string' && groupIdType !== 'number' ) { warn( 'groupId must be string or number for NestedScroll plugin' ); } return this .options.groupId; }; NestedScroll.prototype.init = function (scroll) { scroll.proxy(propertiesConfig$1); this .addBScroll(scroll); this .buildBScrollGraph(); this .analyzeBScrollGraph(); this .ensureEventInvokeSequence(); this .handleHooks(scroll); }; NestedScroll.prototype.handleHooks = function (scroll) { var _this = this ; this .registerHooks(scroll.hooks, scroll.hooks.eventTypes.destroy, function () { _this.deleteScroll(scroll); }); }; NestedScroll.prototype.deleteScroll = function (scroll) { var wrapper = scroll.wrapper; wrapper.isBScrollContainer = undefined; var store = this .store; var hooksFn = this .hooksFn; var i = findIndex(store, function (bscrollFamily) { return bscrollFamily.selfScroll === scroll; }); if (i > -1) { var bscrollFamily = store[i]; bscrollFamily.purge(); store.splice(i, 1); } var k = findIndex(hooksFn, function (_a) { var hooks = _a[0]; return hooks === scroll.hooks; }); if (k > -1) { var _a = hooksFn[k], hooks = _a[0], eventType = _a[1], handler = _a[2]; hooks.off(eventType, handler); hooksFn.splice(k, 1); } }; NestedScroll.prototype.addBScroll = function (scroll) { this .store.push(BScrollFamily.create(scroll)); }; NestedScroll.prototype.buildBScrollGraph = function () { var store = this .store; var bf1; var bf2; var wrapper1; var wrapper2; var len = this .store.length; // build graph for ( var i = 0; i < len; i++) { bf1 = store[i]; wrapper1 = bf1.selfScroll.wrapper; for ( var j = 0; j < len; j++) { bf2 = store[j]; wrapper2 = bf2.selfScroll.wrapper; // same bs if (bf1 === bf2) continue ; if (!wrapper1.contains(wrapper2)) continue ; // bs1 contains bs2 var distance = calculateDistance(wrapper2, wrapper1); if (!bf1.hasDescendants(bf2)) { bf1.addDescendant(bf2, distance); } if (!bf2.hasAncestors(bf1)) { bf2.addAncestor(bf1, distance); } } } }; NestedScroll.prototype.analyzeBScrollGraph = function () { this .store.forEach( function (bscrollFamily) { if (bscrollFamily.analyzed) { return ; } var ancestors = bscrollFamily.ancestors, descendants = bscrollFamily.descendants, currentScroll = bscrollFamily.selfScroll; var beforeScrollStartHandler = function () { // always get the latest scroll var ancestorScrolls = ancestors.map( function (_a) { var bscrollFamily = _a[0]; return bscrollFamily.selfScroll; }); var descendantScrolls = descendants.map( function (_a) { var bscrollFamily = _a[0]; return bscrollFamily.selfScroll; }); forceScrollStopHandler(__spreadArrays(ancestorScrolls, descendantScrolls)); if (isResettingPosition(currentScroll)) { resetPositionHandler(currentScroll); } syncTouchstartData(ancestorScrolls); disableScrollHander(ancestorScrolls, currentScroll); }; var touchEndHandler = function () { var ancestorScrolls = ancestors.map( function (_a) { var bscrollFamily = _a[0]; return bscrollFamily.selfScroll; }); var descendantScrolls = descendants.map( function (_a) { var bscrollFamily = _a[0]; return bscrollFamily.selfScroll; }); enableScrollHander(__spreadArrays(ancestorScrolls, descendantScrolls)); }; bscrollFamily.registerHooks(currentScroll, currentScroll.eventTypes.beforeScrollStart, beforeScrollStartHandler); bscrollFamily.registerHooks(currentScroll, currentScroll.eventTypes.touchEnd, touchEndHandler); var selfActionsHooks = currentScroll.scroller.actions.hooks; bscrollFamily.registerHooks(selfActionsHooks, selfActionsHooks.eventTypes.detectMovingDirection, function () { var ancestorScrolls = ancestors.map( function (_a) { var bscrollFamily = _a[0]; return bscrollFamily.selfScroll; }); var parentScroll = ancestorScrolls[0]; var otherAncestorScrolls = ancestorScrolls.slice(1); var contentMoved = currentScroll.scroller.actions.contentMoved; var isTopScroll = ancestorScrolls.length === 0; if (contentMoved) { disableScrollHander(ancestorScrolls, currentScroll); } else if (!isTopScroll) { if (isOutOfBoundary(currentScroll)) { disableScrollHander([currentScroll], currentScroll); if (parentScroll) { enableScrollHander([parentScroll]); } disableScrollHander(otherAncestorScrolls, currentScroll); return true ; } } }); bscrollFamily.setAnalyzed( true ); }); }; // make sure touchmove|touchend invoke from child to parent NestedScroll.prototype.ensureEventInvokeSequence = function () { var copied = this .store.slice(); var sequencedScroll = copied.sort( function (a, b) { return a.descendants.length - b.descendants.length; }); sequencedScroll.forEach( function (bscrollFamily) { var scroll = bscrollFamily.selfScroll; scroll.scroller.actionsHandler.rebindDOMEvents(); }); }; NestedScroll.prototype.registerHooks = function (hooks, name, handler) { hooks.on(name, handler, this ); this .hooksFn.push([hooks, name, handler]); }; NestedScroll.prototype.purgeNestedScroll = function () { var groupId = this .options.groupId; this .store.forEach( function (bscrollFamily) { bscrollFamily.purge(); }); this .store = []; this .hooksFn.forEach( function (_a) { var hooks = _a[0], eventType = _a[1], handler = _a[2]; hooks.off(eventType, handler); }); this .hooksFn = []; delete NestedScroll.instancesMap[groupId]; }; NestedScroll.pluginName = 'nestedScroll' ; NestedScroll.instancesMap = {}; return NestedScroll; }()); var PRE_NUM = 10; var POST_NUM = 30; var IndexCalculator = /** @class */ ( function () { function IndexCalculator(wrapperHeight, tombstoneHeight) { this .wrapperHeight = wrapperHeight; this .tombstoneHeight = tombstoneHeight; this .lastDirection = 1 /* DOWN */ ; this .lastPos = 0; } IndexCalculator.prototype.calculate = function (pos, list) { var offset = pos - this .lastPos; this .lastPos = pos; var direction = this .getDirection(offset); // important! start index is much more important than end index. var start = this .calculateIndex(0, pos, list); var end = this .calculateIndex(start, pos + this .wrapperHeight, list); if (direction === 1 /* DOWN */ ) { start -= PRE_NUM; end += POST_NUM; } else { start -= POST_NUM; end += PRE_NUM; } if (start < 0) { start = 0; } return { start: start, end: end, }; }; IndexCalculator.prototype.getDirection = function (offset) { var direction; if (offset > 0) { direction = 1 /* DOWN */ ; } else if (offset < 0) { direction = 0 /* UP */ ; } else { return this .lastDirection; } this .lastDirection = direction; return direction; }; IndexCalculator.prototype.calculateIndex = function (start, offset, list) { if (offset <= 0) { return start; } var i = start; var startPos = list[i] && list[i].pos !== -1 ? list[i].pos : 0; var lastPos = startPos; var tombstone = 0; while (i < list.length && list[i].pos < offset) { lastPos = list[i].pos; i++; } if (i === list.length) { tombstone = Math.floor((offset - lastPos) / this .tombstoneHeight); } i += tombstone; return i; }; IndexCalculator.prototype.resetState = function () { this .lastDirection = 1 /* DOWN */ ; this .lastPos = 0; }; return IndexCalculator; }()); var ListItem = /** @class */ ( function () { function ListItem() { this .data = null ; this .dom = null ; this .tombstone = null ; this .width = 0; this .height = 0; this .pos = 0; } return ListItem; }()); var DataManager = /** @class */ ( function () { function DataManager(list, fetchFn, onFetchFinish) { this .fetchFn = fetchFn; this .onFetchFinish = onFetchFinish; this .loadedNum = 0; this .fetching = false ; this .hasMore = true ; this .list = list || []; } DataManager.prototype.update = function (end) { return __awaiter( this , void 0, void 0, function () { var len; return __generator( this , function (_a) { if (! this .hasMore) { end = Math.min(end, this .list.length); } // add data placeholder if (end > this .list.length) { len = end - this .list.length; this .addEmptyData(len); } // tslint:disable-next-line: no-floating-promises return [2 /*return*/ , this .checkToFetch(end)]; }); }); }; DataManager.prototype.add = function (data) { for ( var i = 0; i < data.length; i++) { if (! this .list[ this .loadedNum]) { this .list[ this .loadedNum] = { data: data[i] }; } else { this .list[ this .loadedNum] = __assign(__assign({}, this .list[ this .loadedNum]), { data: data[i] }); } this .loadedNum++; } return this .list; }; DataManager.prototype.addEmptyData = function (len) { for ( var i = 0; i < len; i++) { this .list.push( new ListItem()); } return this .list; }; DataManager.prototype.fetch = function (len) { return __awaiter( this , void 0, void 0, function () { var data; return __generator( this , function (_a) { switch (_a.label) { case 0: if ( this .fetching) { return [2 /*return*/ , []]; } this .fetching = true ; return [4 /*yield*/ , this .fetchFn(len)]; case 1: data = _a.sent(); this .fetching = false ; return [2 /*return*/ , data]; } }); }); }; DataManager.prototype.checkToFetch = function (end) { return __awaiter( this , void 0, void 0, function () { var min, newData, currentEnd; return __generator( this , function (_a) { switch (_a.label) { case 0: if (! this .hasMore) { return [2 /*return*/ ]; } if (end <= this .loadedNum) { return [2 /*return*/ ]; } min = end - this .loadedNum; return [4 /*yield*/ , this .fetch(min)]; case 1: newData = _a.sent(); if (newData instanceof Array && newData.length) { this .add(newData); currentEnd = this .onFetchFinish( this .list, true ); return [2 /*return*/ , this .checkToFetch(currentEnd)]; } else if ( typeof newData === 'boolean' && newData === false ) { this .hasMore = false ; this .list.splice( this .loadedNum); this .onFetchFinish( this .list, false ); } return [2 /*return*/ ]; } }); }); }; DataManager.prototype.getList = function () { return this .list; }; DataManager.prototype.resetState = function () { this .loadedNum = 0; this .fetching = false ; this .hasMore = true ; this .list = []; }; return DataManager; }()); var Tombstone = /** @class */ ( function () { function Tombstone(create) { this .create = create; this .cached = []; this .width = 0; this .height = 0; this .initialed = false ; this .getSize(); } Tombstone.isTombstone = function (el) { if (el && el.classList) { return el.classList.contains( 'tombstone' ); } return false ; }; Tombstone.prototype.getSize = function () { if (! this .initialed) { var tombstone = this .create(); tombstone.style.position = 'absolute' ; document.body.appendChild(tombstone); tombstone.style.display = '' ; this .height = tombstone.offsetHeight; this .width = tombstone.offsetWidth; document.body.removeChild(tombstone); this .cached.push(tombstone); } }; Tombstone.prototype.getOne = function () { var tombstone = this .cached.pop(); if (tombstone) { var tombstoneStyle = tombstone.style; tombstoneStyle.display = '' ; tombstoneStyle.opacity = '1' ; tombstoneStyle[style.transform] = '' ; tombstoneStyle[style.transition] = '' ; return tombstone; } return this .create(); }; Tombstone.prototype.recycle = function (tombstones) { for ( var _i = 0, tombstones_1 = tombstones; _i < tombstones_1.length; _i++) { var tombstone = tombstones_1[_i]; tombstone.style.display = 'none' ; this .cached.push(tombstone); } return this .cached; }; Tombstone.prototype.recycleOne = function (tombstone) { this .cached.push(tombstone); return this .cached; }; return Tombstone; }()); var ANIMATION_DURATION_MS = 200; var DomManager = /** @class */ ( function () { function DomManager(content, renderFn, tombstone) { this .renderFn = renderFn; this .tombstone = tombstone; this .unusedDom = []; this .timers = []; this .setContent(content); } DomManager.prototype.update = function (list, start, end) { if (start >= list.length) { start = list.length - 1; } if (end > list.length) { end = list.length; } this .collectUnusedDom(list, start, end); this .createDom(list, start, end); this .cacheHeight(list, start, end); var _a = this .positionDom(list, start, end), startPos = _a.startPos, startDelta = _a.startDelta, endPos = _a.endPos; return { start: start, startPos: startPos, startDelta: startDelta, end: end, endPos: endPos, }; }; DomManager.prototype.collectUnusedDom = function (list, start, end) { // TODO optimise for ( var i = 0; i < list.length; i++) { if (i === start) { i = end - 1; continue ; } if (list[i].dom) { var dom = list[i].dom; if (Tombstone.isTombstone(dom)) { this .tombstone.recycleOne(dom); dom.style.display = 'none' ; } else { this .unusedDom.push(dom); } list[i].dom = null ; } } return list; }; DomManager.prototype.createDom = function (list, start, end) { for ( var i = start; i < end; i++) { var dom = list[i].dom; var data = list[i].data; if (dom) { if (Tombstone.isTombstone(dom) && data) { list[i].tombstone = dom; list[i].dom = null ; } else { continue ; } } dom = data ? this .renderFn(data, this .unusedDom.pop()) : this .tombstone.getOne(); dom.style.position = 'absolute' ; list[i].dom = dom; list[i].pos = -1; this .content.appendChild(dom); } }; DomManager.prototype.cacheHeight = function (list, start, end) { for ( var i = start; i < end; i++) { if (list[i].data && !list[i].height) { list[i].height = list[i].dom.offsetHeight; } } }; DomManager.prototype.positionDom = function (list, start, end) { var _this = this ; var tombstoneEles = []; var _a = this .getStartPos(list, start, end), startPos = _a.start, startDelta = _a.delta; var pos = startPos; for ( var i = start; i < end; i++) { var tombstone = list[i].tombstone; if (tombstone) { var tombstoneStyle = tombstone.style; tombstoneStyle[style.transition] = cssVendor + "transform " + ANIMATION_DURATION_MS + "ms, opacity " + ANIMATION_DURATION_MS + "ms" ; tombstoneStyle[style.transform] = "translateY(" + pos + "px)" ; tombstoneStyle.opacity = '0' ; list[i].tombstone = null ; tombstoneEles.push(tombstone); } if (list[i].dom && list[i].pos !== pos) { list[i].dom.style[style.transform] = "translateY(" + pos + "px)" ; list[i].pos = pos; } pos += list[i].height || this .tombstone.height; } var timerId = window.setTimeout( function () { _this.tombstone.recycle(tombstoneEles); }, ANIMATION_DURATION_MS); this .timers.push(timerId); return { startPos: startPos, startDelta: startDelta, endPos: pos, }; }; DomManager.prototype.getStartPos = function (list, start, end) { if (list[start] && list[start].pos !== -1) { return { start: list[start].pos, delta: 0, }; } // TODO optimise var pos = list[0].pos === -1 ? 0 : list[0].pos; for ( var i_1 = 0; i_1 < start; i_1++) { pos += list[i_1].height || this .tombstone.height; } var originPos = pos; var i; for (i = start; i < end; i++) { if (!Tombstone.isTombstone(list[i].dom) && list[i].pos !== -1) { pos = list[i].pos; break ; } } var x = i; if (x < end) { while (x > start) { pos -= list[x - 1].height; x--; } } var delta = originPos - pos; return { start: pos, delta: delta, }; }; DomManager.prototype.removeTombstone = function () { var tombstones = this .content.querySelectorAll( '.tombstone' ); for ( var i = tombstones.length - 1; i >= 0; i--) { this .content.removeChild(tombstones[i]); } }; DomManager.prototype.setContent = function (content) { if (content !== this .content) { this .content = content; } }; DomManager.prototype.destroy = function () { this .removeTombstone(); this .timers.forEach( function (id) { clearTimeout(id); }); }; DomManager.prototype.resetState = function () { this .destroy(); this .timers = []; this .unusedDom = []; }; return DomManager; }()); var EXTRA_SCROLL_Y = -2000; var InfinityScroll = /** @class */ ( function () { function InfinityScroll(scroll) { this .scroll = scroll; this .start = 0; this .end = 0; this .init(); } InfinityScroll.prototype.init = function () { var _this = this ; this .handleOptions(); var _a = this .options, fetchFn = _a.fetch, renderFn = _a.render, createTombstoneFn = _a.createTombstone; this .tombstone = new Tombstone(createTombstoneFn); this .indexCalculator = new IndexCalculator( this .scroll.scroller.scrollBehaviorY.wrapperSize, this .tombstone.height); this .domManager = new DomManager( this .scroll.scroller.content, renderFn, this .tombstone); this .dataManager = new DataManager([], fetchFn, 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 (content) { _this.domManager.setContent(content); _this.indexCalculator.resetState(); _this.domManager.resetState(); _this.dataManager.resetState(); _this.update({ y: 0 }); }); var scrollBehaviorY = this .scroll.scroller.scrollBehaviorY; scrollBehaviorY.hooks.on(scrollBehaviorY.hooks.eventTypes.computeBoundary, this .modifyBoundary, this ); this .update({ y: 0 }); }; InfinityScroll.prototype.modifyBoundary = function (boundary) { // manually set position to allow scroll boundary.maxScrollPos = EXTRA_SCROLL_Y; }; InfinityScroll.prototype.handleOptions = function () { // narrow down type to an object var infinityOptions = this .scroll.options.infinity; if (infinityOptions) { if ( typeof infinityOptions.fetch !== 'function' ) { warn( 'Infinity plugin need fetch Function to new data.' ); } if ( typeof infinityOptions.render !== 'function' ) { warn( 'Infinity plugin need render Function to render each item.' ); } if ( typeof infinityOptions.render !== 'function' ) { warn( 'Infinity plugin need createTombstone Function to create tombstone.' ); } this .options = infinityOptions; } this .scroll.options.probeType = 3 /* Realtime */ ; }; InfinityScroll.prototype.update = function (pos) { var position = Math.round(-pos.y); // important! calculate start/end index to render var _a = this .indexCalculator.calculate(position, this .dataManager.getList()), start = _a.start, end = _a.end; this .start = start; this .end = end; // tslint:disable-next-line: no-floating-promises this .dataManager.update(end); this .updateDom( this .dataManager.getList()); }; InfinityScroll.prototype.onFetchFinish = function (list, hasMore) { var end = this .updateDom(list).end; if (!hasMore) { this .domManager.removeTombstone(); this .scroll.scroller.animater.stop(); this .scroll.resetPosition(); } // tslint:disable-next-line: no-floating-promises return end; }; InfinityScroll.prototype.updateDom = function (list) { var _a = this .domManager.update(list, this .start, this .end), end = _a.end, startPos = _a.startPos, endPos = _a.endPos, startDelta = _a.startDelta; if (startDelta) { this .scroll.minScrollY = startDelta; } if (endPos > this .scroll.maxScrollY) { this .scroll.maxScrollY = -(endPos - this .scroll.scroller.scrollBehaviorY.wrapperSize); } return { end: end, startPos: startPos, endPos: endPos, }; }; InfinityScroll.prototype.destroy = function () { var _a = this .scroll.scroller, content = _a.content, scrollBehaviorY = _a.scrollBehaviorY; while (content.firstChild) { content.removeChild(content.firstChild); } this .domManager.destroy(); this .scroll.off( 'scroll' , this .update); this .scroll.off( 'destroy' , this .destroy); scrollBehaviorY.hooks.off(scrollBehaviorY.hooks.eventTypes.computeBoundary); }; InfinityScroll.pluginName = 'infinity' ; return InfinityScroll; }()); var sourcePrefix = 'plugins.movable' ; var propertiesMap = [ { key: 'putAt' , name: 'putAt' , }, ]; var propertiesConfig = propertiesMap.map( function (item) { return { key: item.key, sourceKey: sourcePrefix + "." + item.name, }; }); var Movable = /** @class */ ( function () { function Movable(scroll) { this .scroll = scroll; this .handleBScroll(); this .handleHooks(); } Movable.prototype.handleBScroll = function () { this .scroll.proxy(propertiesConfig); }; Movable.prototype.handleHooks = function () { var _this = this ; this .hooksFn = []; var _a = this .scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY; var computeBoundary = function (boundary, behavior) { if (boundary.maxScrollPos > 0) { // content is smaller than wrapper boundary.minScrollPos = behavior.wrapperSize - behavior.contentSize; boundary.maxScrollPos = 0; } }; this .registerHooks(scrollBehaviorX.hooks, scrollBehaviorX.hooks.eventTypes.ignoreHasScroll, function () { return true ; }); this .registerHooks(scrollBehaviorX.hooks, scrollBehaviorX.hooks.eventTypes.computeBoundary, function (boundary) { computeBoundary(boundary, scrollBehaviorX); }); this .registerHooks(scrollBehaviorY.hooks, scrollBehaviorY.hooks.eventTypes.ignoreHasScroll, function () { return true ; }); this .registerHooks(scrollBehaviorY.hooks, scrollBehaviorY.hooks.eventTypes.computeBoundary, function (boundary) { computeBoundary(boundary, scrollBehaviorY); }); this .registerHooks( this .scroll.hooks, this .scroll.hooks.eventTypes.destroy, function () { _this.destroy(); }); }; Movable.prototype.putAt = function (x, y, time, easing) { if (time === void 0) { time = this .scroll.options.bounceTime; } if (easing === void 0) { easing = ease.bounce; } var position = this .resolvePostion(x, y); this .scroll.scrollTo(position.x, position.y, time, easing); }; Movable.prototype.resolvePostion = function (x, y) { var _a = this .scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY; var resolveFormula = { left: function () { return 0; }, top: function () { return 0; }, right: function () { return scrollBehaviorX.minScrollPos; }, bottom: function () { return scrollBehaviorY.minScrollPos; }, center: function (index) { var baseSize = index === 0 ? scrollBehaviorX.minScrollPos : scrollBehaviorY.minScrollPos; return baseSize / 2; }, }; return { x: typeof x === 'number' ? x : resolveFormula[x](0), y: typeof y === 'number' ? y : resolveFormula[y](1), }; }; Movable.prototype.destroy = function () { this .hooksFn.forEach( function (item) { var hooks = item[0]; var hooksName = item[1]; var handlerFn = item[2]; hooks.off(hooksName, handlerFn); }); this .hooksFn.length = 0; }; Movable.prototype.registerHooks = function (hooks, name, handler) { hooks.on(name, handler, this ); this .hooksFn.push([hooks, name, handler]); }; Movable.pluginName = 'movable' ; Movable.applyOrder = "pre" /* Pre */ ; return Movable; }()); var isImageTag = function (el) { return el.tagName.toLowerCase() === 'img' ; }; var ObserveImage = /** @class */ ( function () { function ObserveImage(scroll) { this .scroll = scroll; this .refreshTimer = 0; this .init(); } ObserveImage.prototype.init = function () { this .handleOptions( this .scroll.options.observeImage); this .bindEventsToWrapper(); }; ObserveImage.prototype.handleOptions = function (userOptions) { if (userOptions === void 0) { userOptions = {}; } userOptions = (userOptions === true ? {} : userOptions); var defaultOptions = { debounceTime: 100, }; this .options = extend(defaultOptions, userOptions); }; ObserveImage.prototype.bindEventsToWrapper = function () { var wrapper = this .scroll.scroller.wrapper; this .imageLoadEventRegister = new EventRegister(wrapper, [ { name: 'load' , handler: this .load.bind( this ), capture: true , }, ]); this .imageErrorEventRegister = new EventRegister(wrapper, [ { name: 'error' , handler: this .load.bind( this ), capture: true , }, ]); }; ObserveImage.prototype.load = function (e) { var _this = this ; var target = e.target; var debounceTime = this .options.debounceTime; if (target && isImageTag(target)) { if (debounceTime === 0) { this .scroll.refresh(); } else { clearTimeout( this .refreshTimer); this .refreshTimer = window.setTimeout( function () { _this.scroll.refresh(); }, this .options.debounceTime); } } }; ObserveImage.pluginName = 'observeImage' ; return ObserveImage; }()); var resolveRatioOption = function (ratioConfig) { var ret = { ratioX: 0, ratioY: 0, }; /* istanbul ignore if */ if (!ratioConfig) { return ret; } if ( typeof ratioConfig === 'number' ) { ret.ratioX = ret.ratioY = ratioConfig; } else if ( typeof ratioConfig === 'object' && ratioConfig) { ret.ratioX = ratioConfig.x || 0; ret.ratioY = ratioConfig.y || 0; } return ret; }; var handleBubbleAndCancelable = function (e) { maybePrevent(e); e.stopPropagation(); }; var Indicator = /** @class */ ( function () { function Indicator(scroll, options) { this .scroll = scroll; this .options = options; this .currentPos = { x: 0, y: 0, }; this .hooksFn = []; this .handleDOM(); this .handleHooks(); this .handleInteractive(); } Indicator.prototype.handleDOM = function () { var _a = this .options, relationElement = _a.relationElement, _b = _a.relationElementHandleElementIndex, relationElementHandleElementIndex = _b === void 0 ? 0 : _b; this .wrapper = relationElement; this .indicatorEl = this .wrapper.children[relationElementHandleElementIndex]; }; Indicator.prototype.handleHooks = function () { var _this = this ; var scroll = this .scroll; var scrollHooks = scroll.hooks; var translaterHooks = scroll.scroller.translater.hooks; var animaterHooks = scroll.scroller.animater.hooks; this .registerHooks(scrollHooks, scrollHooks.eventTypes.refresh, this .refresh); this .registerHooks(translaterHooks, translaterHooks.eventTypes.translate, function (pos) { _this.updatePosition(pos); }); this .registerHooks(animaterHooks, animaterHooks.eventTypes.time, this .transitionTime); this .registerHooks(animaterHooks, animaterHooks.eventTypes.timeFunction, this .transitionTimingFunction); }; Indicator.prototype.transitionTime = function (time) { if (time === void 0) { time = 0; } this .indicatorEl.style[style.transitionDuration] = time + 'ms' ; }; Indicator.prototype.transitionTimingFunction = function (easing) { this .indicatorEl.style[style.transitionTimingFunction] = easing; }; Indicator.prototype.handleInteractive = function () { if ( this .options.interactive !== false ) { this .registerEvents(); } }; Indicator.prototype.registerHooks = function (hooks, name, handler) { hooks.on(name, handler, this ); this .hooksFn.push([hooks, name, handler]); }; Indicator.prototype.registerEvents = function () { var _a = this .scroll.options, disableMouse = _a.disableMouse, disableTouch = _a.disableTouch; var startEvents = []; var moveEvents = []; var endEvents = []; if (!disableMouse) { startEvents.push({ name: 'mousedown' , handler: this .start.bind( this ), }); moveEvents.push({ name: 'mousemove' , handler: this .move.bind( this ), }); endEvents.push({ name: 'mouseup' , handler: this .end.bind( this ), }); } if (!disableTouch) { startEvents.push({ name: 'touchstart' , handler: this .start.bind( this ), }); moveEvents.push({ name: 'touchmove' , handler: this .move.bind( this ), }); endEvents.push({ name: 'touchend' , handler: this .end.bind( this ), }, { name: 'touchcancel' , handler: this .end.bind( this ), }); } this .startEventRegister = new EventRegister( this .indicatorEl, startEvents); this .moveEventRegister = new EventRegister(window, moveEvents); this .endEventRegister = new EventRegister(window, endEvents); }; Indicator.prototype.refresh = function () { var _a = this .scroll, x = _a.x, y = _a.y, hasHorizontalScroll = _a.hasHorizontalScroll, hasVerticalScroll = _a.hasVerticalScroll, maxBScrollX = _a.maxScrollX, maxBScrollY = _a.maxScrollY; var _b = resolveRatioOption( this .options.ratio), ratioX = _b.ratioX, ratioY = _b.ratioY; var _c = getClientSize( this .wrapper), wrapperWidth = _c.width, wrapperHeight = _c.height; var _d = getRect( this .indicatorEl), indicatorWidth = _d.width, indicatorHeight = _d.height; if (hasHorizontalScroll) { this .maxScrollX = wrapperWidth - indicatorWidth; this .translateXSign = this .maxScrollX > 0 ? -1 /* Positive */ : 1 /* NotPositive */ ; this .minScrollX = 0; // ensure positive this .ratioX = ratioX ? ratioX : Math.abs( this .maxScrollX / maxBScrollX); } if (hasVerticalScroll) { this .maxScrollY = wrapperHeight - indicatorHeight; this .translateYSign = this .maxScrollY > 0 ? -1 /* Positive */ : 1 /* NotPositive */ ; this .minScrollY = 0; this .ratioY = ratioY ? ratioY : Math.abs( this .maxScrollY / maxBScrollY); } this .updatePosition({ x: x, y: y, }); }; Indicator.prototype.start = function (e) { if ( this .BScrollIsDisabled()) { return ; } var point = (e.touches ? e.touches[0] : e); handleBubbleAndCancelable(e); this .initiated = true ; this .moved = false ; this .lastPointX = point.pageX; this .lastPointY = point.pageY; this .startTime = getNow(); this .scroll.scroller.hooks.trigger( this .scroll.scroller.hooks.eventTypes.beforeScrollStart); }; Indicator.prototype.BScrollIsDisabled = function () { return ! this .scroll.enabled; }; Indicator.prototype.move = function (e) { if (! this .initiated) { return ; } var point = (e.touches ? e.touches[0] : e); var pointX = point.pageX; var pointY = point.pageY; handleBubbleAndCancelable(e); var deltaX = pointX - this .lastPointX; var deltaY = pointY - this .lastPointY; this .lastPointX = pointX; this .lastPointY = pointY; if (! this .moved && ! this .indicatorNotMoved(deltaX, deltaY)) { this .moved = true ; this .scroll.scroller.hooks.trigger( this .scroll.scroller.hooks.eventTypes.scrollStart); } if ( this .moved) { var newPos = this .getBScrollPosByRatio( this .currentPos, deltaX, deltaY); this .syncBScroll(newPos); } }; Indicator.prototype.end = function (e) { if (! this .initiated) { return ; } this .initiated = false ; handleBubbleAndCancelable(e); if ( this .moved) { var _a = this .scroll, x = _a.x, y = _a.y; this .scroll.scroller.hooks.trigger( this .scroll.scroller.hooks.eventTypes.scrollEnd, { x: x, y: y, }); } }; Indicator.prototype.getBScrollPosByRatio = function (currentPos, deltaX, deltaY) { var currentX = currentPos.x, currentY = currentPos.y; var _a = this .scroll, hasHorizontalScroll = _a.hasHorizontalScroll, hasVerticalScroll = _a.hasVerticalScroll, BScrollMinScrollX = _a.minScrollX, BScrollMaxScrollX = _a.maxScrollX, BScrollMinScrollY = _a.minScrollY, BScrollMaxScrollY = _a.maxScrollY; var _b = this .scroll, x = _b.x, y = _b.y; if (hasHorizontalScroll) { var newPosX = between(currentX + deltaX, Math.min( this .minScrollX, this .maxScrollX), Math.max( this .minScrollX, this .maxScrollX)); var roundX = Math.round((newPosX / this .ratioX) * this .translateXSign); x = between(roundX, BScrollMaxScrollX, BScrollMinScrollX); } if (hasVerticalScroll) { var newPosY = between(currentY + deltaY, Math.min( this .minScrollY, this .maxScrollY), Math.max( this .minScrollY, this .maxScrollY)); var roundY = Math.round((newPosY / this .ratioY) * this .translateYSign); y = between(roundY, BScrollMaxScrollY, BScrollMinScrollY); } return { x: x, y: y }; }; Indicator.prototype.indicatorNotMoved = function (deltaX, deltaY) { var _a = this .currentPos, x = _a.x, y = _a.y; var xNotMoved = (x === this .minScrollX && deltaX <= 0) || (x === this .maxScrollX && deltaX >= 0); var yNotMoved = (y === this .minScrollY && deltaY <= 0) || (y === this .maxScrollY && deltaY >= 0); return xNotMoved && yNotMoved; }; Indicator.prototype.syncBScroll = function (newPos) { var timestamp = getNow(); var _a = this .scroll, options = _a.options, scroller = _a.scroller; var probeType = options.probeType, momentumLimitTime = options.momentumLimitTime; scroller.translater.translate(newPos); // dispatch scroll in interval time if (timestamp - this .startTime > momentumLimitTime) { this .startTime = timestamp; if (probeType === 1 /* Throttle */ ) { scroller.hooks.trigger(scroller.hooks.eventTypes.scroll, newPos); } } // dispatch scroll all the time if (probeType > 1 /* Throttle */ ) { scroller.hooks.trigger(scroller.hooks.eventTypes.scroll, newPos); } }; Indicator.prototype.updatePosition = function (BScrollPos) { var newIndicatorPos = this .getIndicatorPosByRatio(BScrollPos); this .applyTransformProperty(newIndicatorPos); this .currentPos = __assign({}, newIndicatorPos); }; Indicator.prototype.applyTransformProperty = function (pos) { var translateZ = this .scroll.options.translateZ; var transformProperties = [ "translateX(" + pos.x + "px)" , "translateY(" + pos.y + "px)" , "" + translateZ, ]; this .indicatorEl.style[style.transform] = transformProperties.join( ' ' ); }; Indicator.prototype.getIndicatorPosByRatio = function (BScrollPos) { var x = BScrollPos.x, y = BScrollPos.y; var _a = this .scroll, hasHorizontalScroll = _a.hasHorizontalScroll, hasVerticalScroll = _a.hasVerticalScroll; var position = __assign({}, this .currentPos); if (hasHorizontalScroll) { var roundX = Math.round( this .ratioX * x * this .translateXSign); // maybe maxScrollX is negative position.x = between(roundX, Math.min( this .minScrollX, this .maxScrollX), Math.max( this .minScrollX, this .maxScrollX)); } if (hasVerticalScroll) { var roundY = Math.round( this .ratioY * y * this .translateYSign); // maybe maxScrollY is negative position.y = between(roundY, Math.min( this .minScrollY, this .maxScrollY), Math.max( this .minScrollY, this .maxScrollY)); } return position; }; Indicator.prototype.destroy = function () { if ( this .options.interactive !== false ) { this .startEventRegister.destroy(); this .moveEventRegister.destroy(); this .endEventRegister.destroy(); } this .hooksFn.forEach( function (item) { var hooks = item[0]; var hooksName = item[1]; var handlerFn = item[2]; hooks.off(hooksName, handlerFn); }); this .hooksFn.length = 0; }; return Indicator; }()); var Indicators = /** @class */ ( function () { function Indicators(scroll) { this .scroll = scroll; this .options = []; this .indicators = []; this .handleOptions(); this .handleHooks(); } Indicators.prototype.handleOptions = function () { var UserIndicatorsOptions = this .scroll.options.indicators; assert(Array.isArray(UserIndicatorsOptions), "'indicators' must be an array." ); for ( var _i = 0, UserIndicatorsOptions_1 = UserIndicatorsOptions; _i < UserIndicatorsOptions_1.length; _i++) { var indicatorOptions = UserIndicatorsOptions_1[_i]; assert(!!indicatorOptions.relationElement, "'relationElement' must be a HTMLElement." ); this .createIndicators(indicatorOptions); } }; Indicators.prototype.createIndicators = function (options) { this .indicators.push( new Indicator( this .scroll, options)); }; Indicators.prototype.handleHooks = function () { var _this = this ; var scrollHooks = this .scroll.hooks; scrollHooks.on(scrollHooks.eventTypes.destroy, function () { for ( var _i = 0, _a = _this.indicators; _i < _a.length; _i++) { var indicator = _a[_i]; indicator.destroy(); } _this.indicators = []; }); }; Indicators.pluginName = 'indicators' ; return Indicators; }()); BScroll.use(MouseWheel) .use(ObserveDOM) .use(PullDown) .use(PullUp) .use(ScrollBar) .use(Slide) .use(Wheel) .use(Zoom) .use(NestedScroll) .use(InfinityScroll) .use(Movable) .use(ObserveImage) .use(Indicators); exports.Behavior = Behavior; exports.CustomOptions = CustomOptions; exports.Indicators = Indicators; exports.InfinityScroll = InfinityScroll; exports.MouseWheel = MouseWheel; exports.Movable = Movable; exports.NestedScroll = NestedScroll; exports.ObserveDom = ObserveDOM; exports.ObserveImage = ObserveImage; exports.PullDownRefresh = PullDown; exports.PullUpLoad = PullUp; exports.ScrollBar = ScrollBar; exports.Slide = Slide; exports.Wheel = Wheel; exports.Zoom = Zoom; exports.createBScroll = createBScroll; exports[ "default" ] = BScroll; Object.defineProperty(exports, '__esModule' , { value: true }); })); |
1 | <br><br><br>iscroll<br><br> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 | /*! iScroll v5.1.2 ~ (c) 2008-2014 Matteo Spinelli ~ http://cubiq.org/license */ ( function (window, document, Math) { //请求动画帧 var rAF = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback) { window.setTimeout(callback, 1000 / 60); }; //显示器16.7ms刷新间隔之前发生了其他绘制请求(setTimeout),导致所有帧丢失,setTimeout的定时器值推荐最小使用16.7ms的原因(16.7 = 1000 / 60, 即每秒60帧) //requestAnimationFrame与setTimeout的不同在于,前者跟着浏览器重绘时间走,不存在后者丢帧的问题 var utils = ( function () { var me = {}; var _elementStyle = document.createElement( 'div' ).style; //获取浏览器特性前缀 var _vendor = ( function () { var vendors = [ 't' , 'webkitT' , 'MozT' , 'msT' , 'OT' ], transform, i = 0, l = vendors.length; for ( ; i < l; i++ ) { transform = vendors[i] + 'ransform' ; if ( transform in _elementStyle ) return vendors[i].substr(0, vendors[i].length-1); } return false ; })(); //拼装样式属性名 function _prefixStyle (style) { if ( _vendor === false ) return false ; if ( _vendor === '' ) return style; return _vendor + style.charAt(0).toUpperCase() + style.substr(1); } //获取当前时间 me.getTime = Date.now || function getTime () { return new Date().getTime(); }; //对象复制 me.extend = function (target, obj) { for ( var i in obj ) { target[i] = obj[i]; } }; //事件 me.addEvent = function (el, type, fn, capture) { el.addEventListener(type, fn, !!capture); }; me.removeEvent = function (el, type, fn, capture) { el.removeEventListener(type, fn, !!capture); }; //MSPointerEvent 指针事件是一些事件和相关接口,用于处理来自鼠标、手写笔或触摸屏等设备的硬件不可知的指针输入,IE10引入,IE11去掉前缀,其他浏览器都不支持指针事件。 me.prefixPointerEvent = function (pointerEvent) { return window.MSPointerEvent ? 'MSPointer' + pointerEvent.charAt(9).toUpperCase() + pointerEvent.substr(10): pointerEvent; }; //deceleration减速 /** * 根据我们的拖动返回运动的长度与耗时,用于惯性拖动判断 * @param current 当前鼠标位置 * @param start touchStart时候记录的Y(可能是X)的开始位置,但是在touchmove时候可能被重写 * @param time touchstart到手指离开时候经历的时间,同样可能被touchmove重写 * @param lowerMargin y可移动的最大距离,这个一般为计算得出 this.wrapperHeight - this.scrollerHeight * @param wrapperSize 如果有边界距离的话就是可拖动,不然碰到0的时候便停止 * @param deceleration 匀减速 * @returns {{destination: number, duration: number}} */ me.momentum = function (current, start, time, lowerMargin, wrapperSize, deceleration) { var distance = current - start, speed = Math.abs(distance) / time, destination, duration; //减速变量 deceleration = deceleration === undefined ? 0.0006 : deceleration; //减速路程 destination = current + ( speed * speed ) / ( 2 * deceleration ) * ( distance < 0 ? -1 : 1 ); //持续时间 duration = speed / deceleration; if ( destination < lowerMargin ) { destination = wrapperSize ? lowerMargin - ( wrapperSize / 2.5 * ( speed / 8 ) ) : lowerMargin; distance = Math.abs(destination - current); duration = distance / speed; } else if ( destination > 0 ) { destination = wrapperSize ? wrapperSize / 2.5 * ( speed / 8 ) : 0; distance = Math.abs(current) + destination; duration = distance / speed; } return { destination: Math.round(destination), duration: duration }; }; var _transform = _prefixStyle( 'transform' ); me.extend(me, { hasTransform: _transform !== false , hasPerspective: _prefixStyle( 'perspective' ) in _elementStyle, //透视 hasTouch: 'ontouchstart' in window, hasPointer: window.PointerEvent || window.MSPointerEvent, // IE10 is prefixed hasTransition: _prefixStyle( 'transition' ) in _elementStyle }); // This should find all Android browsers lower than build 535.19 (both stock browser and webview) 低版本安卓机 me.isBadAndroid = /Android /.test(window.navigator.appVersion) && !(/Chrome\/\d/.test(window.navigator.appVersion)); me.extend(me.style = {}, { transform: _transform, transitionTimingFunction: _prefixStyle( 'transitionTimingFunction' ), transitionDuration: _prefixStyle( 'transitionDuration' ), transitionDelay: _prefixStyle( 'transitionDelay' ), transformOrigin: _prefixStyle( 'transformOrigin' ) }); me.hasClass = function (e, c) { var re = new RegExp( "(^|\\s)" + c + "(\\s|$)" ); return re.test(e.className); }; me.addClass = function (e, c) { if ( me.hasClass(e, c) ) { return ; } var newclass = e.className.split( ' ' ); newclass.push(c); e.className = newclass.join( ' ' ); }; me.removeClass = function (e, c) { if ( !me.hasClass(e, c) ) { return ; } var re = new RegExp( "(^|\\s)" + c + "(\\s|$)" , 'g' ); e.className = e.className.replace(re, ' ' ); }; me.offset = function (el) { var left = -el.offsetLeft, top = -el.offsetTop; // jshint -W084 while (el = el.offsetParent) { left -= el.offsetLeft; top -= el.offsetTop; } // jshint +W084 return { left: left, top: top }; }; // 配合config里面的preventDefaultException属性,不对匹配到的element使用e.preventDefault()。 me.preventDefaultException = function (el, exceptions) { for ( var i in exceptions ) { if ( exceptions[i].test(el[i]) ) { return true ; } } return false ; }; // 事件类型 me.extend(me.eventType = {}, { touchstart: 1, touchmove: 1, touchend: 1, mousedown: 2, mousemove: 2, mouseup: 2, pointerdown: 3, pointermove: 3, pointerup: 3, MSPointerDown: 3, MSPointerMove: 3, MSPointerUp: 3 }); // 缓动函数 me.extend(me.ease = {}, { quadratic: { style: 'cubic-bezier(0.25, 0.46, 0.45, 0.94)' , fn: function (k) { return k * ( 2 - k ); } }, circular: { style: 'cubic-bezier(0.1, 0.57, 0.1, 1)' , // Not properly "circular" but this looks better, it should be (0.075, 0.82, 0.165, 1) fn: function (k) { return Math.sqrt( 1 - ( --k * k ) ); } }, back: { style: 'cubic-bezier(0.175, 0.885, 0.32, 1.275)' , fn: function (k) { var b = 4; return ( k = k - 1 ) * k * ( ( b + 1 ) * k + b ) + 1; } }, bounce: { style: '' , fn: function (k) { if ( ( k /= 1 ) < ( 1 / 2.75 ) ) { return 7.5625 * k * k; } else if ( k < ( 2 / 2.75 ) ) { return 7.5625 * ( k -= ( 1.5 / 2.75 ) ) * k + 0.75; } else if ( k < ( 2.5 / 2.75 ) ) { return 7.5625 * ( k -= ( 2.25 / 2.75 ) ) * k + 0.9375; } else { return 7.5625 * ( k -= ( 2.625 / 2.75 ) ) * k + 0.984375; } } }, elastic: { style: '' , fn: function (k) { var f = 0.22, e = 0.4; if ( k === 0 ) { return 0; } if ( k == 1 ) { return 1; } return ( e * Math.pow( 2, - 10 * k ) * Math.sin( ( k - f / 4 ) * ( 2 * Math.PI ) / f ) + 1 ); } } }); me.tap = function (e, eventName) { var ev = document.createEvent( 'Event' ); /** 只有在新创建的 Event 对象被 Document 对象或 Element 对象的 dispatchEvent() 方法分派之前,才能调用 Event.initEvent() 方法 初始化新事件对象的属性 */ ev.initEvent(eventName, true , true ); ev.pageX = e.pageX; ev.pageY = e.pageY; //事件触发器就是用来触发某个元素下的某个事件 e.target.dispatchEvent(ev); }; me.click = function (e) { var target = e.target, ev; //不是select/input/textarea就创建事件 if ( !(/(SELECT|INPUT|TEXTAREA)/i).test(target.tagName) ) { ev = document.createEvent( 'MouseEvents' ); ev.initMouseEvent( 'click' , true , true , e.view, 1, target.screenX, target.screenY, target.clientX, target.clientY, e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, 0, null ); ev._constructed = true ; target.dispatchEvent(ev); } }; return me; })(); function IScroll (el, options) { //传入的元素 必须要有子元素 this .wrapper = typeof el == 'string' ? document.querySelector(el) : el; //子元素 实际滑动元素 this .scroller = this .wrapper.children[0]; this .scrollerStyle = this .scroller.style; // cache style for better performance this .options = { // INSERT POINT: OPTIONS startX: 0, startY: 0, //默认是Y轴上下滚动 scrollY: true , //方向锁定阈值,比如用户点击屏幕后,x与y之间差距大于5px,判断用户的拖动意图,是x方向拖动还是y方向 directionLockThreshold: 5, //是否有惯性缓冲动画 momentum: true , //超出边界时候是否还能拖动 bounce: true , //超出边界还原时间点 bounceTime: 600, //超出边界返回的动画 bounceEasing: '' , //是否阻止默认滚动事件 preventDefault: true , //当遇到表单元素则不阻止冒泡,而是弹出系统自带相应的输入控件 preventDefaultException: { tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT)$/ }, //硬件合成 通过GPU做图形渲染 HWCompositing: true , //使用transition useTransition: true , //使用transform useTransform: true }; for ( var i in options ) { this .options[i] = options[i]; } // Normalize options this .translateZ = this .options.HWCompositing && utils.hasPerspective ? ' translateZ(0)' : '' ; this .options.useTransition = utils.hasTransition && this .options.useTransition; this .options.useTransform = utils.hasTransform && this .options.useTransform; // 默认false,当你想保留原生垂直滚动但能够添加水平iscroll时候,设置为true,iscroll区域水平滑动时候的touch垂直移动,不会触发原生的垂直滑动 // 通常设置为:{eventPassthrough:true,scrollX:true,scrollY:false} // this .options.eventPassthrough = this .options.eventPassthrough === true ? 'vertical' : this .options.eventPassthrough; //当设置了eventPassthrough时候,不阻止默认的滚动事件 this .options.preventDefault = ! this .options.eventPassthrough && this .options.preventDefault; // If you want eventPassthrough I have to lock one of the axes // eventPassthrough可以传入具体名字(vertical/horizontal),这里更好说明了eventPassthrough的作用,对于传入的值来阻止相应轴的滑动事件 // eventPassthrough -> true -> vertical -> scrollY : false 垂直滚动忽略 this .options.scrollY = this .options.eventPassthrough == 'vertical' ? false : this .options.scrollY; this .options.scrollX = this .options.eventPassthrough == 'horizontal' ? false : this .options.scrollX; // With eventPassthrough we also need lockDirection mechanism // freeScroll只能与scrollX一起使用 {scrollX:true,freeScroll:true} this .options.freeScroll = this .options.freeScroll && ! this .options.eventPassthrough; this .options.directionLockThreshold = this .options.eventPassthrough ? 0 : this .options.directionLockThreshold; // 缓动函数 this .options.bounceEasing = typeof this .options.bounceEasing == 'string' ? utils.ease[ this .options.bounceEasing] || utils.ease.circular : this .options.bounceEasing; //window resize时重新获取位置 this .options.resizePolling = this .options.resizePolling === undefined ? 60 : this .options.resizePolling; if ( this .options.tap === true ) { this .options.tap = 'tap' ; } // INSERT POINT: NORMALIZATION // Some defaults this .x = 0; this .y = 0; this .directionX = 0; this .directionY = 0; this ._events = {}; // INSERT POINT: DEFAULTS // IScroll初始化 this ._init(); // this .refresh(); // 定位到最顶最左 this .scrollTo( this .options.startX, this .options.startY); // 代表“启用”的一个标志 this .enable(); } IScroll.prototype = { version: '5.1.2' , _init: function () { this ._initEvents(); // INSERT POINT: _init }, destroy: function () { this ._initEvents( true ); this ._execEvent( 'destroy' ); }, _transitionEnd: function (e) { if ( e.target != this .scroller || ! this .isInTransition ) { return ; } this ._transitionTime(); if ( ! this .resetPosition( this .options.bounceTime) ) { this .isInTransition = false ; this ._execEvent( 'scrollEnd' ); } }, _start: function (e) { // React to left mouse button only // 不是已经注册的事件,而且按下的不是左键,就返回不处理。 if ( utils.eventType[e.type] != 1 ) { if ( e.button !== 0 ) { return ; } } // 没有启用,返回不处理。 if ( ! this .enabled || ( this .initiated && utils.eventType[e.type] !== this .initiated) ) { return ; } // 如果 preventDefault === true 且 不是落后的安卓版本 且 不是需要过滤的target 就 阻止默认的行为 if ( this .options.preventDefault && !utils.isBadAndroid && !utils.preventDefaultException(e.target, this .options.preventDefaultException) ) { e.preventDefault(); } //e.touches表示的在屏幕上所有的触摸点,但事实上,绝大数手机浏览器并不支持多点触摸,所有用e.touchees[0]捕获一个触点就知足吧, //不要再奢望获取e.touches[>0]了,这个触点的位置可以有e.touches[0].pageX获取页面x坐标(像素); var point = e.touches ? e.touches[0] : e, pos; // 事件类型 this .initiated = utils.eventType[e.type]; this .moved = false ; //是否移动的标志 this .distX = 0; // this .distY = 0; // this .directionX = 0; //x方向移动数 this .directionY = 0; //y方向移动数 this .directionLocked = 0; //方向锁 // 设置运动时间 this ._transitionTime(); // 开始时间 this .startTime = utils.getTime(); // 如果还在运动中 if ( this .options.useTransition && this .isInTransition ) { this .isInTransition = false ; // 获取当前位置 pos = this .getComputedPosition(); // 滑动到当前位置 相当于停止于此处 this ._translate(Math.round(pos.x), Math.round(pos.y)); // 触发滑动结束回调函数 this ._execEvent( 'scrollEnd' ); } else if ( ! this .options.useTransition && this .isAnimating ) { this .isAnimating = false ; this ._execEvent( 'scrollEnd' ); } this .startX = this .x; // scroller开始位置x this .startY = this .y; // scroller开始位置y this .absStartX = this .x; // this .absStartY = this .y; // this .pointX = point.pageX; // 触点x this .pointY = point.pageY; // 触点y // 触发滑动前回调函数 this ._execEvent( 'beforeScrollStart' ); }, _move: function (e) { // 禁止 or 不存在此eventType 则返回 if ( ! this .enabled || utils.eventType[e.type] !== this .initiated ) { return ; } if ( this .options.preventDefault ) { // increases performance on Android? TODO: check! e.preventDefault(); } // point 触点 var point = e.touches ? e.touches[0] : e, deltaX = point.pageX - this .pointX, // 当前触点的pagex - 开始时的pagex = 触点档次增量x deltaY = point.pageY - this .pointY, // 触点增量y timestamp = utils.getTime(), newX, newY, absDistX, absDistY; // 最近上一次的触点位置 this .pointX = point.pageX; this .pointY = point.pageY; // 触点移动的距离 this .distX += deltaX; this .distY += deltaY; absDistX = Math.abs( this .distX); absDistY = Math.abs( this .distY); // We need to move at least 10 pixels for the scrolling to initiate // 触点至少移动10px才会触发scroll的move 并且 移动大于300ms if ( timestamp - this .endTime > 300 && (absDistX < 10 && absDistY < 10) ) { return ; } // If you are scrolling in one direction lock the other // 除非设置了freeScroll,否则将只允许同一时间一个方向滑动 if ( ! this .directionLocked && ! this .options.freeScroll ) { if ( absDistX > absDistY + this .options.directionLockThreshold ) { this .directionLocked = 'h' ; // lock horizontally } else if ( absDistY >= absDistX + this .options.directionLockThreshold ) { this .directionLocked = 'v' ; // lock vertically } else { this .directionLocked = 'n' ; // no lock } } if ( this .directionLocked == 'h' ) { if ( this .options.eventPassthrough == 'vertical' ) { e.preventDefault(); } else if ( this .options.eventPassthrough == 'horizontal' ) { this .initiated = false ; return ; } deltaY = 0; } else if ( this .directionLocked == 'v' ) { if ( this .options.eventPassthrough == 'horizontal' ) { e.preventDefault(); } else if ( this .options.eventPassthrough == 'vertical' ) { this .initiated = false ; return ; } deltaX = 0; } deltaX = this .hasHorizontalScroll ? deltaX : 0; deltaY = this .hasVerticalScroll ? deltaY : 0; // this.x this.y 是最近上一次的scroller位置 newX = this .x + deltaX; newY = this .y + deltaY; // Slow down if outside of the boundaries if ( newX > 0 || newX < this .maxScrollX ) { newX = this .options.bounce ? this .x + deltaX / 3 : newX > 0 ? 0 : this .maxScrollX; } if ( newY > 0 || newY < this .maxScrollY ) { newY = this .options.bounce ? this .y + deltaY / 3 : newY > 0 ? 0 : this .maxScrollY; } this .directionX = deltaX > 0 ? -1 : deltaX < 0 ? 1 : 0; // -1 手势向左 1 手势向右 this .directionY = deltaY > 0 ? -1 : deltaY < 0 ? 1 : 0; // -1 手势向上 1 手势向下 if ( ! this .moved ) { this ._execEvent( 'scrollStart' ); } this .moved = true ; this ._translate(newX, newY); /* REPLACE START: _move */ if ( timestamp - this .startTime > 300 ) { //300ms更新一次 this .startTime = timestamp; this .startX = this .x; this .startY = this .y; } /* REPLACE END: _move */ }, // touchEnd时候处理缓动 _end: function (e) { if ( ! this .enabled || utils.eventType[e.type] !== this .initiated ) { return ; } if ( this .options.preventDefault && !utils.preventDefaultException(e.target, this .options.preventDefaultException) ) { e.preventDefault(); } var point = e.changedTouches ? e.changedTouches[0] : e, momentumX, momentumY, duration = utils.getTime() - this .startTime, newX = Math.round( this .x), newY = Math.round( this .y), distanceX = Math.abs(newX - this .startX), //单次移动过程的x轴移动距离 distanceY = Math.abs(newY - this .startY), time = 0, easing = '' ; this .isInTransition = 0; this .initiated = 0; this .endTime = utils.getTime(); // reset if we are outside of the boundaries // 超过了边界就重新回到边界位 if ( this .resetPosition( this .options.bounceTime) ) { return ; } // 坚持滑动到 this .scrollTo(newX, newY); // ensures that the last position is rounded // we scrolled less than 10 pixels if ( ! this .moved ) { if ( this .options.tap ) { utils.tap(e, this .options.tap); } if ( this .options.click ) { utils.click(e); } this ._execEvent( 'scrollCancel' ); return ; } if ( this ._events.flick && duration < 200 && distanceX < 100 && distanceY < 100 ) { this ._execEvent( 'flick' ); return ; } // start momentum animation if needed // 获取缓动的距离 和 时间 { destination , duration } if ( this .options.momentum && duration < 300 ) { momentumX = this .hasHorizontalScroll ? utils.momentum( this .x, this .startX, duration, this .maxScrollX, this .options.bounce ? this .wrapperWidth : 0, this .options.deceleration) : { destination: newX, duration: 0 }; momentumY = this .hasVerticalScroll ? utils.momentum( this .y, this .startY, duration, this .maxScrollY, this .options.bounce ? this .wrapperHeight : 0, this .options.deceleration) : { destination: newY, duration: 0 }; newX = momentumX.destination; newY = momentumY.destination; time = Math.max(momentumX.duration, momentumY.duration); this .isInTransition = 1; } // INSERT POINT: _end if ( newX != this .x || newY != this .y ) { // change easing function when scroller goes out of the boundaries if ( newX > 0 || newX < this .maxScrollX || newY > 0 || newY < this .maxScrollY ) { easing = utils.ease.quadratic; } this .scrollTo(newX, newY, time, easing); return ; } this ._execEvent( 'scrollEnd' ); }, _resize: function () { var that = this ; clearTimeout( this .resizeTimeout); this .resizeTimeout = setTimeout( function () { that.refresh(); }, this .options.resizePolling); }, /** * 重新定位 */ resetPosition: function (time) { var x = this .x, y = this .y; time = time || 0; /** * 如果禁止水平滑动或者x大于0,x=0。如果可以滑动的情况,x应该是小于0的。 * 否则(可水平滑动),x为maxScrollX即最左 */ if ( ! this .hasHorizontalScroll || this .x > 0 ) { x = 0; } else if ( this .x < this .maxScrollX ) { x = this .maxScrollX; } /** * 如果禁止垂直滑动或者y大于0,y=0。如果可以滑动的情况,y应该是小于0的。 * 否则(可垂直滑动),y为maxScrollY即最上 */ if ( ! this .hasVerticalScroll || this .y > 0 ) { y = 0; } else if ( this .y < this .maxScrollY ) { y = this .maxScrollY; } // 初始化时候x y 都是0 返回。 if ( x == this .x && y == this .y ) { return false ; } this .scrollTo(x, y, time, this .options.bounceEasing); return true ; }, /** * scroll关闭的标志 */ disable: function () { this .enabled = false ; }, /** * scroll启用的标志 */ enable: function () { this .enabled = true ; }, /** * 重新获取位置等参数信息 */ refresh: function () { var rf = this .wrapper.offsetHeight; // Force reflow // 获取包含块的宽度/高度 this .wrapperWidth = this .wrapper.clientWidth; this .wrapperHeight = this .wrapper.clientHeight; /* REPLACE START: refresh */ // 滑动区的高度/宽度 this .scrollerWidth = this .scroller.offsetWidth; this .scrollerHeight = this .scroller.offsetHeight; // 最多允许滑动的x/y this .maxScrollX = this .wrapperWidth - this .scrollerWidth; this .maxScrollY = this .wrapperHeight - this .scrollerHeight; /* REPLACE END: refresh */ // 是否可以垂直/水平滑动 this .hasHorizontalScroll = this .options.scrollX && this .maxScrollX < 0; this .hasVerticalScroll = this .options.scrollY && this .maxScrollY < 0; if ( ! this .hasHorizontalScroll ) { this .maxScrollX = 0; this .scrollerWidth = this .wrapperWidth; } if ( ! this .hasVerticalScroll ) { this .maxScrollY = 0; this .scrollerHeight = this .wrapperHeight; } this .endTime = 0; this .directionX = 0; this .directionY = 0; // 获取包含块的offsetLeft offsetTop this .wrapperOffset = utils.offset( this .wrapper); this ._execEvent( 'refresh' ); this .resetPosition(); // INSERT POINT: _refresh }, /** * 自定义事件三件套,不解释。 */ on: function (type, fn) { if ( ! this ._events[type] ) { this ._events[type] = []; } this ._events[type].push(fn); }, off: function (type, fn) { if ( ! this ._events[type] ) { return ; } var index = this ._events[type].indexOf(fn); if ( index > -1 ) { this ._events[type].splice(index, 1); } }, _execEvent: function (type) { if ( ! this ._events[type] ) { return ; } var i = 0, l = this ._events[type].length; if ( !l ) { return ; } for ( ; i < l; i++ ) { this ._events[type][i].apply( this , [].slice.call(arguments, 1)); } }, scrollBy: function (x, y, time, easing) { x = this .x + x; y = this .y + y; time = time || 0; this .scrollTo(x, y, time, easing); }, /** * * @param x 为移动的x轴坐标 * @param y 为移动的y轴坐标 * @param time 为移动时间 * @param easing 为移动的动画效果 */ scrollTo: function (x, y, time, easing) { easing = easing || utils.ease.circular; this .isInTransition = this .options.useTransition && time > 0; if ( !time || ( this .options.useTransition && easing.style) ) { this ._transitionTimingFunction(easing.style); this ._transitionTime(time); this ._translate(x, y); } else { this ._animate(x, y, time, easing.fn); } }, /** * 这个方法实际上是对scrollTo的进一步封装,滚动到相应的元素区域。 * @param el 为需要滚动到的元素引用 * @param time 为滚动时间 * @param offsetX 为X轴偏移量 * @param offsetY 为Y轴偏移量 * @param easing 动画效果 */ scrollToElement: function (el, time, offsetX, offsetY, easing) { el = el.nodeType ? el : this .scroller.querySelector(el); if ( !el ) { return ; } var pos = utils.offset(el); pos.left -= this .wrapperOffset.left; pos.top -= this .wrapperOffset.top; // if offsetX/Y are true we center the element to the screen if ( offsetX === true ) { offsetX = Math.round(el.offsetWidth / 2 - this .wrapper.offsetWidth / 2); } if ( offsetY === true ) { offsetY = Math.round(el.offsetHeight / 2 - this .wrapper.offsetHeight / 2); } pos.left -= offsetX || 0; pos.top -= offsetY || 0; pos.left = pos.left > 0 ? 0 : pos.left < this .maxScrollX ? this .maxScrollX : pos.left; pos.top = pos.top > 0 ? 0 : pos.top < this .maxScrollY ? this .maxScrollY : pos.top; time = time === undefined || time === null || time === 'auto' ? Math.max(Math.abs( this .x-pos.left), Math.abs( this .y-pos.top)) : time; this .scrollTo(pos.left, pos.top, time, easing); }, // 动画运动时间 _transitionTime: function (time) { time = time || 0; this .scrollerStyle[utils.style.transitionDuration] = time + 'ms' ; // 落后的安卓机运动時間需要把0转0.001s if ( !time && utils.isBadAndroid ) { this .scrollerStyle[utils.style.transitionDuration] = '0.001s' ; } // INSERT POINT: _transitionTime }, _transitionTimingFunction: function (easing) { this .scrollerStyle[utils.style.transitionTimingFunction] = easing; // INSERT POINT: _transitionTimingFunction }, /** * @param x 为移动的x轴坐标 * @param y 为移动的y轴坐标 */ _translate: function (x, y) { if ( this .options.useTransform ) { /* REPLACE START: _translate */ this .scrollerStyle[utils.style.transform] = 'translate(' + x + 'px,' + y + 'px)' + this .translateZ; /* REPLACE END: _translate */ } else { x = Math.round(x); y = Math.round(y); this .scrollerStyle.left = x + 'px' ; this .scrollerStyle.top = y + 'px' ; } this .x = x; this .y = y; // INSERT POINT: _translate }, /** * @param remove 是否解绑事件 */ _initEvents: function (remove) { var eventType = remove ? utils.removeEvent : utils.addEvent, // 是否绑定到wrapper元素上 target = this .options.bindToWrapper ? this .wrapper : window; //旋转屏幕事件 eventType(window, 'orientationchange' , this ); eventType(window, 'resize' , this ); if ( this .options.click ) { eventType( this .wrapper, 'click' , this , true ); } // 如果没禁用鼠标,绑定鼠标事件,针对PC。 if ( ! this .options.disableMouse ) { eventType( this .wrapper, 'mousedown' , this ); eventType(target, 'mousemove' , this ); eventType(target, 'mousecancel' , this ); eventType(target, 'mouseup' , this ); } // 针对win phone的touch事件 if ( utils.hasPointer && ! this .options.disablePointer ) { eventType( this .wrapper, utils.prefixPointerEvent( 'pointerdown' ), this ); eventType(target, utils.prefixPointerEvent( 'pointermove' ), this ); eventType(target, utils.prefixPointerEvent( 'pointercancel' ), this ); eventType(target, utils.prefixPointerEvent( 'pointerup' ), this ); } //针对ios & Android的touch事件 if ( utils.hasTouch && ! this .options.disableTouch ) { eventType( this .wrapper, 'touchstart' , this ); eventType(target, 'touchmove' , this ); eventType(target, 'touchcancel' , this ); eventType(target, 'touchend' , this ); } // css3动画结束后的回调事件 eventType( this .scroller, 'transitionend' , this ); eventType( this .scroller, 'webkitTransitionEnd' , this ); eventType( this .scroller, 'oTransitionEnd' , this ); eventType( this .scroller, 'MSTransitionEnd' , this ); }, getComputedPosition: function () { //获取scroller的样式 var matrix = window.getComputedStyle( this .scroller, null ), x, y; //两种方式 transform 和 top/left ( transform在ios下,文本输入的光标fixed ) if ( this .options.useTransform ) { matrix = matrix[utils.style.transform].split( ')' )[0].split( ', ' ); x = +(matrix[12] || matrix[4]); y = +(matrix[13] || matrix[5]); } else { x = +matrix.left.replace(/[^-\d.]/g, '' ); y = +matrix.top.replace(/[^-\d.]/g, '' ); } //返回 (x ,y) or (top ,left) return { x: x, y: y }; }, /** * @param destx 为移动目的地的x轴坐标 * @param desty 为移动目的地的y轴坐标 * @param duration 为移动的时间 * @param easingFn 为移动缓动函数 */ _animate: function (destX, destY, duration, easingFn) { var that = this , startX = this .x, startY = this .y, startTime = utils.getTime(), destTime = startTime + duration; function step () { var now = utils.getTime(), newX, newY, easing; if ( now >= destTime ) { that.isAnimating = false ; that._translate(destX, destY); if ( !that.resetPosition(that.options.bounceTime) ) { that._execEvent( 'scrollEnd' ); } return ; } now = ( now - startTime ) / duration; easing = easingFn(now); newX = ( destX - startX ) * easing + startX; newY = ( destY - startY ) * easing + startY; that._translate(newX, newY); if ( that.isAnimating ) { rAF(step); } } this .isAnimating = true ; step(); }, handleEvent: function (e) { switch ( e.type ) { case 'touchstart' : case 'pointerdown' : case 'MSPointerDown' : case 'mousedown' : this ._start(e); break ; case 'touchmove' : case 'pointermove' : case 'MSPointerMove' : case 'mousemove' : this ._move(e); break ; case 'touchend' : case 'pointerup' : case 'MSPointerUp' : case 'mouseup' : case 'touchcancel' : case 'pointercancel' : case 'MSPointerCancel' : case 'mousecancel' : this ._end(e); break ; case 'orientationchange' : case 'resize' : this ._resize(); break ; case 'transitionend' : case 'webkitTransitionEnd' : case 'oTransitionEnd' : case 'MSTransitionEnd' : this ._transitionEnd(e); break ; case 'wheel' : case 'DOMMouseScroll' : case 'mousewheel' : this ._wheel(e); break ; case 'keydown' : this ._key(e); break ; case 'click' : if ( !e._constructed ) { e.preventDefault(); e.stopPropagation(); } break ; } } }; IScroll.utils = utils; if ( typeof module != 'undefined' && module.exports ) { module.exports = IScroll; } else { window.IScroll = IScroll; } })(window, document, Math); |
1 | <br><br> |
1 | 本文地址:<a href= "http://www.cnblogs.com/surfaces/" target= "_blank" >http://www.cnblogs.com/surfaces/</a> |
1 |
标签:
移动端
, requestAnimationFrame
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话