ten-design-vue
Version:
ten-vue
480 lines (419 loc) • 15 kB
JavaScript
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 2);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports) {
module.exports = require("./util");
/***/ }),
/* 1 */
/***/ (function(module, exports) {
module.exports = require("../affix");
/***/ }),
/* 2 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./src/components/anchor/anchor.vue?vue&type=template&id=6bb53d24&
var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c(_vm.wrapper,{tag:"component",attrs:{"target":_vm.target,"offset-top":_vm.offsetTop,"offset-bottom":_vm.offsetBottom}},[_c('div',{staticClass:"ten-anchor-wrapper",style:({ maxHeight: _vm.offsetTop ? ("calc(100vh - " + _vm.offsetTop + "px)") : '100vh' })},[_c('div',{staticClass:"ten-anchor"},[_c('div',{staticClass:"ten-anchor__prefix"},[_c('span',{ref:"dot",class:['ten-anchor__prefix-dot', { visible: _vm.activeLink }]})]),_vm._t("default")],2)])])}
var staticRenderFns = []
// CONCATENATED MODULE: ./src/components/anchor/anchor.vue?vue&type=template&id=6bb53d24&
// EXTERNAL MODULE: external "../affix"
var external_affix_ = __webpack_require__(1);
var external_affix_default = /*#__PURE__*/__webpack_require__.n(external_affix_);
// EXTERNAL MODULE: external "./util"
var external_util_ = __webpack_require__(0);
// CONCATENATED MODULE: ./node_modules/babel-loader/lib??ref--1!./node_modules/vue-loader/lib??vue-loader-options!./src/components/anchor/anchor.vue?vue&type=script&lang=js&
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
var anchorvue_type_script_lang_js_name = 'ten-anchor';
var CustomWrapper = {
render: function render(h) {
return h('div', this.$slots.default);
}
};
/* harmony default export */ var anchorvue_type_script_lang_js_ = ({
name: anchorvue_type_script_lang_js_name,
provide: function provide() {
return {
anchor: this
};
},
components: {
CustomWrapper: CustomWrapper,
TenAffix: external_affix_default.a
},
props: {
/**
* 开启固定模式
*/
affix: {
type: Boolean,
default: true
},
/**
* 锚点区域边界
*/
bounds: {
type: Number,
default: 5
},
/**
* 是否显示小圆点
*/
showDot: {
type: Boolean,
default: true
},
/**
* 监听滚动的元素(默认为window),传入选择器字符串如'#parent'
*/
target: String,
/**
* 距离窗口顶部达到指定偏移量后触发
*/
offsetTop: {
type: Number,
default: 0
},
/**
* 距离窗口底部达到指定偏移量后触发
*/
offsetBottom: {
type: Number
}
},
data: function data() {
this.links = [];
this.container = null;
return {
activeLink: null
};
},
computed: {
wrapper: function wrapper() {
return this.affix ? 'ten-affix' : 'custom-wrapper';
}
},
mounted: function mounted() {
var _this = this;
this.$on('link:click', this.onLinkClick);
this.$nextTick(function () {
_this.container = document.querySelector(_this.target) || window;
_this.container.addEventListener('scroll', _this.handleScroll);
_this.handleScroll();
});
},
beforeDestroy: function beforeDestroy() {
this.container.addEventListener('scroll', this.handleScroll);
},
updated: function updated() {
this.$nextTick(this.updateDot);
},
methods: {
appendLink: function appendLink(link) {
if (!this.links.includes(link)) {
this.links.push(link);
}
},
removeLink: function removeLink(link) {
var index = this.links.indexOf(link);
if (index !== -1) {
this.links.splice(index, 1);
}
},
onLinkClick: function onLinkClick(e, link) {
/**
* 锚点点击时触发
*
* @event click
* @param {Object} LinkProps
*/
this.$emit('click', e, link.$props);
},
handleScroll: function handleScroll() {
if (this.animating) {
return;
}
var offsetTop = this.offsetTop,
bounds = this.bounds;
this.activeLink = this.getCurrentAnchor(offsetTop, bounds);
},
scrollTo: function scrollTo(link) {
var _this2 = this;
var offsetTop = this.offsetTop,
container = this.container;
this.animating = true;
this.activeLink = link;
Object(external_util_["scrollTo"])(link, offsetTop, container, function () {
_this2.animating = false;
});
},
getCurrentAnchor: function getCurrentAnchor() {
var _this3 = this;
var offsetTop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
var bounds = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5;
var activeLink = '';
if (typeof document === 'undefined') {
return activeLink;
}
var linkSections = [];
this.links.forEach(function (link) {
var sharpLinkMatch = external_util_["sharpMatcherRegx"].exec(link.toString());
if (!sharpLinkMatch) {
return;
}
var target = document.getElementById(sharpLinkMatch[1]);
if (target) {
var top = Object(external_util_["getOffsetTop"])(target, _this3.container);
if (top < offsetTop + bounds) {
linkSections.push({
link: link,
top: top
});
}
}
});
if (linkSections.length) {
var maxSection = linkSections.reduce(function (prev, curr) {
return curr.top > prev.top ? curr : prev;
}); // eslint-disable-line
return maxSection.link;
}
return '';
},
updateDot: function updateDot() {
if (typeof document === 'undefined') {
return;
}
var _this$$el$getElements = this.$el.getElementsByClassName("".concat(anchorvue_type_script_lang_js_name, "-link-title--active")),
_this$$el$getElements2 = _slicedToArray(_this$$el$getElements, 1),
linkNode = _this$$el$getElements2[0];
if (linkNode) {
this.$refs.dot.style.top = "".concat(linkNode.offsetTop + linkNode.clientHeight / 2 - 4.5, "px");
}
}
}
});
// CONCATENATED MODULE: ./src/components/anchor/anchor.vue?vue&type=script&lang=js&
/* harmony default export */ var anchor_anchorvue_type_script_lang_js_ = (anchorvue_type_script_lang_js_);
// CONCATENATED MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
/* globals __VUE_SSR_CONTEXT__ */
// IMPORTANT: Do NOT use ES2015 features in this file (except for modules).
// This module is a runtime utility for cleaner component module output and will
// be included in the final webpack user bundle.
function normalizeComponent (
scriptExports,
render,
staticRenderFns,
functionalTemplate,
injectStyles,
scopeId,
moduleIdentifier, /* server only */
shadowMode /* vue-cli only */
) {
// Vue.extend constructor export interop
var options = typeof scriptExports === 'function'
? scriptExports.options
: scriptExports
// render functions
if (render) {
options.render = render
options.staticRenderFns = staticRenderFns
options._compiled = true
}
// functional template
if (functionalTemplate) {
options.functional = true
}
// scopedId
if (scopeId) {
options._scopeId = 'data-v-' + scopeId
}
var hook
if (moduleIdentifier) { // server build
hook = function (context) {
// 2.3 injection
context =
context || // cached call
(this.$vnode && this.$vnode.ssrContext) || // stateful
(this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
// 2.2 with runInNewContext: true
if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
context = __VUE_SSR_CONTEXT__
}
// inject component styles
if (injectStyles) {
injectStyles.call(this, context)
}
// register component module identifier for async chunk inferrence
if (context && context._registeredComponents) {
context._registeredComponents.add(moduleIdentifier)
}
}
// used by ssr in case component is cached and beforeCreate
// never gets called
options._ssrRegister = hook
} else if (injectStyles) {
hook = shadowMode
? function () {
injectStyles.call(
this,
(options.functional ? this.parent : this).$root.$options.shadowRoot
)
}
: injectStyles
}
if (hook) {
if (options.functional) {
// for template-only hot-reload because in that case the render fn doesn't
// go through the normalizer
options._injectStyles = hook
// register for functional component in vue file
var originalRender = options.render
options.render = function renderWithStyleInjection (h, context) {
hook.call(context)
return originalRender(h, context)
}
} else {
// inject component registration as beforeCreate hook
var existing = options.beforeCreate
options.beforeCreate = existing
? [].concat(existing, hook)
: [hook]
}
}
return {
exports: scriptExports,
options: options
}
}
// CONCATENATED MODULE: ./src/components/anchor/anchor.vue
/* normalize component */
var component = normalizeComponent(
anchor_anchorvue_type_script_lang_js_,
render,
staticRenderFns,
false,
null,
null,
null
)
/* harmony default export */ var anchor_anchor = __webpack_exports__["default"] = (component.exports);
/***/ })
/******/ ]);