vuescroll-native.js 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577
  1. /*
  2. * Vuescroll v4.18.1
  3. * (c) 2018-2023 Yi(Yves) Wang
  4. * Released under the MIT License
  5. * Github: https://github.com/YvesCoding/vuescroll
  6. * Website: http://vuescrolljs.yvescoding.me/
  7. */
  8. (function (global, factory) {
  9. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('vue')) :
  10. typeof define === 'function' && define.amd ? define(['vue'], factory) :
  11. (global = global || self, global.vuescroll = factory(global.Vue));
  12. }(this, (function (Vue) { 'use strict';
  13. Vue = Vue && Object.prototype.hasOwnProperty.call(Vue, 'default') ? Vue['default'] : Vue;
  14. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
  15. return typeof obj;
  16. } : function (obj) {
  17. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  18. };
  19. var classCallCheck = function (instance, Constructor) {
  20. if (!(instance instanceof Constructor)) {
  21. throw new TypeError("Cannot call a class as a function");
  22. }
  23. };
  24. var createClass = function () {
  25. function defineProperties(target, props) {
  26. for (var i = 0; i < props.length; i++) {
  27. var descriptor = props[i];
  28. descriptor.enumerable = descriptor.enumerable || false;
  29. descriptor.configurable = true;
  30. if ("value" in descriptor) descriptor.writable = true;
  31. Object.defineProperty(target, descriptor.key, descriptor);
  32. }
  33. }
  34. return function (Constructor, protoProps, staticProps) {
  35. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  36. if (staticProps) defineProperties(Constructor, staticProps);
  37. return Constructor;
  38. };
  39. }();
  40. var defineProperty = function (obj, key, value) {
  41. if (key in obj) {
  42. Object.defineProperty(obj, key, {
  43. value: value,
  44. enumerable: true,
  45. configurable: true,
  46. writable: true
  47. });
  48. } else {
  49. obj[key] = value;
  50. }
  51. return obj;
  52. };
  53. var _extends = Object.assign || function (target) {
  54. for (var i = 1; i < arguments.length; i++) {
  55. var source = arguments[i];
  56. for (var key in source) {
  57. if (Object.prototype.hasOwnProperty.call(source, key)) {
  58. target[key] = source[key];
  59. }
  60. }
  61. }
  62. return target;
  63. };
  64. var toConsumableArray = function (arr) {
  65. if (Array.isArray(arr)) {
  66. for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
  67. return arr2;
  68. } else {
  69. return Array.from(arr);
  70. }
  71. };
  72. function isIE() {
  73. /* istanbul ignore if */
  74. if (isServer()) return false;
  75. var agent = navigator.userAgent.toLowerCase();
  76. return agent.indexOf('msie') !== -1 || agent.indexOf('trident') !== -1 || agent.indexOf(' edge/') !== -1;
  77. }
  78. var isIos = function isIos() {
  79. /* istanbul ignore if */
  80. if (isServer()) return false;
  81. var u = navigator.userAgent;
  82. return !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
  83. };
  84. /* istanbul ignore next */
  85. var isServer = function isServer() {
  86. return Vue.prototype.$isServer;
  87. };
  88. var touchManager = function () {
  89. function touchManager() {
  90. classCallCheck(this, touchManager);
  91. }
  92. createClass(touchManager, [{
  93. key: 'getEventObject',
  94. value: function getEventObject(originEvent) {
  95. return this.touchObject ? this.isTouch ? originEvent.touches : [originEvent] : null;
  96. }
  97. }, {
  98. key: 'getTouchObject',
  99. value: function getTouchObject() /* istanbul ignore next */{
  100. if (isServer()) return null;
  101. this.isTouch = false;
  102. var agent = navigator.userAgent,
  103. platform = navigator.platform,
  104. touchObject = {};
  105. touchObject.touch = !!('ontouchstart' in window && !window.opera || 'msmaxtouchpoints' in window.navigator || 'maxtouchpoints' in window.navigator || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0);
  106. touchObject.nonDeskTouch = touchObject.touch && !/win32/i.test(platform) || touchObject.touch && /win32/i.test(platform) && /mobile/i.test(agent);
  107. touchObject.eventType = 'onmousedown' in window && !touchObject.nonDeskTouch ? 'mouse' : 'ontouchstart' in window ? 'touch' : 'msmaxtouchpoints' in window.navigator || navigator.msMaxTouchPoints > 0 ? 'mstouchpoints' : 'maxtouchpoints' in window.navigator || navigator.maxTouchPoints > 0 ? 'touchpoints' : 'mouse';
  108. switch (touchObject.eventType) {
  109. case 'mouse':
  110. touchObject.touchstart = 'mousedown';
  111. touchObject.touchend = 'mouseup';
  112. touchObject.touchmove = 'mousemove';
  113. touchObject.touchenter = 'mouseenter';
  114. touchObject.touchmove = 'mousemove';
  115. touchObject.touchleave = 'mouseleave';
  116. break;
  117. case 'touch':
  118. touchObject.touchstart = 'touchstart';
  119. touchObject.touchend = 'touchend';
  120. touchObject.touchmove = 'touchmove';
  121. touchObject.touchcancel = 'touchcancel';
  122. touchObject.touchenter = 'touchstart';
  123. touchObject.touchmove = 'touchmove';
  124. touchObject.touchleave = 'touchend';
  125. this.isTouch = true;
  126. break;
  127. case 'mstouchpoints':
  128. touchObject.touchstart = 'MSPointerDown';
  129. touchObject.touchend = 'MSPointerUp';
  130. touchObject.touchmove = 'MSPointerMove';
  131. touchObject.touchcancel = 'MSPointerCancel';
  132. touchObject.touchenter = 'MSPointerDown';
  133. touchObject.touchmove = 'MSPointerMove';
  134. touchObject.touchleave = 'MSPointerUp';
  135. break;
  136. case 'touchpoints':
  137. touchObject.touchstart = 'pointerdown';
  138. touchObject.touchend = 'pointerup';
  139. touchObject.touchmove = 'pointermove';
  140. touchObject.touchcancel = 'pointercancel';
  141. touchObject.touchenter = 'pointerdown';
  142. touchObject.touchmove = 'pointermove';
  143. touchObject.touchleave = 'pointerup';
  144. break;
  145. }
  146. return this.touchObject = touchObject;
  147. }
  148. }]);
  149. return touchManager;
  150. }();
  151. /**
  152. * ZoomManager
  153. * Get the browser zoom ratio
  154. */
  155. var ZoomManager = function () {
  156. function ZoomManager() {
  157. var _this = this;
  158. classCallCheck(this, ZoomManager);
  159. this.originPixelRatio = this.getRatio();
  160. this.lastPixelRatio = this.originPixelRatio;
  161. window.addEventListener('resize', function () {
  162. _this.lastPixelRatio = _this.getRatio();
  163. });
  164. }
  165. createClass(ZoomManager, [{
  166. key: 'getRatio',
  167. value: function getRatio() {
  168. var ratio = 0;
  169. var screen = window.screen;
  170. var ua = navigator.userAgent.toLowerCase();
  171. if (window.devicePixelRatio !== undefined) {
  172. ratio = window.devicePixelRatio;
  173. } else if (~ua.indexOf('msie')) {
  174. if (screen.deviceXDPI && screen.logicalXDPI) {
  175. ratio = screen.deviceXDPI / screen.logicalXDPI;
  176. }
  177. } else if (window.outerWidth !== undefined && window.innerWidth !== undefined) {
  178. ratio = window.outerWidth / window.innerWidth;
  179. }
  180. if (ratio) {
  181. ratio = Math.round(ratio * 100);
  182. }
  183. return ratio;
  184. }
  185. }, {
  186. key: 'getRatioBetweenPreAndCurrent',
  187. value: function getRatioBetweenPreAndCurrent() {
  188. return this.originPixelRatio / this.lastPixelRatio;
  189. }
  190. }]);
  191. return ZoomManager;
  192. }();
  193. function deepCopy(from, to, shallow) {
  194. if (shallow && isUndef(to)) {
  195. return from;
  196. }
  197. if (isArray(from)) {
  198. to = [];
  199. from.forEach(function (item, index) {
  200. to[index] = deepCopy(item, to[index]);
  201. });
  202. } else if (from) {
  203. if (!isPlainObj(from)) {
  204. return from;
  205. }
  206. to = {};
  207. for (var key in from) {
  208. to[key] = _typeof(from[key]) === 'object' ? deepCopy(from[key], to[key]) : from[key];
  209. }
  210. }
  211. return to;
  212. }
  213. function mergeObject(from, to, force, shallow) {
  214. if (shallow && isUndef(to)) {
  215. return from;
  216. }
  217. to = to || {};
  218. if (isArray(from)) {
  219. if (!isArray(to) && force) {
  220. to = [];
  221. }
  222. if (isArray(to)) {
  223. from.forEach(function (item, index) {
  224. to[index] = mergeObject(item, to[index], force, shallow);
  225. });
  226. }
  227. } else if (from) {
  228. if (!isPlainObj(from)) {
  229. if (force) {
  230. to = from;
  231. }
  232. } else {
  233. for (var key in from) {
  234. if (_typeof(from[key]) === 'object') {
  235. if (isUndef(to[key])) {
  236. to[key] = deepCopy(from[key], to[key], shallow);
  237. } else {
  238. mergeObject(from[key], to[key], force, shallow);
  239. }
  240. } else {
  241. if (isUndef(to[key]) || force) to[key] = from[key];
  242. }
  243. }
  244. }
  245. }
  246. return to;
  247. }
  248. function defineReactive(target, key, source, souceKey) {
  249. /* istanbul ignore if */
  250. if (!source[key] && typeof source !== 'function') {
  251. return;
  252. }
  253. souceKey = souceKey || key;
  254. Object.defineProperty(target, key, {
  255. get: function get() {
  256. return source[souceKey];
  257. },
  258. configurable: true
  259. });
  260. }
  261. var scrollBarWidth = void 0;
  262. var zoomManager = void 0;
  263. function getGutter() {
  264. /* istanbul ignore next */
  265. if (isServer()) return 0;
  266. if (!zoomManager) {
  267. zoomManager = new ZoomManager();
  268. }
  269. if (scrollBarWidth !== undefined) return scrollBarWidth * zoomManager.getRatioBetweenPreAndCurrent();
  270. var outer = document.createElement('div');
  271. outer.style.visibility = 'hidden';
  272. outer.style.width = '100px';
  273. outer.style.position = 'absolute';
  274. outer.style.top = '-9999px';
  275. document.body.appendChild(outer);
  276. var widthNoScroll = outer.offsetWidth;
  277. outer.style.overflow = 'scroll';
  278. var inner = document.createElement('div');
  279. inner.style.width = '100%';
  280. outer.appendChild(inner);
  281. var widthWithScroll = inner.offsetWidth;
  282. outer.parentNode.removeChild(outer);
  283. scrollBarWidth = widthNoScroll - widthWithScroll;
  284. // multi the browser zoom
  285. if (!zoomManager) {
  286. zoomManager = new ZoomManager();
  287. }
  288. return scrollBarWidth * zoomManager.getRatioBetweenPreAndCurrent();
  289. }
  290. function eventCenter(dom, eventName, hander) {
  291. var capture = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  292. var type = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'on';
  293. type == 'on' ? dom.addEventListener(eventName, hander, capture) : dom.removeEventListener(eventName, hander, capture);
  294. }
  295. var warn = function warn(msg) {
  296. console.warn('[vuescroll] ' + msg);
  297. };
  298. function isChildInParent(child, parent) {
  299. var flag = false;
  300. if (!child || !parent) {
  301. return flag;
  302. }
  303. while (child.parentNode !== parent && child.parentNode.nodeType !== 9 && !child.parentNode._isVuescroll) {
  304. child = child.parentNode;
  305. }
  306. if (child.parentNode == parent) {
  307. flag = true;
  308. }
  309. return flag;
  310. }
  311. function getPrefix(global) {
  312. var docStyle = document.documentElement.style;
  313. var engine;
  314. /* istanbul ignore if */
  315. if (global.opera && Object.prototype.toString.call(opera) === '[object Opera]') {
  316. engine = 'presto';
  317. } /* istanbul ignore next */else if ('MozAppearance' in docStyle) {
  318. engine = 'gecko';
  319. } else if ('WebkitAppearance' in docStyle) {
  320. engine = 'webkit';
  321. } /* istanbul ignore next */else if (typeof navigator.cpuClass === 'string') {
  322. engine = 'trident';
  323. }
  324. var vendorPrefix = {
  325. trident: 'ms',
  326. gecko: 'moz',
  327. webkit: 'webkit',
  328. presto: 'O'
  329. }[engine];
  330. return vendorPrefix;
  331. }
  332. function getComplitableStyle(property, value) {
  333. /* istanbul ignore if */
  334. if (isServer()) return false;
  335. var compatibleValue = '-' + getPrefix(window) + '-' + value;
  336. var testElm = document.createElement('div');
  337. testElm.style[property] = compatibleValue;
  338. if (testElm.style[property] == compatibleValue) {
  339. return compatibleValue;
  340. }
  341. /* istanbul ignore next */
  342. return false;
  343. }
  344. /**
  345. * Insert children into user-passed slot at vnode level
  346. */
  347. function insertChildrenIntoSlot(h) {
  348. var parentVnode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  349. var childVNode = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
  350. var data = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  351. var swapChildren = arguments[4];
  352. /* istanbul ignore if */
  353. if (parentVnode && parentVnode.length > 1) {
  354. return swapChildren ? [].concat(toConsumableArray(childVNode), toConsumableArray(parentVnode)) : [].concat(toConsumableArray(parentVnode), toConsumableArray(childVNode));
  355. }
  356. parentVnode = parentVnode[0];
  357. var _getVnodeInfo = getVnodeInfo(parentVnode),
  358. ch = _getVnodeInfo.ch,
  359. tag = _getVnodeInfo.tag,
  360. isComponent = _getVnodeInfo.isComponent;
  361. if (isComponent) {
  362. parentVnode.data = mergeObject({ attrs: parentVnode.componentOptions.propsData }, parentVnode.data, false, // force: false
  363. true // shallow: true
  364. );
  365. }
  366. ch = swapChildren ? [].concat(toConsumableArray(childVNode), toConsumableArray(ch)) : [].concat(toConsumableArray(ch), toConsumableArray(childVNode));
  367. delete parentVnode.data.slot;
  368. return h(tag, mergeObject(data, parentVnode.data, false, true), ch);
  369. }
  370. /**
  371. * Get the info of a vnode,
  372. * vnode must be parentVnode
  373. */
  374. function getVnodeInfo(vnode) {
  375. if (!vnode || vnode.length > 1) return {};
  376. vnode = vnode[0] ? vnode[0] : vnode;
  377. var isComponent = !!vnode.componentOptions;
  378. var ch = void 0;
  379. var tag = void 0;
  380. if (isComponent) {
  381. ch = vnode.componentOptions.children || [];
  382. tag = vnode.componentOptions.tag;
  383. } else {
  384. ch = vnode.children || [];
  385. tag = vnode.tag;
  386. }
  387. return {
  388. isComponent: isComponent,
  389. ch: ch,
  390. tag: tag
  391. };
  392. }
  393. /**
  394. * Get the vuescroll instance instead of
  395. * user pass component like slot.
  396. */
  397. function getRealParent(ctx) {
  398. var parent = ctx.$parent;
  399. if (!parent._isVuescrollRoot && parent) {
  400. parent = parent.$parent;
  401. }
  402. return parent;
  403. }
  404. var isArray = function isArray(_) {
  405. return Array.isArray(_);
  406. };
  407. var isPlainObj = function isPlainObj(_) {
  408. return Object.prototype.toString.call(_) == '[object Object]';
  409. };
  410. var isUndef = function isUndef(_) {
  411. return typeof _ === 'undefined';
  412. };
  413. function getNumericValue(distance, size) {
  414. var number = void 0;
  415. if (!(number = /(-?\d+(?:\.\d+?)?)%$/.exec(distance))) {
  416. number = distance - 0;
  417. } else {
  418. number = number[1] - 0;
  419. number = size * number / 100;
  420. }
  421. return number;
  422. }
  423. function createStyle(styleId, cssText) {
  424. /* istanbul ignore if */
  425. if (isServer() || document.getElementById(styleId)) {
  426. return;
  427. }
  428. var head = document.head || doc.getElementsByTagName('head')[0];
  429. var style = document.createElement('style');
  430. style.id = styleId;
  431. style.type = 'text/css';
  432. /* istanbul ignore if */
  433. if (style.styleSheet) {
  434. style.styleSheet.cssText = cssText;
  435. } else {
  436. style.appendChild(document.createTextNode(cssText));
  437. }
  438. head.appendChild(style);
  439. }
  440. // Hide the ios native scrollbar.
  441. function createHideBarStyle() {
  442. /* istanbul ignore next */
  443. {
  444. var cssText = '.__hidebar::-webkit-scrollbar {\n width: 0;\n height: 0;\n }';
  445. createStyle('vuescroll-hide-ios-bar', cssText);
  446. }
  447. }
  448. var api = {
  449. mounted: function mounted() {
  450. vsInstances[this._uid] = this;
  451. },
  452. beforeDestroy: function beforeDestroy() {
  453. delete vsInstances[this._uid];
  454. },
  455. methods: {
  456. // public api
  457. scrollTo: function scrollTo(_ref, speed, easing) {
  458. var x = _ref.x,
  459. y = _ref.y;
  460. // istanbul ignore if
  461. if (speed === true || typeof speed == 'undefined') {
  462. speed = this.mergedOptions.scrollPanel.speed;
  463. }
  464. this.internalScrollTo(x, y, speed, easing);
  465. },
  466. scrollBy: function scrollBy(_ref2, speed, easing) {
  467. var _ref2$dx = _ref2.dx,
  468. dx = _ref2$dx === undefined ? 0 : _ref2$dx,
  469. _ref2$dy = _ref2.dy,
  470. dy = _ref2$dy === undefined ? 0 : _ref2$dy;
  471. var _getPosition = this.getPosition(),
  472. _getPosition$scrollLe = _getPosition.scrollLeft,
  473. scrollLeft = _getPosition$scrollLe === undefined ? 0 : _getPosition$scrollLe,
  474. _getPosition$scrollTo = _getPosition.scrollTop,
  475. scrollTop = _getPosition$scrollTo === undefined ? 0 : _getPosition$scrollTo;
  476. if (dx) {
  477. scrollLeft += getNumericValue(dx, this.scrollPanelElm.scrollWidth - this.$el.clientWidth);
  478. }
  479. if (dy) {
  480. scrollTop += getNumericValue(dy, this.scrollPanelElm.scrollHeight - this.$el.clientHeight);
  481. }
  482. this.internalScrollTo(scrollLeft, scrollTop, speed, easing);
  483. },
  484. scrollIntoView: function scrollIntoView(elm) {
  485. var animate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  486. var parentElm = this.$el;
  487. if (typeof elm === 'string') {
  488. elm = parentElm.querySelector(elm);
  489. }
  490. if (!isChildInParent(elm, parentElm)) {
  491. warn('The element or selector you passed is not the element of Vuescroll, please pass the element that is in Vuescroll to scrollIntoView API. ');
  492. return;
  493. }
  494. // parent elm left, top
  495. var _$el$getBoundingClien = this.$el.getBoundingClientRect(),
  496. left = _$el$getBoundingClien.left,
  497. top = _$el$getBoundingClien.top;
  498. // child elm left, top
  499. var _elm$getBoundingClien = elm.getBoundingClientRect(),
  500. childLeft = _elm$getBoundingClien.left,
  501. childTop = _elm$getBoundingClien.top;
  502. var diffX = left - childLeft;
  503. var diffY = top - childTop;
  504. this.scrollBy({
  505. dx: -diffX,
  506. dy: -diffY
  507. }, animate);
  508. },
  509. refresh: function refresh() {
  510. this.refreshInternalStatus();
  511. // refresh again to keep status is correct
  512. this.$nextTick(this.refreshInternalStatus);
  513. }
  514. }
  515. };
  516. /** Public Api */
  517. /**
  518. * Refresh all
  519. */
  520. var vsInstances = {};
  521. function refreshAll() {
  522. for (var vs in vsInstances) {
  523. vsInstances[vs].refresh();
  524. }
  525. }
  526. var baseConfig = {
  527. // vuescroll
  528. vuescroll: {
  529. // vuescroll's size(height/width) should be a percent(100%)
  530. // or be a number that is equal to its parentNode's width or
  531. // height ?
  532. sizeStrategy: 'percent',
  533. /** Whether to detect dom resize or not */
  534. detectResize: true,
  535. /** Enable locking to the main axis if user moves only slightly on one of them at start */
  536. locking: true
  537. },
  538. scrollPanel: {
  539. // when component mounted.. it will automatically scrolls.
  540. initialScrollY: false,
  541. initialScrollX: false,
  542. // feat: #11
  543. scrollingX: true,
  544. scrollingY: true,
  545. speed: 300,
  546. easing: undefined,
  547. // Sometimes, the nativebar maybe on the left,
  548. // See https://github.com/YvesCoding/vuescroll/issues/64
  549. verticalNativeBarPos: 'right',
  550. maxHeight: undefined,
  551. maxWidth: undefined
  552. },
  553. //
  554. rail: {
  555. background: '#01a99a',
  556. opacity: 0,
  557. border: 'none',
  558. /** Rail's size(Height/Width) , default -> 6px */
  559. size: '6px',
  560. /** Specify rail's border-radius, or the border-radius of rail and bar will be equal to the rail's size. default -> false **/
  561. specifyBorderRadius: false,
  562. /** Rail the distance from the two ends of the X axis and Y axis. **/
  563. gutterOfEnds: null,
  564. /** Rail the distance from the side of container. **/
  565. gutterOfSide: '2px',
  566. /** Whether to keep rail show or not, default -> false, event content height is not enough */
  567. keepShow: false
  568. },
  569. bar: {
  570. /** How long to hide bar after mouseleave, default -> 500 */
  571. showDelay: 500,
  572. /** Specify bar's border-radius, or the border-radius of rail and bar will be equal to the rail's size. default -> false **/
  573. specifyBorderRadius: false,
  574. /** Whether to show bar on scrolling, default -> true */
  575. onlyShowBarOnScroll: true,
  576. /** Whether to keep show or not, default -> false */
  577. keepShow: false,
  578. /** Bar's background , default -> #00a650 */
  579. background: 'rgb(3, 185, 118)',
  580. /** Bar's opacity, default -> 1 */
  581. opacity: 1,
  582. /** bar's size(Height/Width) , default -> 6px */
  583. size: '6px',
  584. minSize: 0,
  585. disable: false
  586. },
  587. scrollButton: {
  588. enable: false,
  589. background: 'rgb(3, 185, 118)',
  590. opacity: 1,
  591. step: 180,
  592. mousedownStep: 30
  593. }
  594. };
  595. /**
  596. * validate the options
  597. * @export
  598. * @param {any} ops
  599. */
  600. function validateOps(ops) {
  601. var renderError = false;
  602. var scrollPanel = ops.scrollPanel;
  603. var _ops$bar = ops.bar,
  604. vBar = _ops$bar.vBar,
  605. hBar = _ops$bar.hBar;
  606. var _ops$rail = ops.rail,
  607. vRail = _ops$rail.vRail,
  608. hRail = _ops$rail.hRail;
  609. // validate scrollPanel
  610. var initialScrollY = scrollPanel['initialScrollY'];
  611. var initialScrollX = scrollPanel['initialScrollX'];
  612. if (initialScrollY && !String(initialScrollY).match(/^\d+(\.\d+)?(%)?$/)) {
  613. warn('The prop `initialScrollY` or `initialScrollX` should be a percent number like `10%` or an exact number that greater than or equal to 0 like `100`.');
  614. }
  615. if (initialScrollX && !String(initialScrollX).match(/^\d+(\.\d+)?(%)?$/)) {
  616. warn('The prop `initialScrollY` or `initialScrollX` should be a percent number like `10%` or an exact number that greater than or equal to 0 like `100`.');
  617. }
  618. // validate deprecated vBar/hBar vRail/hRail
  619. if (vBar || hBar || vRail || hRail) {
  620. warn('The options: vRail, hRail, vBar, hBar have been deprecated since v4.7.0,' + 'please use corresponing rail/bar instead!');
  621. }
  622. if (_extraValidate) {
  623. _extraValidate = [].concat(_extraValidate);
  624. _extraValidate.forEach(function (hasError) {
  625. if (hasError(ops)) {
  626. renderError = true;
  627. }
  628. });
  629. }
  630. return renderError;
  631. }
  632. var _extraValidate = null;
  633. var extendOpts = function extendOpts(extraOpts, extraValidate) {
  634. extraOpts = [].concat(extraOpts);
  635. extraOpts.forEach(function (opts) {
  636. mergeObject(opts, baseConfig);
  637. });
  638. _extraValidate = extraValidate;
  639. };
  640. // all modes
  641. // some small changes.
  642. var smallChangeArray = ['mergedOptions.vuescroll.pullRefresh.tips', 'mergedOptions.vuescroll.pushLoad.tips', 'mergedOptions.vuescroll.scroller.disable', 'mergedOptions.rail', 'mergedOptions.bar'];
  643. var scrollMap = {
  644. vertical: {
  645. size: 'height',
  646. opsSize: 'width',
  647. posName: 'top',
  648. opposName: 'bottom',
  649. sidePosName: 'right',
  650. page: 'pageY',
  651. scroll: 'scrollTop',
  652. scrollSize: 'scrollHeight',
  653. offset: 'offsetHeight',
  654. client: 'clientY',
  655. axis: 'Y',
  656. scrollButton: {
  657. start: 'top',
  658. end: 'bottom'
  659. }
  660. },
  661. horizontal: {
  662. size: 'width',
  663. opsSize: 'height',
  664. posName: 'left',
  665. opposName: 'right',
  666. sidePosName: 'bottom',
  667. page: 'pageX',
  668. scroll: 'scrollLeft',
  669. scrollSize: 'scrollWidth',
  670. offset: 'offsetWidth',
  671. client: 'clientX',
  672. axis: 'X',
  673. scrollButton: {
  674. start: 'left',
  675. end: 'right'
  676. }
  677. }
  678. };
  679. function requestAnimationFrame(global) {
  680. // Check for request animation Frame support
  681. var requestFrame = global.requestAnimationFrame || global.webkitRequestAnimationFrame || global.mozRequestAnimationFrame || global.oRequestAnimationFrame;
  682. var isNative = !!requestFrame;
  683. if (requestFrame && !/requestAnimationFrame\(\)\s*\{\s*\[native code\]\s*\}/i.test(requestFrame.toString())) {
  684. isNative = false;
  685. }
  686. if (isNative) {
  687. return function (callback, root) {
  688. requestFrame(callback, root);
  689. };
  690. }
  691. var TARGET_FPS = 60;
  692. var requests = {};
  693. var rafHandle = 1;
  694. var intervalHandle = null;
  695. var lastActive = +new Date();
  696. return function (callback) {
  697. var callbackHandle = rafHandle++;
  698. // Store callback
  699. requests[callbackHandle] = callback;
  700. // Create timeout at first request
  701. if (intervalHandle === null) {
  702. intervalHandle = setInterval(function () {
  703. var time = +new Date();
  704. var currentRequests = requests;
  705. // Reset data structure before executing callbacks
  706. requests = {};
  707. for (var key in currentRequests) {
  708. if (currentRequests.hasOwnProperty(key)) {
  709. currentRequests[key](time);
  710. lastActive = time;
  711. }
  712. }
  713. // Disable the timeout when nothing happens for a certain
  714. // period of time
  715. if (time - lastActive > 2500) {
  716. clearInterval(intervalHandle);
  717. intervalHandle = null;
  718. }
  719. }, 1000 / TARGET_FPS);
  720. }
  721. return callbackHandle;
  722. };
  723. }
  724. var colorCache = {};
  725. var rgbReg = /rgb\(/;
  726. var extractRgbColor = /rgb\((.*)\)/;
  727. // Transform a common color int oa `rgbA` color
  728. function getRgbAColor(color, opacity) {
  729. var id = color + '&' + opacity;
  730. if (colorCache[id]) {
  731. return colorCache[id];
  732. }
  733. var div = document.createElement('div');
  734. div.style.background = color;
  735. document.body.appendChild(div);
  736. var computedColor = window.getComputedStyle(div).backgroundColor;
  737. document.body.removeChild(div);
  738. /* istanbul ignore if */
  739. if (!rgbReg.test(computedColor)) {
  740. return color;
  741. }
  742. return colorCache[id] = 'rgba(' + extractRgbColor.exec(computedColor)[1] + ', ' + opacity + ')';
  743. }
  744. var bar = {
  745. name: 'bar',
  746. props: {
  747. ops: Object,
  748. state: Object,
  749. hideBar: Boolean,
  750. otherBarHide: Boolean,
  751. type: String
  752. },
  753. computed: {
  754. bar: function bar() {
  755. return scrollMap[this.type];
  756. },
  757. barSize: function barSize() {
  758. return Math.max(this.state.size, this.ops.bar.minSize);
  759. },
  760. barRatio: function barRatio() {
  761. return (1 - this.barSize) / (1 - this.state.size);
  762. }
  763. },
  764. render: function render(h) {
  765. var _style, _style2, _barStyle;
  766. var vm = this;
  767. /** Get rgbA format background color */
  768. var railBackgroundColor = getRgbAColor(vm.ops.rail.background, vm.ops.rail.opacity);
  769. if (!this.touchManager) {
  770. this.touchManager = new touchManager();
  771. }
  772. /** Rail Data */
  773. var railSize = vm.ops.rail.size;
  774. var endPos = vm.otherBarHide ? 0 : railSize;
  775. var touchObj = vm.touchManager.getTouchObject();
  776. var rail = {
  777. class: '__rail-is-' + vm.type,
  778. style: (_style = {
  779. position: 'absolute',
  780. 'z-index': '1',
  781. borderRadius: vm.ops.rail.specifyBorderRadius || railSize,
  782. background: railBackgroundColor,
  783. border: vm.ops.rail.border
  784. }, defineProperty(_style, vm.bar.opsSize, railSize), defineProperty(_style, vm.bar.posName, vm.ops.rail['gutterOfEnds'] || 0), defineProperty(_style, vm.bar.opposName, vm.ops.rail['gutterOfEnds'] || endPos), defineProperty(_style, vm.bar.sidePosName, vm.ops.rail['gutterOfSide']), _style)
  785. };
  786. if (touchObj) {
  787. var _rail$on;
  788. rail.on = (_rail$on = {}, defineProperty(_rail$on, touchObj.touchenter, function () {
  789. vm.setRailHover();
  790. }), defineProperty(_rail$on, touchObj.touchleave, function () {
  791. vm.setRailLeave();
  792. }), _rail$on);
  793. }
  794. // left space for scroll button
  795. var buttonSize = vm.ops.scrollButton.enable ? railSize : 0;
  796. var barWrapper = {
  797. class: '__bar-wrap-is-' + vm.type,
  798. style: (_style2 = {
  799. position: 'absolute',
  800. borderRadius: vm.ops.rail.specifyBorderRadius || railSize
  801. }, defineProperty(_style2, vm.bar.posName, buttonSize), defineProperty(_style2, vm.bar.opposName, buttonSize), _style2),
  802. on: {}
  803. };
  804. var scrollDistance = vm.state.posValue * vm.state.size;
  805. var pos = scrollDistance * vm.barRatio / vm.barSize;
  806. var opacity = vm.state.opacity;
  807. var parent = getRealParent(this);
  808. // set class hook
  809. parent.setClassHook(this.type == 'vertical' ? 'vBarVisible' : 'hBarVisible', !!opacity);
  810. /** Scrollbar style */
  811. var barStyle = (_barStyle = {
  812. cursor: 'pointer',
  813. position: 'absolute',
  814. margin: 'auto',
  815. transition: 'opacity 0.5s',
  816. 'user-select': 'none',
  817. 'border-radius': 'inherit'
  818. }, defineProperty(_barStyle, vm.bar.size, vm.barSize * 100 + '%'), defineProperty(_barStyle, 'background', vm.ops.bar.background), defineProperty(_barStyle, vm.bar.opsSize, vm.ops.bar.size), defineProperty(_barStyle, 'opacity', opacity), defineProperty(_barStyle, 'transform', 'translate' + scrollMap[vm.type].axis + '(' + pos + '%)'), _barStyle);
  819. var bar = {
  820. style: barStyle,
  821. class: '__bar-is-' + vm.type,
  822. ref: 'thumb',
  823. on: {}
  824. };
  825. if (vm.type == 'vertical') {
  826. barWrapper.style.width = '100%';
  827. // Let bar to be on the center.
  828. bar.style.left = 0;
  829. bar.style.right = 0;
  830. } else {
  831. barWrapper.style.height = '100%';
  832. bar.style.top = 0;
  833. bar.style.bottom = 0;
  834. }
  835. /* istanbul ignore next */
  836. {
  837. var _touchObj = this.touchManager.getTouchObject();
  838. bar.on[_touchObj.touchstart] = this.createBarEvent();
  839. barWrapper.on[_touchObj.touchstart] = this.createTrackEvent();
  840. }
  841. return h(
  842. 'div',
  843. rail,
  844. [this.createScrollbarButton(h, 'start'), this.hideBar ? null : h(
  845. 'div',
  846. barWrapper,
  847. [h('div', bar)]
  848. ), this.createScrollbarButton(h, 'end')]
  849. );
  850. },
  851. data: function data() {
  852. return {
  853. isBarDragging: false
  854. };
  855. },
  856. methods: {
  857. setRailHover: function setRailHover() {
  858. var parent = getRealParent(this);
  859. var state = parent.vuescroll.state;
  860. if (!state.isRailHover) {
  861. state.isRailHover = true;
  862. parent.showBar();
  863. }
  864. },
  865. setRailLeave: function setRailLeave() {
  866. var parent = getRealParent(this);
  867. var state = parent.vuescroll.state;
  868. state.isRailHover = false;
  869. parent.hideBar();
  870. },
  871. setBarDrag: function setBarDrag(val) /* istanbul ignore next */{
  872. this.$emit('setBarDrag', this.isBarDragging = val);
  873. var parent = getRealParent(this);
  874. // set class hook
  875. parent.setClassHook(this.type == 'vertical' ? 'vBarDragging' : 'hBarDragging', !!val);
  876. },
  877. createBarEvent: function createBarEvent() {
  878. var ctx = this;
  879. var parent = getRealParent(ctx);
  880. var touchObj = ctx.touchManager.getTouchObject();
  881. function mousedown(e) /* istanbul ignore next */{
  882. var event = ctx.touchManager.getEventObject(e);
  883. if (!event) return;
  884. e.stopImmediatePropagation();
  885. e.preventDefault();
  886. event = event[0];
  887. document.onselectstart = function () {
  888. return false;
  889. };
  890. ctx.axisStartPos = event[ctx.bar.client] - ctx.$refs['thumb'].getBoundingClientRect()[ctx.bar.posName];
  891. // Tell parent that the mouse has been down.
  892. ctx.setBarDrag(true);
  893. eventCenter(document, touchObj.touchmove, mousemove);
  894. eventCenter(document, touchObj.touchend, mouseup);
  895. }
  896. function mousemove(e) /* istanbul ignore next */{
  897. if (!ctx.axisStartPos) {
  898. return;
  899. }
  900. var event = ctx.touchManager.getEventObject(e);
  901. if (!event) return;
  902. event = event[0];
  903. var thubmParent = ctx.$refs.thumb.parentNode;
  904. var delta = event[ctx.bar.client] - thubmParent.getBoundingClientRect()[ctx.bar.posName];
  905. delta = delta / ctx.barRatio;
  906. var percent = (delta - ctx.axisStartPos) / thubmParent[ctx.bar.offset];
  907. parent.scrollTo(defineProperty({}, ctx.bar.axis.toLowerCase(), parent.scrollPanelElm[ctx.bar.scrollSize] * percent), false);
  908. }
  909. function mouseup() /* istanbul ignore next */{
  910. ctx.setBarDrag(false);
  911. parent.hideBar();
  912. document.onselectstart = null;
  913. ctx.axisStartPos = 0;
  914. eventCenter(document, touchObj.touchmove, mousemove, false, 'off');
  915. eventCenter(document, touchObj.touchend, mouseup, false, 'off');
  916. }
  917. return mousedown;
  918. },
  919. createTrackEvent: function createTrackEvent() {
  920. var ctx = this;
  921. return function handleClickTrack(e) {
  922. var parent = getRealParent(ctx);
  923. var _ctx$bar = ctx.bar,
  924. client = _ctx$bar.client,
  925. offset = _ctx$bar.offset,
  926. posName = _ctx$bar.posName,
  927. axis = _ctx$bar.axis;
  928. var thumb = ctx.$refs['thumb'];
  929. e.preventDefault();
  930. e.stopImmediatePropagation();
  931. /* istanbul ignore if */
  932. if (!thumb) return;
  933. var barOffset = thumb[offset];
  934. var event = ctx.touchManager.getEventObject(e)[0];
  935. var percent = (event[client] - e.currentTarget.getBoundingClientRect()[posName] - barOffset / 2) / (e.currentTarget[offset] - barOffset);
  936. parent.scrollTo(defineProperty({}, axis.toLowerCase(), percent * 100 + '%'));
  937. };
  938. },
  939. // Scrollbuton relative things...
  940. createScrollbarButton: function createScrollbarButton(h, type /* start or end */) {
  941. var _style3;
  942. var barContext = this;
  943. if (!barContext.ops.scrollButton.enable) {
  944. return null;
  945. }
  946. var size = barContext.ops.rail.size;
  947. var _barContext$ops$scrol = barContext.ops.scrollButton,
  948. opacity = _barContext$ops$scrol.opacity,
  949. background = _barContext$ops$scrol.background;
  950. var borderColor = getRgbAColor(background, opacity);
  951. var wrapperProps = {
  952. class: ['__bar-button', '__bar-button-is-' + barContext.type + '-' + type],
  953. style: (_style3 = {}, defineProperty(_style3, barContext.bar.scrollButton[type], 0), defineProperty(_style3, 'width', size), defineProperty(_style3, 'height', size), defineProperty(_style3, 'position', 'absolute'), defineProperty(_style3, 'cursor', 'pointer'), defineProperty(_style3, 'display', 'table'), _style3),
  954. ref: type
  955. };
  956. var innerProps = {
  957. class: '__bar-button-inner',
  958. style: {
  959. border: 'calc(' + size + ' / 2.5) solid transparent',
  960. width: '0',
  961. height: '0',
  962. margin: 'auto',
  963. position: 'absolute',
  964. top: '0',
  965. bottom: '0',
  966. right: '0',
  967. left: '0'
  968. },
  969. on: {}
  970. };
  971. if (barContext.type == 'vertical') {
  972. if (type == 'start') {
  973. innerProps.style['border-bottom-color'] = borderColor;
  974. innerProps.style['transform'] = 'translateY(-25%)';
  975. } else {
  976. innerProps.style['border-top-color'] = borderColor;
  977. innerProps.style['transform'] = 'translateY(25%)';
  978. }
  979. } else {
  980. if (type == 'start') {
  981. innerProps.style['border-right-color'] = borderColor;
  982. innerProps.style['transform'] = 'translateX(-25%)';
  983. } else {
  984. innerProps.style['border-left-color'] = borderColor;
  985. innerProps.style['transform'] = 'translateX(25%)';
  986. }
  987. }
  988. /* istanbul ignore next */
  989. {
  990. var touchObj = this.touchManager.getTouchObject();
  991. innerProps.on[touchObj.touchstart] = this.createScrollButtonEvent(type, touchObj);
  992. }
  993. return h(
  994. 'div',
  995. wrapperProps,
  996. [h('div', innerProps)]
  997. );
  998. },
  999. createScrollButtonEvent: function createScrollButtonEvent(type, touchObj) {
  1000. var ctx = this;
  1001. var parent = getRealParent(ctx);
  1002. var _ctx$ops$scrollButton = ctx.ops.scrollButton,
  1003. step = _ctx$ops$scrollButton.step,
  1004. mousedownStep = _ctx$ops$scrollButton.mousedownStep;
  1005. var stepWithDirection = type == 'start' ? -step : step;
  1006. var mousedownStepWithDirection = type == 'start' ? -mousedownStep : mousedownStep;
  1007. var ref = requestAnimationFrame(window);
  1008. // bar props: type
  1009. var barType = ctx.type;
  1010. var isMouseDown = false;
  1011. var isMouseout = true;
  1012. var timeoutId = void 0;
  1013. function start(e) {
  1014. /* istanbul ignore if */
  1015. if (3 == e.which) {
  1016. return;
  1017. }
  1018. // set class hook
  1019. parent.setClassHook('cliking' + barType + type + 'Button', true);
  1020. e.stopImmediatePropagation();
  1021. e.preventDefault();
  1022. isMouseout = false;
  1023. parent.scrollBy(defineProperty({}, 'd' + ctx.bar.axis.toLowerCase(), stepWithDirection));
  1024. eventCenter(document, touchObj.touchend, endPress, false);
  1025. if (touchObj.touchstart == 'mousedown') {
  1026. var elm = ctx.$refs[type];
  1027. eventCenter(elm, 'mouseenter', enter, false);
  1028. eventCenter(elm, 'mouseleave', leave, false);
  1029. }
  1030. clearTimeout(timeoutId);
  1031. timeoutId = setTimeout(function () /* istanbul ignore next */{
  1032. isMouseDown = true;
  1033. ref(pressing, window);
  1034. }, 500);
  1035. }
  1036. function pressing() /* istanbul ignore next */{
  1037. if (isMouseDown && !isMouseout) {
  1038. parent.scrollBy(defineProperty({}, 'd' + ctx.bar.axis.toLowerCase(), mousedownStepWithDirection), false);
  1039. ref(pressing, window);
  1040. }
  1041. }
  1042. function endPress() {
  1043. clearTimeout(timeoutId);
  1044. isMouseDown = false;
  1045. eventCenter(document, touchObj.touchend, endPress, false, 'off');
  1046. if (touchObj.touchstart == 'mousedown') {
  1047. var elm = ctx.$refs[type];
  1048. eventCenter(elm, 'mouseenter', enter, false, 'off');
  1049. eventCenter(elm, 'mouseleave', leave, false, 'off');
  1050. }
  1051. parent.setClassHook('cliking' + barType + type + 'Button', false);
  1052. }
  1053. function enter() /* istanbul ignore next */{
  1054. isMouseout = false;
  1055. pressing();
  1056. }
  1057. function leave() /* istanbul ignore next */{
  1058. isMouseout = true;
  1059. }
  1060. return start;
  1061. }
  1062. }
  1063. };
  1064. function getBarData(vm, type) {
  1065. var axis = scrollMap[type].axis;
  1066. /** type.charAt(0) = vBar/hBar */
  1067. var barType = type.charAt(0) + 'Bar';
  1068. var hideBar = !vm.bar[barType].state.size || !vm.mergedOptions.scrollPanel['scrolling' + axis] || vm.refreshLoad && type !== 'vertical' || vm.mergedOptions.bar.disable;
  1069. var keepShowRail = vm.mergedOptions.rail.keepShow;
  1070. if (hideBar && !keepShowRail) {
  1071. return null;
  1072. }
  1073. return {
  1074. hideBar: hideBar,
  1075. props: {
  1076. type: type,
  1077. ops: {
  1078. bar: vm.mergedOptions.bar,
  1079. rail: vm.mergedOptions.rail,
  1080. scrollButton: vm.mergedOptions.scrollButton
  1081. },
  1082. state: vm.bar[barType].state,
  1083. hideBar: hideBar
  1084. },
  1085. on: {
  1086. setBarDrag: vm.setBarDrag
  1087. },
  1088. ref: type + 'Bar',
  1089. key: type
  1090. };
  1091. }
  1092. /**
  1093. * create bars
  1094. *
  1095. * @param {any} size
  1096. * @param {any} type
  1097. */
  1098. function createBar(h, vm) {
  1099. var verticalBarProps = getBarData(vm, 'vertical');
  1100. var horizontalBarProps = getBarData(vm, 'horizontal');
  1101. // set class hooks
  1102. vm.setClassHook('hasVBar', !!(verticalBarProps && !verticalBarProps.hideBar));
  1103. vm.setClassHook('hasHBar', !!(horizontalBarProps && !horizontalBarProps.hideBar));
  1104. return [verticalBarProps ? h('bar', _extends({}, verticalBarProps, {
  1105. props: _extends({ otherBarHide: !horizontalBarProps }, verticalBarProps.props)
  1106. })) : null, horizontalBarProps ? h('bar', _extends({}, horizontalBarProps, {
  1107. props: _extends({ otherBarHide: !verticalBarProps }, horizontalBarProps.props)
  1108. })) : null];
  1109. }
  1110. /**
  1111. * This is like a HOC, It extracts the common parts of the
  1112. * native-mode, slide-mode and mix-mode.
  1113. * Each mode must implement the following methods:
  1114. * 1. refreshInternalStatus : use to refresh the component
  1115. * 2. destroy : Destroy some registryed events before component destroy.
  1116. * 3. updateBarStateAndEmitEvent: use to update bar states and emit events.
  1117. */
  1118. var createComponent = function createComponent(_ref) {
  1119. var _render = _ref.render,
  1120. components = _ref.components,
  1121. mixins = _ref.mixins;
  1122. return {
  1123. name: 'vueScroll',
  1124. props: {
  1125. ops: { type: Object }
  1126. },
  1127. components: components,
  1128. mixins: [api].concat(toConsumableArray([].concat(mixins))),
  1129. created: function created() {
  1130. var _this = this;
  1131. /**
  1132. * Begin to merge options
  1133. */
  1134. var _gfc = mergeObject(this.$vuescrollConfig || {}, {});
  1135. var ops = mergeObject(baseConfig, _gfc);
  1136. this.$options.propsData.ops = this.$options.propsData.ops || {};
  1137. Object.keys(this.$options.propsData.ops).forEach(function (key) {
  1138. {
  1139. defineReactive(_this.mergedOptions, key, _this.$options.propsData.ops);
  1140. }
  1141. });
  1142. // from ops to mergedOptions
  1143. mergeObject(ops, this.mergedOptions);
  1144. this._isVuescrollRoot = true;
  1145. this.renderError = validateOps(this.mergedOptions);
  1146. },
  1147. render: function render(h) {
  1148. var vm = this;
  1149. if (vm.renderError) {
  1150. return h('div', [[vm.$slots['default']]]);
  1151. }
  1152. if (!vm.touchManager) vm.touchManager = new touchManager();
  1153. // vuescroll data
  1154. var data = {
  1155. style: {
  1156. height: vm.vuescroll.state.height,
  1157. width: vm.vuescroll.state.width,
  1158. padding: 0,
  1159. position: 'relative',
  1160. overflow: 'hidden'
  1161. },
  1162. class: _extends({ __vuescroll: true }, vm.classHooks)
  1163. };
  1164. var touchObj = vm.touchManager.getTouchObject();
  1165. if (touchObj) {
  1166. var _data$on;
  1167. data.on = (_data$on = {}, defineProperty(_data$on, touchObj.touchenter, function () {
  1168. vm.vuescroll.state.pointerLeave = false;
  1169. vm.updateBarStateAndEmitEvent();
  1170. vm.setClassHook('mouseEnter', true);
  1171. }), defineProperty(_data$on, touchObj.touchleave, function () {
  1172. vm.vuescroll.state.pointerLeave = true;
  1173. vm.hideBar();
  1174. vm.setClassHook('mouseEnter', false);
  1175. }), defineProperty(_data$on, touchObj.touchmove, function () /* istanbul ignore next */{
  1176. vm.vuescroll.state.pointerLeave = false;
  1177. vm.updateBarStateAndEmitEvent();
  1178. }), _data$on);
  1179. }
  1180. var ch = [_render(h, vm)].concat(toConsumableArray(createBar(h, vm)));
  1181. var _customContainer = this.$slots['scroll-container'];
  1182. if (_customContainer) {
  1183. return insertChildrenIntoSlot(h, _customContainer, ch, data);
  1184. }
  1185. return h(
  1186. 'div',
  1187. data,
  1188. [ch]
  1189. );
  1190. },
  1191. mounted: function mounted() {
  1192. var _this2 = this;
  1193. if (!this.renderError) {
  1194. this.initVariables();
  1195. this.initWatchOpsChange();
  1196. // Call external merged Api
  1197. this.refreshInternalStatus();
  1198. this.updatedCbs.push(function () {
  1199. _this2.scrollToAnchor();
  1200. // need to reflow to deal with the
  1201. // latest thing.
  1202. _this2.updateBarStateAndEmitEvent();
  1203. });
  1204. }
  1205. },
  1206. updated: function updated() {
  1207. var _this3 = this;
  1208. this.updatedCbs.forEach(function (cb) {
  1209. cb.call(_this3);
  1210. });
  1211. // Clear
  1212. this.updatedCbs = [];
  1213. },
  1214. beforeDestroy: function beforeDestroy() {
  1215. if (this.destroy) {
  1216. this.destroy();
  1217. }
  1218. },
  1219. /** ------------------------------- Computed ----------------------------- */
  1220. computed: {
  1221. scrollPanelElm: function scrollPanelElm() {
  1222. return this.$refs['scrollPanel']._isVue ? this.$refs['scrollPanel'].$el : this.$refs['scrollPanel'];
  1223. }
  1224. },
  1225. data: function data() {
  1226. return {
  1227. vuescroll: {
  1228. state: {
  1229. isDragging: false,
  1230. pointerLeave: true,
  1231. isRailHover: false,
  1232. /** Default sizeStrategies */
  1233. height: '100%',
  1234. width: '100%',
  1235. // current size strategy
  1236. currentSizeStrategy: 'percent',
  1237. currentScrollState: null,
  1238. currentScrollInfo: null
  1239. }
  1240. },
  1241. bar: {
  1242. vBar: {
  1243. state: {
  1244. posValue: 0,
  1245. size: 0,
  1246. opacity: 0
  1247. }
  1248. },
  1249. hBar: {
  1250. state: {
  1251. posValue: 0,
  1252. size: 0,
  1253. opacity: 0
  1254. }
  1255. }
  1256. },
  1257. mergedOptions: {
  1258. vuescroll: {},
  1259. scrollPanel: {},
  1260. scrollContent: {},
  1261. rail: {},
  1262. bar: {}
  1263. },
  1264. updatedCbs: [],
  1265. renderError: false,
  1266. classHooks: {
  1267. hasVBar: false,
  1268. hasHBar: false,
  1269. vBarVisible: false,
  1270. hBarVisible: false,
  1271. vBarDragging: false,
  1272. hBarDragging: false,
  1273. clikingVerticalStartButton: false,
  1274. clikingVerticalEndButton: false,
  1275. clikingHorizontalStartButton: false,
  1276. clikingHorizontalEndButton: false,
  1277. mouseEnter: false
  1278. }
  1279. };
  1280. },
  1281. /** ------------------------------- Methods -------------------------------- */
  1282. methods: {
  1283. /** ------------------------ Handlers --------------------------- */
  1284. scrollingComplete: function scrollingComplete() {
  1285. this.updateBarStateAndEmitEvent('handle-scroll-complete');
  1286. },
  1287. setBarDrag: function setBarDrag(val) {
  1288. /* istanbul ignore next */
  1289. this.vuescroll.state.isDragging = val;
  1290. },
  1291. setClassHook: function setClassHook(name, value) {
  1292. this.classHooks[name] = value;
  1293. },
  1294. /** ------------------------ Some Helpers --------------------------- */
  1295. /*
  1296. * To have a good ux, instead of hiding bar immediately, we hide bar
  1297. * after some seconds by using this simple debounce-hidebar method.
  1298. */
  1299. showAndDefferedHideBar: function showAndDefferedHideBar(forceHideBar) {
  1300. var _this4 = this;
  1301. this.showBar();
  1302. if (this.timeoutId) {
  1303. clearTimeout(this.timeoutId);
  1304. this.timeoutId = 0;
  1305. }
  1306. this.timeoutId = setTimeout(function () {
  1307. _this4.timeoutId = 0;
  1308. _this4.hideBar(forceHideBar);
  1309. }, this.mergedOptions.bar.showDelay);
  1310. },
  1311. showBar: function showBar() {
  1312. var opacity = this.mergedOptions.bar.opacity;
  1313. this.bar.vBar.state.opacity = opacity;
  1314. this.bar.hBar.state.opacity = opacity;
  1315. },
  1316. hideBar: function hideBar(forceHideBar) {
  1317. var _vuescroll$state = this.vuescroll.state,
  1318. isDragging = _vuescroll$state.isDragging,
  1319. isRailHover = _vuescroll$state.isRailHover;
  1320. /* istanbul ignore next */
  1321. if (isDragging || isRailHover) {
  1322. return;
  1323. }
  1324. if (forceHideBar && !this.mergedOptions.bar.keepShow) {
  1325. this.bar.hBar.state.opacity = 0;
  1326. this.bar.vBar.state.opacity = 0;
  1327. }
  1328. // add isDragging condition
  1329. // to prevent from hiding bar while dragging the bar
  1330. if (!this.mergedOptions.bar.keepShow && !this.vuescroll.state.isDragging) {
  1331. this.bar.vBar.state.opacity = 0;
  1332. this.bar.hBar.state.opacity = 0;
  1333. }
  1334. },
  1335. useNumbericSize: function useNumbericSize() {
  1336. this.vuescroll.state.currentSizeStrategy = 'number';
  1337. var _mergedOptions$scroll = this.mergedOptions.scrollPanel,
  1338. maxHeight = _mergedOptions$scroll.maxHeight,
  1339. maxWidth = _mergedOptions$scroll.maxWidth;
  1340. var _$el$parentNode = this.$el.parentNode,
  1341. parentClientHeight = _$el$parentNode.clientHeight,
  1342. parentClientWidth = _$el$parentNode.clientWidth;
  1343. var _scrollPanelElm = this.scrollPanelElm,
  1344. scrollHeight = _scrollPanelElm.scrollHeight,
  1345. scrollWidth = _scrollPanelElm.scrollWidth;
  1346. var width = void 0;
  1347. var height = void 0;
  1348. if (maxHeight || maxWidth) {
  1349. height = scrollHeight <= maxHeight ? undefined : maxHeight;
  1350. width = scrollWidth <= maxWidth ? undefined : maxWidth;
  1351. } else {
  1352. height = parentClientHeight;
  1353. width = parentClientWidth;
  1354. }
  1355. this.vuescroll.state.height = height ? height + 'px' : undefined;
  1356. this.vuescroll.state.width = width ? width + 'px' : undefined;
  1357. },
  1358. usePercentSize: function usePercentSize() {
  1359. this.vuescroll.state.currentSizeStrategy = 'percent';
  1360. this.vuescroll.state.height = '100%';
  1361. this.vuescroll.state.width = '100%';
  1362. },
  1363. // Set its size to be equal to its parentNode
  1364. setVsSize: function setVsSize() {
  1365. var sizeStrategy = this.mergedOptions.vuescroll.sizeStrategy;
  1366. var _mergedOptions$scroll2 = this.mergedOptions.scrollPanel,
  1367. maxHeight = _mergedOptions$scroll2.maxHeight,
  1368. maxWidth = _mergedOptions$scroll2.maxWidth;
  1369. var _scrollPanelElm2 = this.scrollPanelElm,
  1370. clientHeight = _scrollPanelElm2.clientHeight,
  1371. clientWidth = _scrollPanelElm2.clientWidth;
  1372. if (sizeStrategy == 'number' || maxHeight && clientHeight > maxHeight || maxWidth && clientWidth > maxWidth) {
  1373. this.useNumbericSize();
  1374. } else if (sizeStrategy == 'percent' && clientHeight != maxHeight && clientWidth != maxWidth) {
  1375. this.usePercentSize();
  1376. }
  1377. },
  1378. /** ------------------------ Init --------------------------- */
  1379. initWatchOpsChange: function initWatchOpsChange() {
  1380. var _this5 = this;
  1381. var watchOpts = {
  1382. deep: true,
  1383. sync: true
  1384. };
  1385. this.$watch('mergedOptions', function () {
  1386. setTimeout(function () {
  1387. if (_this5.isSmallChangeThisTick) {
  1388. _this5.isSmallChangeThisTick = false;
  1389. _this5.updateBarStateAndEmitEvent('options-change');
  1390. return;
  1391. }
  1392. _this5.refreshInternalStatus();
  1393. }, 0);
  1394. }, watchOpts);
  1395. /**
  1396. * We also watch `small` changes, and when small changes happen, we send
  1397. * a signal to vuescroll, to tell it:
  1398. * 1. we don't need to registry resize
  1399. * 2. we don't need to registry scroller.
  1400. */
  1401. smallChangeArray.forEach(function (opts) {
  1402. _this5.$watch(opts, function () {
  1403. _this5.isSmallChangeThisTick = true;
  1404. }, watchOpts);
  1405. });
  1406. },
  1407. // scrollTo hash-anchor while mounted component have mounted.
  1408. scrollToAnchor: function scrollToAnchor() /* istanbul ignore next */{
  1409. var validateHashSelector = function validateHashSelector(hash) {
  1410. return (/^#[a-zA-Z_]\d*$/.test(hash)
  1411. );
  1412. };
  1413. var hash = window.location.hash;
  1414. if (!hash || (hash = hash.slice(hash.lastIndexOf('#'))) && !validateHashSelector(hash)) {
  1415. return;
  1416. }
  1417. var elm = document.querySelector(hash);
  1418. if (!isChildInParent(elm, this.$el) || this.mergedOptions.scrollPanel.initialScrollY || this.mergedOptions.scrollPanel.initialScrollX) {
  1419. return;
  1420. }
  1421. this.scrollIntoView(elm);
  1422. }
  1423. /** ------------------------ Registry Resize --------------------------- */
  1424. }
  1425. };
  1426. };
  1427. // begin importing
  1428. var scrollPanel = {
  1429. name: 'scrollPanel',
  1430. props: { ops: { type: Object, required: true } },
  1431. methods: {
  1432. // trigger scrollPanel options initialScrollX,
  1433. // initialScrollY
  1434. updateInitialScroll: function updateInitialScroll() {
  1435. var x = 0;
  1436. var y = 0;
  1437. var parent = getRealParent(this);
  1438. if (this.ops.initialScrollX) {
  1439. x = this.ops.initialScrollX;
  1440. }
  1441. if (this.ops.initialScrollY) {
  1442. y = this.ops.initialScrollY;
  1443. }
  1444. if (x || y) {
  1445. parent.scrollTo({ x: x, y: y });
  1446. }
  1447. }
  1448. },
  1449. mounted: function mounted() {
  1450. var _this = this;
  1451. setTimeout(function () {
  1452. if (!_this._isDestroyed) {
  1453. _this.updateInitialScroll();
  1454. }
  1455. }, 0);
  1456. },
  1457. render: function render(h) {
  1458. // eslint-disable-line
  1459. var data = {
  1460. class: ['__panel'],
  1461. style: {
  1462. position: 'relative',
  1463. boxSizing: 'border-box'
  1464. }
  1465. };
  1466. var parent = getRealParent(this);
  1467. var _customPanel = parent.$slots['scroll-panel'];
  1468. if (_customPanel) {
  1469. return insertChildrenIntoSlot(h, _customPanel, this.$slots.default, data);
  1470. }
  1471. return h(
  1472. 'div',
  1473. data,
  1474. [[this.$slots.default]]
  1475. );
  1476. }
  1477. };
  1478. /**
  1479. * Init following things
  1480. * 1. Component
  1481. * 2. Render
  1482. * 3. Config
  1483. */
  1484. function _install(core, render) {
  1485. var _components;
  1486. var extraConfigs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
  1487. var extraValidators = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
  1488. var components = (_components = {}, defineProperty(_components, scrollPanel.name, scrollPanel), defineProperty(_components, bar.name, bar), _components);
  1489. var opts = {};
  1490. opts.components = components;
  1491. opts.render = render;
  1492. opts.mixins = core;
  1493. var comp = createComponent(opts);
  1494. // Init Config
  1495. extendOpts(extraConfigs, extraValidators);
  1496. return comp;
  1497. }
  1498. /**
  1499. * Get the children of parent those are in viewport
  1500. */
  1501. function getCurrentViewportDom(parent, container) {
  1502. var children = parent.children;
  1503. var domFragment = [];
  1504. var isCurrentview = function isCurrentview(dom) {
  1505. var _dom$getBoundingClien = dom.getBoundingClientRect(),
  1506. left = _dom$getBoundingClien.left,
  1507. top = _dom$getBoundingClien.top,
  1508. width = _dom$getBoundingClien.width,
  1509. height = _dom$getBoundingClien.height;
  1510. var _container$getBoundin = container.getBoundingClientRect(),
  1511. parentLeft = _container$getBoundin.left,
  1512. parentTop = _container$getBoundin.top,
  1513. parentHeight = _container$getBoundin.height,
  1514. parentWidth = _container$getBoundin.width;
  1515. if (left - parentLeft + width > 0 && left - parentLeft < parentWidth && top - parentTop + height > 0 && top - parentTop < parentHeight) {
  1516. return true;
  1517. }
  1518. return false;
  1519. };
  1520. for (var i = 0; i < children.length; i++) {
  1521. var dom = children.item(i);
  1522. if (isCurrentview(dom) && !dom.isResizeElm) {
  1523. domFragment.push(dom);
  1524. }
  1525. }
  1526. return domFragment;
  1527. }
  1528. /**
  1529. * Compatible to scroller's animation function
  1530. */
  1531. function createEasingFunction(easing, easingPattern) {
  1532. return function (time) {
  1533. return easingPattern(easing, time);
  1534. };
  1535. }
  1536. /**
  1537. * Calculate the easing pattern
  1538. * @link https://github.com/cferdinandi/smooth-scroll/blob/master/src/js/smooth-scroll.js
  1539. * modified by wangyi7099
  1540. * @param {String} type Easing pattern
  1541. * @param {Number} time Time animation should take to complete
  1542. * @returns {Number}
  1543. */
  1544. function easingPattern(easing, time) {
  1545. var pattern = null;
  1546. /* istanbul ignore next */
  1547. {
  1548. // Default Easing Patterns
  1549. if (easing === 'easeInQuad') pattern = time * time; // accelerating from zero velocity
  1550. if (easing === 'easeOutQuad') pattern = time * (2 - time); // decelerating to zero velocity
  1551. if (easing === 'easeInOutQuad') pattern = time < 0.5 ? 2 * time * time : -1 + (4 - 2 * time) * time; // acceleration until halfway, then deceleration
  1552. if (easing === 'easeInCubic') pattern = time * time * time; // accelerating from zero velocity
  1553. if (easing === 'easeOutCubic') pattern = --time * time * time + 1; // decelerating to zero velocity
  1554. if (easing === 'easeInOutCubic') pattern = time < 0.5 ? 4 * time * time * time : (time - 1) * (2 * time - 2) * (2 * time - 2) + 1; // acceleration until halfway, then deceleration
  1555. if (easing === 'easeInQuart') pattern = time * time * time * time; // accelerating from zero velocity
  1556. if (easing === 'easeOutQuart') pattern = 1 - --time * time * time * time; // decelerating to zero velocity
  1557. if (easing === 'easeInOutQuart') pattern = time < 0.5 ? 8 * time * time * time * time : 1 - 8 * --time * time * time * time; // acceleration until halfway, then deceleration
  1558. if (easing === 'easeInQuint') pattern = time * time * time * time * time; // accelerating from zero velocity
  1559. if (easing === 'easeOutQuint') pattern = 1 + --time * time * time * time * time; // decelerating to zero velocity
  1560. if (easing === 'easeInOutQuint') pattern = time < 0.5 ? 16 * time * time * time * time * time : 1 + 16 * --time * time * time * time * time; // acceleration until halfway, then deceleration
  1561. }
  1562. return pattern || time; // no easing, no acceleration
  1563. }
  1564. function noop() {
  1565. return true;
  1566. }
  1567. /* istanbul ignore next */
  1568. var now = Date.now || function () {
  1569. return new Date().getTime();
  1570. };
  1571. var ScrollControl = function () {
  1572. function ScrollControl() {
  1573. classCallCheck(this, ScrollControl);
  1574. this.init();
  1575. this.isRunning = false;
  1576. }
  1577. createClass(ScrollControl, [{
  1578. key: 'pause',
  1579. value: function pause() {
  1580. /* istanbul ignore if */
  1581. if (!this.isRunning) return;
  1582. this.isPaused = true;
  1583. }
  1584. }, {
  1585. key: 'stop',
  1586. value: function stop() {
  1587. this.isStopped = true;
  1588. }
  1589. }, {
  1590. key: 'continue',
  1591. value: function _continue() {
  1592. /* istanbul ignore if */
  1593. if (!this.isPaused) return;
  1594. this.isPaused = false;
  1595. this.ts = now() - this.percent * this.spd;
  1596. this.execScroll();
  1597. }
  1598. }, {
  1599. key: 'startScroll',
  1600. value: function startScroll(st, ed, spd) {
  1601. var stepCb = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : noop;
  1602. var completeCb = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : noop;
  1603. var vertifyCb = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : noop;
  1604. var easingMethod = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : noop;
  1605. var df = ed - st;
  1606. var dir = df > 0 ? -1 : 1;
  1607. var nt = now();
  1608. if (!this.isRunning) {
  1609. this.init();
  1610. }
  1611. if (dir != this.dir || nt - this.ts > 200) {
  1612. this.ts = nt;
  1613. this.dir = dir;
  1614. this.st = st;
  1615. this.ed = ed;
  1616. this.df = df;
  1617. } /* istanbul ignore next */else {
  1618. this.df += df;
  1619. }
  1620. this.spd = spd;
  1621. this.completeCb = completeCb;
  1622. this.vertifyCb = vertifyCb;
  1623. this.stepCb = stepCb;
  1624. this.easingMethod = easingMethod;
  1625. if (!this.isRunning) this.execScroll();
  1626. }
  1627. }, {
  1628. key: 'execScroll',
  1629. value: function execScroll() {
  1630. var _this = this;
  1631. if (!this.df) return;
  1632. var percent = this.percent || 0;
  1633. this.percent = 0;
  1634. this.isRunning = true;
  1635. var loop = function loop() {
  1636. /* istanbul ignore if */
  1637. if (!_this.isRunning || !_this.vertifyCb(percent) || _this.isStopped) {
  1638. _this.isRunning = false;
  1639. return;
  1640. }
  1641. percent = (now() - _this.ts) / _this.spd;
  1642. if (_this.isPaused) {
  1643. _this.percent = percent;
  1644. _this.isRunning = false;
  1645. return;
  1646. }
  1647. if (percent < 1) {
  1648. var value = _this.st + _this.df * _this.easingMethod(percent);
  1649. _this.stepCb(value);
  1650. _this.ref(loop);
  1651. } else {
  1652. // trigger complete
  1653. _this.stepCb(_this.st + _this.df);
  1654. _this.completeCb();
  1655. _this.isRunning = false;
  1656. }
  1657. };
  1658. this.ref(loop);
  1659. }
  1660. }, {
  1661. key: 'init',
  1662. value: function init() {
  1663. this.st = 0;
  1664. this.ed = 0;
  1665. this.df = 0;
  1666. this.spd = 0;
  1667. this.ts = 0;
  1668. this.dir = 0;
  1669. this.ref = requestAnimationFrame(window);
  1670. this.isPaused = false;
  1671. this.isStopped = false;
  1672. }
  1673. }]);
  1674. return ScrollControl;
  1675. }();
  1676. function scrollTo(elm, x, y) {
  1677. var speed = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 300;
  1678. var easing = arguments[4];
  1679. var scrollingComplete = arguments[5];
  1680. var scrollLeft = void 0,
  1681. scrollTop = void 0,
  1682. scrollHeight = void 0,
  1683. scrollWidth = void 0,
  1684. clientWidth = void 0,
  1685. clientHeight = void 0;
  1686. var _elm = elm,
  1687. nodeType = _elm.nodeType;
  1688. var scrollX = new ScrollControl();
  1689. var scrollY = new ScrollControl();
  1690. if (!nodeType) {
  1691. warn('You must pass a dom for the first param, ' + 'for window scrolling, ' + 'you can pass document as the first param.');
  1692. return;
  1693. }
  1694. if (nodeType == 9) {
  1695. // document
  1696. elm = elm.scrollingElement;
  1697. }
  1698. var _elm2 = elm;
  1699. scrollLeft = _elm2.scrollLeft;
  1700. scrollTop = _elm2.scrollTop;
  1701. scrollHeight = _elm2.scrollHeight;
  1702. scrollWidth = _elm2.scrollWidth;
  1703. clientWidth = _elm2.clientWidth;
  1704. clientHeight = _elm2.clientHeight;
  1705. if (typeof x === 'undefined') {
  1706. x = scrollLeft;
  1707. } else {
  1708. x = getNumericValue(x, scrollWidth - clientWidth);
  1709. }
  1710. if (typeof y === 'undefined') {
  1711. y = scrollTop;
  1712. } else {
  1713. y = getNumericValue(y, scrollHeight - clientHeight);
  1714. }
  1715. var easingMethod = createEasingFunction(easing, easingPattern);
  1716. scrollX.startScroll(scrollLeft, x, speed, function (dx) {
  1717. elm.scrollLeft = dx;
  1718. }, scrollingComplete, undefined, easingMethod);
  1719. scrollY.startScroll(scrollTop, y, speed, function (dy) {
  1720. elm.scrollTop = dy;
  1721. }, scrollingComplete, undefined, easingMethod);
  1722. }
  1723. var api$1 = {
  1724. mounted: function mounted() {
  1725. // registry scroll
  1726. this.scrollX = new ScrollControl();
  1727. this.scrollY = new ScrollControl();
  1728. },
  1729. methods: {
  1730. nativeStop: function nativeStop() {
  1731. this.scrollX.stop();
  1732. this.scrollY.stop();
  1733. },
  1734. nativePause: function nativePause() {
  1735. this.scrollX.pause();
  1736. this.scrollY.pause();
  1737. },
  1738. nativeContinue: function nativeContinue() {
  1739. this.scrollX.continue();
  1740. this.scrollY.continue();
  1741. },
  1742. nativeScrollTo: function nativeScrollTo(x, y, speed, easing) {
  1743. if (speed === false) ; else if (typeof speed === 'undefined') {
  1744. speed = this.mergedOptions.scrollPanel.speed;
  1745. }
  1746. var elm = this.scrollPanelElm;
  1747. var scrollTop = elm.scrollTop,
  1748. scrollLeft = elm.scrollLeft,
  1749. scrollWidth = elm.scrollWidth,
  1750. clientWidth = elm.clientWidth,
  1751. scrollHeight = elm.scrollHeight,
  1752. clientHeight = elm.clientHeight;
  1753. if (typeof x === 'undefined') {
  1754. x = scrollLeft;
  1755. } else {
  1756. x = getNumericValue(x, scrollWidth - clientWidth);
  1757. }
  1758. if (typeof y === 'undefined') {
  1759. y = scrollTop;
  1760. } else {
  1761. y = getNumericValue(y, scrollHeight - clientHeight);
  1762. }
  1763. if (speed) {
  1764. easing = easing || this.mergedOptions.scrollPanel.easing;
  1765. var easingMethod = createEasingFunction(easing, easingPattern);
  1766. if (x != scrollLeft) {
  1767. this.scrollX.startScroll(scrollLeft, x, speed, function (x) {
  1768. elm.scrollLeft = x;
  1769. }, this.scrollingComplete.bind(this), undefined, easingMethod);
  1770. }
  1771. if (y != scrollTop) {
  1772. this.scrollY.startScroll(scrollTop, y, speed, function (y) {
  1773. elm.scrollTop = y;
  1774. }, this.scrollingComplete.bind(this), undefined, easingMethod);
  1775. }
  1776. } else {
  1777. elm.scrollTop = y;
  1778. elm.scrollLeft = x;
  1779. }
  1780. },
  1781. getCurrentviewDomNative: function getCurrentviewDomNative() {
  1782. var parent = this.scrollContentElm;
  1783. var domFragment = getCurrentViewportDom(parent, this.$el);
  1784. return domFragment;
  1785. }
  1786. }
  1787. };
  1788. function getPanelData(context) {
  1789. // scrollPanel data start
  1790. var data = {
  1791. ref: 'scrollPanel',
  1792. style: {
  1793. height: '100%',
  1794. overflowY: 'scroll',
  1795. overflowX: 'scroll'
  1796. },
  1797. class: [],
  1798. nativeOn: {
  1799. '&scroll': context.handleScroll
  1800. },
  1801. props: {
  1802. ops: context.mergedOptions.scrollPanel
  1803. }
  1804. };
  1805. context.scrollYEnable = true;
  1806. context.scrollXEnable = true;
  1807. data.nativeOn.DOMMouseScroll = data.nativeOn.mousewheel = context.onMouseWheel;
  1808. var _context$mergedOption = context.mergedOptions.scrollPanel,
  1809. scrollingY = _context$mergedOption.scrollingY,
  1810. scrollingX = _context$mergedOption.scrollingX;
  1811. if (!context.bar.hBar.state.size || !scrollingX) {
  1812. context.scrollXEnable = false;
  1813. data.style.overflowX = 'hidden';
  1814. }
  1815. if (!context.bar.vBar.state.size || !scrollingY) {
  1816. context.scrollYEnable = false;
  1817. data.style.overflowY = 'hidden';
  1818. }
  1819. var gutter = getGutter();
  1820. /* istanbul ignore if */
  1821. if (!gutter) {
  1822. createHideBarStyle();
  1823. data.class.push('__hidebar');
  1824. if (isIos()) {
  1825. data.style['-webkit-overflow-scrolling'] = 'touch';
  1826. }
  1827. } else {
  1828. // hide system bar by use a negative value px
  1829. // gutter should be 0 when manually disable scrollingX #14
  1830. if (context.bar.vBar.state.size && context.mergedOptions.scrollPanel.scrollingY) {
  1831. if (context.mergedOptions.scrollPanel.verticalNativeBarPos == 'right') {
  1832. data.style.marginRight = '-' + gutter + 'px';
  1833. } /* istanbul ignore next */else {
  1834. data.style.marginLeft = '-' + gutter + 'px';
  1835. }
  1836. }
  1837. if (context.bar.hBar.state.size && context.mergedOptions.scrollPanel.scrollingX) {
  1838. data.style.height = 'calc(100% + ' + gutter + 'px)';
  1839. }
  1840. }
  1841. // clear legency styles of slide mode...
  1842. data.style.transformOrigin = '';
  1843. data.style.transform = '';
  1844. return data;
  1845. }
  1846. /**
  1847. * create a scrollPanel
  1848. *
  1849. * @param {any} size
  1850. * @param {any} context
  1851. * @returns
  1852. */
  1853. function createPanel(h, context) {
  1854. var data = {};
  1855. data = getPanelData(context);
  1856. return h(
  1857. 'scrollPanel',
  1858. data,
  1859. [getPanelChildren(h, context)]
  1860. );
  1861. }
  1862. function getPanelChildren(h, context) {
  1863. var viewStyle = {
  1864. position: 'relative',
  1865. 'box-sizing': 'border-box',
  1866. 'min-width': '100%',
  1867. 'min-height': '100%'
  1868. };
  1869. var data = {
  1870. style: viewStyle,
  1871. ref: 'scrollContent',
  1872. class: '__view'
  1873. };
  1874. var _customContent = context.$slots['scroll-content'];
  1875. if (context.mergedOptions.scrollPanel.scrollingX) {
  1876. viewStyle.width = getComplitableStyle('width', 'fit-content');
  1877. } else {
  1878. data.style['width'] = '100%';
  1879. }
  1880. if (context.mergedOptions.scrollPanel.padding) {
  1881. data.style.paddingRight = context.mergedOptions.rail.size;
  1882. }
  1883. if (_customContent) {
  1884. return insertChildrenIntoSlot(h, _customContent, context.$slots.default, data);
  1885. }
  1886. return h(
  1887. 'div',
  1888. data,
  1889. [context.$slots.default]
  1890. );
  1891. }
  1892. // detect content size change
  1893. function installResizeDetection(element, callback) {
  1894. return injectObject(element, callback);
  1895. }
  1896. function injectObject(element, callback) {
  1897. if (element.hasResized) {
  1898. return;
  1899. }
  1900. var OBJECT_STYLE = 'display: block; position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: none; padding: 0; margin: 0; opacity: 0; z-index: -1000; pointer-events: none;';
  1901. // define a wrap due to ie's zIndex bug
  1902. var objWrap = document.createElement('div');
  1903. objWrap.style.cssText = OBJECT_STYLE;
  1904. var object = document.createElement('object');
  1905. object.style.cssText = OBJECT_STYLE;
  1906. object.type = 'text/html';
  1907. object.tabIndex = -1;
  1908. object.onload = function () {
  1909. eventCenter(object.contentDocument.defaultView, 'resize', callback);
  1910. };
  1911. // https://github.com/wnr/element-resize-detector/blob/aafe9f7ea11d1eebdab722c7c5b86634e734b9b8/src/detection-strategy/object.js#L159
  1912. if (!isIE()) {
  1913. object.data = 'about:blank';
  1914. }
  1915. objWrap.isResizeElm = true;
  1916. objWrap.appendChild(object);
  1917. element.appendChild(objWrap);
  1918. if (isIE()) {
  1919. object.data = 'about:blank';
  1920. }
  1921. return function destroy() {
  1922. if (object.contentDocument) {
  1923. eventCenter(object.contentDocument.defaultView, 'resize', callback, 'off');
  1924. }
  1925. element.removeChild(objWrap);
  1926. element.hasResized = false;
  1927. };
  1928. }
  1929. /**
  1930. * These mixes is exclusive for native mode
  1931. */
  1932. var update = {
  1933. methods: {
  1934. updateNativeModeBarState: function updateNativeModeBarState() {
  1935. var container = this.scrollPanelElm;
  1936. var isPercent = this.vuescroll.state.currentSizeStrategy == 'percent';
  1937. var _vuescroll$state = this.vuescroll.state,
  1938. width = _vuescroll$state.width,
  1939. height = _vuescroll$state.height;
  1940. var clientWidth = isPercent || !width ? container.clientWidth : width.slice(0, -2); // xxxpx ==> xxx
  1941. var clientHeight = isPercent || !height ? container.clientHeight : height.slice(0, -2);
  1942. var heightPercentage = clientHeight / container.scrollHeight;
  1943. var widthPercentage = clientWidth / container.scrollWidth;
  1944. this.bar.vBar.state.posValue = container.scrollTop * 100 / clientHeight;
  1945. this.bar.hBar.state.posValue = container.scrollLeft * 100 / clientWidth;
  1946. this.bar.vBar.state.size = heightPercentage < 1 ? heightPercentage : 0;
  1947. this.bar.hBar.state.size = widthPercentage < 1 ? widthPercentage : 0;
  1948. },
  1949. getNativePosition: function getNativePosition() {
  1950. return {
  1951. scrollTop: this.scrollPanelElm.scrollTop,
  1952. scrollLeft: this.scrollPanelElm.scrollLeft
  1953. };
  1954. },
  1955. css: function css(dom, style) /* istanbul ignore next */{
  1956. return window.getComputedStyle(dom)[style];
  1957. },
  1958. checkScrollable: function checkScrollable(e, deltaX, deltaY) /* istanbul ignore next */{
  1959. var scrollable = false;
  1960. // check mouse point scrollable.
  1961. var dom = e.target ? e.target : e;
  1962. while (dom && dom.nodeType == 1 && dom !== this.scrollPanelElm.parentNode && !/^BODY|HTML/.test(dom.nodeName)) {
  1963. var ov = this.css(dom, 'overflow') || '';
  1964. if (/scroll|auto/.test(ov)) {
  1965. var _getScrollProcess = this.getScrollProcess(dom),
  1966. v = _getScrollProcess.v,
  1967. h = _getScrollProcess.h;
  1968. var isScrollX = this.css(dom, 'overflowX') !== 'hidden';
  1969. var isScrollY = this.css(dom, 'overflowY') !== 'hidden';
  1970. if (isScrollX && (deltaX < 0 && h > 0 || deltaX > 0 && h < 1) || isScrollY && (deltaY < 0 && v > 0 || deltaY > 0 && v < 1)) {
  1971. scrollable = dom == this.scrollPanelElm;
  1972. break;
  1973. }
  1974. }
  1975. dom = dom.parentNode ? dom.parentNode : false;
  1976. }
  1977. return scrollable;
  1978. },
  1979. onMouseWheel: function onMouseWheel(event) /* istanbul ignore next */{
  1980. var _mergedOptions$vuescr = this.mergedOptions.vuescroll,
  1981. isReverse = _mergedOptions$vuescr.wheelDirectionReverse,
  1982. duration = _mergedOptions$vuescr.wheelScrollDuration,
  1983. checkShiftKey = _mergedOptions$vuescr.checkShiftKey,
  1984. locking = _mergedOptions$vuescr.locking,
  1985. deltaPercent = _mergedOptions$vuescr.deltaPercent;
  1986. var deltaX = void 0;
  1987. var deltaY = void 0;
  1988. if (event.wheelDelta) {
  1989. if (event.deltaY || event.deltaX) {
  1990. deltaX = event.deltaX * deltaPercent;
  1991. deltaY = event.deltaY * deltaPercent;
  1992. if (locking) {
  1993. if (Math.abs(event.deltaX) > Math.abs(event.deltaY)) {
  1994. deltaY = 0;
  1995. } else {
  1996. deltaX = 0;
  1997. }
  1998. }
  1999. } else {
  2000. deltaX = 0;
  2001. deltaY = -1 * event.wheelDelta / 2;
  2002. }
  2003. } else if (event.detail) {
  2004. deltaY = deltaX = event.detail * 16;
  2005. // horizontal scroll
  2006. if (event.axis == 1) {
  2007. deltaY = 0;
  2008. } else if (event.axis == 2) {
  2009. // vertical scroll
  2010. deltaX = 0;
  2011. }
  2012. }
  2013. if (checkShiftKey && event.shiftKey) {
  2014. // swap value
  2015. deltaX ^= deltaY;
  2016. deltaY ^= deltaX;
  2017. deltaX ^= deltaY;
  2018. }
  2019. if (isReverse) {
  2020. deltaX ^= deltaY;
  2021. deltaY ^= deltaX;
  2022. deltaX ^= deltaY;
  2023. }
  2024. if (this.checkScrollable(event, deltaX, deltaY)) {
  2025. event.stopPropagation();
  2026. event.preventDefault();
  2027. this.scrollBy({ dx: deltaX, dy: deltaY }, duration);
  2028. }
  2029. }
  2030. },
  2031. computed: {
  2032. scrollContentElm: function scrollContentElm() {
  2033. return this.$refs['scrollContent']._isVue ? this.$refs['scrollContent'].$el : this.$refs['scrollContent'];
  2034. }
  2035. }
  2036. };
  2037. var mixins = [api$1, update];
  2038. var core = {
  2039. mixins: mixins,
  2040. methods: {
  2041. destroy: function destroy() {
  2042. /* istanbul ignore next */
  2043. if (this.destroyResize) {
  2044. this.destroyResize();
  2045. }
  2046. },
  2047. getCurrentviewDom: function getCurrentviewDom() {
  2048. return this.getCurrentviewDomNative();
  2049. },
  2050. internalScrollTo: function internalScrollTo(destX, destY, animate, easing) {
  2051. this.nativeScrollTo(destX, destY, animate, easing);
  2052. },
  2053. internalStop: function internalStop() {
  2054. this.nativeStop();
  2055. },
  2056. internalPause: function internalPause() {
  2057. this.nativePause();
  2058. },
  2059. internalContinue: function internalContinue() {
  2060. this.nativeContinue();
  2061. },
  2062. handleScroll: function handleScroll(nativeEvent) {
  2063. this.updateBarStateAndEmitEvent('handle-scroll', nativeEvent);
  2064. },
  2065. updateBarStateAndEmitEvent: function updateBarStateAndEmitEvent(eventType) {
  2066. var nativeEvent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  2067. this.updateNativeModeBarState();
  2068. if (eventType) {
  2069. this.emitEvent(eventType, nativeEvent);
  2070. }
  2071. if (this.mergedOptions.bar.onlyShowBarOnScroll) {
  2072. if (eventType == 'handle-scroll' || eventType == 'handle-resize' || eventType == 'refresh-status' || eventType == 'window-resize' || eventType == 'options-change') {
  2073. this.showAndDefferedHideBar(true /* forceHideBar: true */);
  2074. }
  2075. } else {
  2076. this.showAndDefferedHideBar();
  2077. }
  2078. },
  2079. getScrollProcess: function getScrollProcess(elm) {
  2080. var _ref = elm || this.scrollPanelElm,
  2081. scrollHeight = _ref.scrollHeight,
  2082. scrollWidth = _ref.scrollWidth,
  2083. clientHeight = _ref.clientHeight,
  2084. clientWidth = _ref.clientWidth,
  2085. scrollTop = _ref.scrollTop,
  2086. scrollLeft = _ref.scrollLeft;
  2087. var v = Math.min(scrollTop / (scrollHeight - clientHeight || 1), 1);
  2088. var h = Math.min(scrollLeft / (scrollWidth - clientWidth || 1), 1);
  2089. return {
  2090. v: v,
  2091. h: h
  2092. };
  2093. },
  2094. emitEvent: function emitEvent(eventType) {
  2095. var nativeEvent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  2096. var _scrollPanelElm = this.scrollPanelElm,
  2097. scrollTop = _scrollPanelElm.scrollTop,
  2098. scrollLeft = _scrollPanelElm.scrollLeft;
  2099. var vertical = {
  2100. type: 'vertical'
  2101. };
  2102. var horizontal = {
  2103. type: 'horizontal'
  2104. };
  2105. var _getScrollProcess = this.getScrollProcess(),
  2106. v = _getScrollProcess.v,
  2107. h = _getScrollProcess.h;
  2108. vertical.process = v;
  2109. horizontal.process = h;
  2110. vertical['barSize'] = this.bar.vBar.state.size;
  2111. horizontal['barSize'] = this.bar.hBar.state.size;
  2112. vertical['scrollTop'] = scrollTop;
  2113. horizontal['scrollLeft'] = scrollLeft;
  2114. this.$emit(eventType, vertical, horizontal, nativeEvent);
  2115. },
  2116. initVariables: function initVariables() {
  2117. this.$el._isVuescroll = true;
  2118. },
  2119. refreshInternalStatus: function refreshInternalStatus() {
  2120. // 1.set vuescroll height or width according to
  2121. // sizeStrategy
  2122. this.setVsSize();
  2123. // 2. registry resize event
  2124. this.registryResize();
  2125. // 3. update scrollbar's height/width
  2126. this.updateBarStateAndEmitEvent('refresh-status');
  2127. },
  2128. registryResize: function registryResize() {
  2129. var _this = this;
  2130. var resizeEnable = this.mergedOptions.vuescroll.detectResize;
  2131. /* istanbul ignore next */
  2132. if (this.destroyResize && resizeEnable) {
  2133. return;
  2134. }
  2135. if (this.destroyResize) {
  2136. this.destroyResize();
  2137. }
  2138. if (!resizeEnable) {
  2139. return;
  2140. }
  2141. var contentElm = this.scrollContentElm;
  2142. var vm = this;
  2143. var handleWindowResize = function handleWindowResize() /* istanbul ignore next */{
  2144. vm.updateBarStateAndEmitEvent('window-resize');
  2145. };
  2146. var handleDomResize = function handleDomResize() {
  2147. var currentSize = {};
  2148. currentSize['width'] = _this.scrollPanelElm.scrollWidth;
  2149. currentSize['height'] = _this.scrollPanelElm.scrollHeight;
  2150. _this.updateBarStateAndEmitEvent('handle-resize', currentSize);
  2151. // Since content sie changes, we should tell parent to set
  2152. // correct size to fit content's size
  2153. _this.setVsSize();
  2154. };
  2155. window.addEventListener('resize', handleWindowResize, false);
  2156. var destroyDomResize = installResizeDetection(contentElm, handleDomResize);
  2157. var destroyWindowResize = function destroyWindowResize() {
  2158. window.removeEventListener('resize', handleWindowResize, false);
  2159. };
  2160. this.destroyResize = function () {
  2161. destroyWindowResize();
  2162. destroyDomResize();
  2163. _this.destroyResize = null;
  2164. };
  2165. },
  2166. getPosition: function getPosition() {
  2167. return this.getNativePosition();
  2168. }
  2169. }
  2170. };
  2171. var config = {
  2172. vuescroll: {
  2173. wheelScrollDuration: 0,
  2174. wheelDirectionReverse: false,
  2175. checkShiftKey: true,
  2176. deltaPercent: 1
  2177. }
  2178. };
  2179. var component = _install(core, createPanel, [config]);
  2180. function install(Vue) {
  2181. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  2182. Vue.component(opts.name || component.name, component);
  2183. Vue.prototype.$vuescrollConfig = opts.ops || {};
  2184. }
  2185. var Vuescroll = _extends({
  2186. install: install,
  2187. version: '4.18.1',
  2188. refreshAll: refreshAll,
  2189. scrollTo: scrollTo
  2190. }, component);
  2191. /* istanbul ignore if */
  2192. if (typeof window !== 'undefined' && window.Vue) {
  2193. window.Vue.use(Vuescroll);
  2194. }
  2195. return Vuescroll;
  2196. })));