scrollbar.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/
  6. /******/ // The require function
  7. /******/ function __webpack_require__(moduleId) {
  8. /******/
  9. /******/ // Check if module is in cache
  10. /******/ if(installedModules[moduleId]) {
  11. /******/ return installedModules[moduleId].exports;
  12. /******/ }
  13. /******/ // Create a new module (and put it into the cache)
  14. /******/ var module = installedModules[moduleId] = {
  15. /******/ i: moduleId,
  16. /******/ l: false,
  17. /******/ exports: {}
  18. /******/ };
  19. /******/
  20. /******/ // Execute the module function
  21. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22. /******/
  23. /******/ // Flag the module as loaded
  24. /******/ module.l = true;
  25. /******/
  26. /******/ // Return the exports of the module
  27. /******/ return module.exports;
  28. /******/ }
  29. /******/
  30. /******/
  31. /******/ // expose the modules object (__webpack_modules__)
  32. /******/ __webpack_require__.m = modules;
  33. /******/
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/
  37. /******/ // define getter function for harmony exports
  38. /******/ __webpack_require__.d = function(exports, name, getter) {
  39. /******/ if(!__webpack_require__.o(exports, name)) {
  40. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  41. /******/ }
  42. /******/ };
  43. /******/
  44. /******/ // define __esModule on exports
  45. /******/ __webpack_require__.r = function(exports) {
  46. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  47. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  48. /******/ }
  49. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  50. /******/ };
  51. /******/
  52. /******/ // create a fake namespace object
  53. /******/ // mode & 1: value is a module id, require it
  54. /******/ // mode & 2: merge all properties of value into the ns
  55. /******/ // mode & 4: return value when already ns object
  56. /******/ // mode & 8|1: behave like require
  57. /******/ __webpack_require__.t = function(value, mode) {
  58. /******/ if(mode & 1) value = __webpack_require__(value);
  59. /******/ if(mode & 8) return value;
  60. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  61. /******/ var ns = Object.create(null);
  62. /******/ __webpack_require__.r(ns);
  63. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  64. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  65. /******/ return ns;
  66. /******/ };
  67. /******/
  68. /******/ // getDefaultExport function for compatibility with non-harmony modules
  69. /******/ __webpack_require__.n = function(module) {
  70. /******/ var getter = module && module.__esModule ?
  71. /******/ function getDefault() { return module['default']; } :
  72. /******/ function getModuleExports() { return module; };
  73. /******/ __webpack_require__.d(getter, 'a', getter);
  74. /******/ return getter;
  75. /******/ };
  76. /******/
  77. /******/ // Object.prototype.hasOwnProperty.call
  78. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  79. /******/
  80. /******/ // __webpack_public_path__
  81. /******/ __webpack_require__.p = "/dist/";
  82. /******/
  83. /******/
  84. /******/ // Load entry module and return exports
  85. /******/ return __webpack_require__(__webpack_require__.s = 131);
  86. /******/ })
  87. /************************************************************************/
  88. /******/ ({
  89. /***/ 131:
  90. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  91. "use strict";
  92. __webpack_require__.r(__webpack_exports__);
  93. // EXTERNAL MODULE: external "element-ui/lib/utils/resize-event"
  94. var resize_event_ = __webpack_require__(16);
  95. // EXTERNAL MODULE: external "element-ui/lib/utils/scrollbar-width"
  96. var scrollbar_width_ = __webpack_require__(38);
  97. var scrollbar_width_default = /*#__PURE__*/__webpack_require__.n(scrollbar_width_);
  98. // EXTERNAL MODULE: external "element-ui/lib/utils/util"
  99. var util_ = __webpack_require__(3);
  100. // EXTERNAL MODULE: external "element-ui/lib/utils/dom"
  101. var dom_ = __webpack_require__(2);
  102. // CONCATENATED MODULE: ./packages/scrollbar/src/util.js
  103. var BAR_MAP = {
  104. vertical: {
  105. offset: 'offsetHeight',
  106. scroll: 'scrollTop',
  107. scrollSize: 'scrollHeight',
  108. size: 'height',
  109. key: 'vertical',
  110. axis: 'Y',
  111. client: 'clientY',
  112. direction: 'top'
  113. },
  114. horizontal: {
  115. offset: 'offsetWidth',
  116. scroll: 'scrollLeft',
  117. scrollSize: 'scrollWidth',
  118. size: 'width',
  119. key: 'horizontal',
  120. axis: 'X',
  121. client: 'clientX',
  122. direction: 'left'
  123. }
  124. };
  125. function renderThumbStyle(_ref) {
  126. var move = _ref.move,
  127. size = _ref.size,
  128. bar = _ref.bar;
  129. var style = {};
  130. var translate = 'translate' + bar.axis + '(' + move + '%)';
  131. style[bar.size] = size;
  132. style.transform = translate;
  133. style.msTransform = translate;
  134. style.webkitTransform = translate;
  135. return style;
  136. };
  137. // CONCATENATED MODULE: ./packages/scrollbar/src/bar.js
  138. /* istanbul ignore next */
  139. /* harmony default export */ var src_bar = ({
  140. name: 'Bar',
  141. props: {
  142. vertical: Boolean,
  143. size: String,
  144. move: Number
  145. },
  146. computed: {
  147. bar: function bar() {
  148. return BAR_MAP[this.vertical ? 'vertical' : 'horizontal'];
  149. },
  150. wrap: function wrap() {
  151. return this.$parent.wrap;
  152. }
  153. },
  154. render: function render(h) {
  155. var size = this.size,
  156. move = this.move,
  157. bar = this.bar;
  158. return h(
  159. 'div',
  160. {
  161. 'class': ['el-scrollbar__bar', 'is-' + bar.key],
  162. on: {
  163. 'mousedown': this.clickTrackHandler
  164. }
  165. },
  166. [h('div', {
  167. ref: 'thumb',
  168. 'class': 'el-scrollbar__thumb',
  169. on: {
  170. 'mousedown': this.clickThumbHandler
  171. },
  172. style: renderThumbStyle({ size: size, move: move, bar: bar }) })]
  173. );
  174. },
  175. methods: {
  176. clickThumbHandler: function clickThumbHandler(e) {
  177. // prevent click event of right button
  178. if (e.ctrlKey || e.button === 2) {
  179. return;
  180. }
  181. this.startDrag(e);
  182. this[this.bar.axis] = e.currentTarget[this.bar.offset] - (e[this.bar.client] - e.currentTarget.getBoundingClientRect()[this.bar.direction]);
  183. },
  184. clickTrackHandler: function clickTrackHandler(e) {
  185. var offset = Math.abs(e.target.getBoundingClientRect()[this.bar.direction] - e[this.bar.client]);
  186. var thumbHalf = this.$refs.thumb[this.bar.offset] / 2;
  187. var thumbPositionPercentage = (offset - thumbHalf) * 100 / this.$el[this.bar.offset];
  188. this.wrap[this.bar.scroll] = thumbPositionPercentage * this.wrap[this.bar.scrollSize] / 100;
  189. },
  190. startDrag: function startDrag(e) {
  191. e.stopImmediatePropagation();
  192. this.cursorDown = true;
  193. Object(dom_["on"])(document, 'mousemove', this.mouseMoveDocumentHandler);
  194. Object(dom_["on"])(document, 'mouseup', this.mouseUpDocumentHandler);
  195. document.onselectstart = function () {
  196. return false;
  197. };
  198. },
  199. mouseMoveDocumentHandler: function mouseMoveDocumentHandler(e) {
  200. if (this.cursorDown === false) return;
  201. var prevPage = this[this.bar.axis];
  202. if (!prevPage) return;
  203. var offset = (this.$el.getBoundingClientRect()[this.bar.direction] - e[this.bar.client]) * -1;
  204. var thumbClickPosition = this.$refs.thumb[this.bar.offset] - prevPage;
  205. var thumbPositionPercentage = (offset - thumbClickPosition) * 100 / this.$el[this.bar.offset];
  206. this.wrap[this.bar.scroll] = thumbPositionPercentage * this.wrap[this.bar.scrollSize] / 100;
  207. },
  208. mouseUpDocumentHandler: function mouseUpDocumentHandler(e) {
  209. this.cursorDown = false;
  210. this[this.bar.axis] = 0;
  211. Object(dom_["off"])(document, 'mousemove', this.mouseMoveDocumentHandler);
  212. document.onselectstart = null;
  213. }
  214. },
  215. destroyed: function destroyed() {
  216. Object(dom_["off"])(document, 'mouseup', this.mouseUpDocumentHandler);
  217. }
  218. });
  219. // CONCATENATED MODULE: ./packages/scrollbar/src/main.js
  220. // reference https://github.com/noeldelgado/gemini-scrollbar/blob/master/index.js
  221. /* istanbul ignore next */
  222. /* harmony default export */ var main = ({
  223. name: 'ElScrollbar',
  224. components: { Bar: src_bar },
  225. props: {
  226. native: Boolean,
  227. wrapStyle: {},
  228. wrapClass: {},
  229. viewClass: {},
  230. viewStyle: {},
  231. noresize: Boolean, // 如果 container 尺寸不会发生变化,最好设置它可以优化性能
  232. tag: {
  233. type: String,
  234. default: 'div'
  235. }
  236. },
  237. data: function data() {
  238. return {
  239. sizeWidth: '0',
  240. sizeHeight: '0',
  241. moveX: 0,
  242. moveY: 0
  243. };
  244. },
  245. computed: {
  246. wrap: function wrap() {
  247. return this.$refs.wrap;
  248. }
  249. },
  250. render: function render(h) {
  251. var gutter = scrollbar_width_default()();
  252. var style = this.wrapStyle;
  253. if (gutter) {
  254. var gutterWith = '-' + gutter + 'px';
  255. var gutterStyle = 'margin-bottom: ' + gutterWith + '; margin-right: ' + gutterWith + ';';
  256. if (Array.isArray(this.wrapStyle)) {
  257. style = Object(util_["toObject"])(this.wrapStyle);
  258. style.marginRight = style.marginBottom = gutterWith;
  259. } else if (typeof this.wrapStyle === 'string') {
  260. style += gutterStyle;
  261. } else {
  262. style = gutterStyle;
  263. }
  264. }
  265. var view = h(this.tag, {
  266. class: ['el-scrollbar__view', this.viewClass],
  267. style: this.viewStyle,
  268. ref: 'resize'
  269. }, this.$slots.default);
  270. var wrap = h(
  271. 'div',
  272. {
  273. ref: 'wrap',
  274. style: style,
  275. on: {
  276. 'scroll': this.handleScroll
  277. },
  278. 'class': [this.wrapClass, 'el-scrollbar__wrap', gutter ? '' : 'el-scrollbar__wrap--hidden-default'] },
  279. [[view]]
  280. );
  281. var nodes = void 0;
  282. if (!this.native) {
  283. nodes = [wrap, h(src_bar, {
  284. attrs: {
  285. move: this.moveX,
  286. size: this.sizeWidth }
  287. }), h(src_bar, {
  288. attrs: {
  289. vertical: true,
  290. move: this.moveY,
  291. size: this.sizeHeight }
  292. })];
  293. } else {
  294. nodes = [h(
  295. 'div',
  296. {
  297. ref: 'wrap',
  298. 'class': [this.wrapClass, 'el-scrollbar__wrap'],
  299. style: style },
  300. [[view]]
  301. )];
  302. }
  303. return h('div', { class: 'el-scrollbar' }, nodes);
  304. },
  305. methods: {
  306. handleScroll: function handleScroll() {
  307. var wrap = this.wrap;
  308. this.moveY = wrap.scrollTop * 100 / wrap.clientHeight;
  309. this.moveX = wrap.scrollLeft * 100 / wrap.clientWidth;
  310. },
  311. update: function update() {
  312. var heightPercentage = void 0,
  313. widthPercentage = void 0;
  314. var wrap = this.wrap;
  315. if (!wrap) return;
  316. heightPercentage = wrap.clientHeight * 100 / wrap.scrollHeight;
  317. widthPercentage = wrap.clientWidth * 100 / wrap.scrollWidth;
  318. this.sizeHeight = heightPercentage < 100 ? heightPercentage + '%' : '';
  319. this.sizeWidth = widthPercentage < 100 ? widthPercentage + '%' : '';
  320. }
  321. },
  322. mounted: function mounted() {
  323. if (this.native) return;
  324. this.$nextTick(this.update);
  325. !this.noresize && Object(resize_event_["addResizeListener"])(this.$refs.resize, this.update);
  326. },
  327. beforeDestroy: function beforeDestroy() {
  328. if (this.native) return;
  329. !this.noresize && Object(resize_event_["removeResizeListener"])(this.$refs.resize, this.update);
  330. }
  331. });
  332. // CONCATENATED MODULE: ./packages/scrollbar/index.js
  333. /* istanbul ignore next */
  334. main.install = function (Vue) {
  335. Vue.component(main.name, main);
  336. };
  337. /* harmony default export */ var scrollbar = __webpack_exports__["default"] = (main);
  338. /***/ }),
  339. /***/ 16:
  340. /***/ (function(module, exports) {
  341. module.exports = require("element-ui/lib/utils/resize-event");
  342. /***/ }),
  343. /***/ 2:
  344. /***/ (function(module, exports) {
  345. module.exports = require("element-ui/lib/utils/dom");
  346. /***/ }),
  347. /***/ 3:
  348. /***/ (function(module, exports) {
  349. module.exports = require("element-ui/lib/utils/util");
  350. /***/ }),
  351. /***/ 38:
  352. /***/ (function(module, exports) {
  353. module.exports = require("element-ui/lib/utils/scrollbar-width");
  354. /***/ })
  355. /******/ });