v-md-editor
Version:
A markdown editor built on Vue
1,570 lines (1,431 loc) • 129 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("vue"));
else if(typeof define === 'function' && define.amd)
define("VMdEditor", ["vue"], factory);
else if(typeof exports === 'object')
exports["VMdEditor"] = factory(require("vue"));
else
root["VMdEditor"] = factory(root["Vue"]);
})(typeof self !== 'undefined' ? self : this, function(__WEBPACK_EXTERNAL_MODULE__0__) {
return /******/ (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 = 12);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE__0__;
/***/ }),
/* 1 */,
/* 2 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "f", function() { return isObject; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return arraytoObject; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "c", function() { return importAll; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "d", function() { return inBrowser; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "e", function() { return isKorean; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return generatorText; });
var toString = Object.prototype.toString;
var isObject = function isObject(target) {
return toString.call(target) === '[object Object]';
};
function extend(to, _from) {
Object.keys(_from).forEach(function (key) {
to[key] = _from[key];
});
return to;
}
function arraytoObject(arr) {
var res = {};
for (var i = 0; i < arr.length; i++) {
if (arr[i]) {
extend(res, arr[i]);
}
}
return res;
}
function importAll(map, r) {
r.keys().forEach(function (filePath) {
map[filePath] = r(filePath);
});
}
var inBrowser = typeof window !== 'undefined';
function isKorean(text) {
var reg = /([(\uAC00-\uD7AF)|(\u3130-\u318F)])+/gi;
return reg.test(text);
}
function generatorText(_ref) {
var selected = _ref.selected,
InsertGetter = _ref.InsertGetter,
_ref$selectedGetter = _ref.selectedGetter,
selectedGetter = _ref$selectedGetter === void 0 ? function (selected) {
return selected;
} : _ref$selectedGetter,
_ref$ignoreEmptyLine = _ref.ignoreEmptyLine,
ignoreEmptyLine = _ref$ignoreEmptyLine === void 0 ? true : _ref$ignoreEmptyLine;
var insertContent;
var newSelected;
if (selected) {
newSelected = selectedGetter(selected);
insertContent = InsertGetter(selected, 1);
// 如果当前选中的文本包含换行 则插入后选中插入的所有文本
if (selected.indexOf('\n') !== -1) {
insertContent = selected.split('\n').map(function (rowText, index) {
var isEmptyLine = !rowText;
if (ignoreEmptyLine && isEmptyLine) return '';
return InsertGetter(rowText, index + 1).replace(selectedGetter(null), '');
}).join('\n');
newSelected = insertContent;
}
} else {
insertContent = InsertGetter(null, 1);
newSelected = selectedGetter(selected);
}
return {
insertContent: insertContent,
newSelected: newSelected
};
}
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// runtime helper for setting properties on components
// in a tree-shakable way
exports.default = (sfc, props) => {
const target = sfc.__vccOpts || sfc;
for (const [key, val] of props) {
target[key] = val;
}
return target;
};
/***/ }),
/* 4 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "c", function() { return LINE_MARKUP; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return HEADING_MARKUP; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return ANCHOR_MARKUP; });
var LINE_MARKUP = 'data-v-md-line';
var HEADING_MARKUP = 'data-v-md-heading';
var ANCHOR_MARKUP = 'data-v-md-anchor';
/***/ }),
/* 5 */,
/* 6 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return addResizeListener; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return removeResizeListener; });
/* harmony import */ var resize_observer_polyfill__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(22);
// Modified from https://github.com/ElemeFE/element/blob/dev/src/utils/resize-event.js
/* eslint-disable no-underscore-dangle */
var isServer = typeof window === 'undefined';
/* istanbul ignore next */
var resizeHandler = function resizeHandler(entries) {
entries.forEach(function (entry) {
var listeners = entry.target.__resizeListeners__ || [];
if (listeners.length) {
listeners.forEach(function (fn) {
fn();
});
}
});
};
/* istanbul ignore next */
var addResizeListener = function addResizeListener(element, fn) {
if (isServer) return;
if (!element.__resizeListeners__) {
element.__resizeListeners__ = [];
element.__ro__ = new resize_observer_polyfill__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"](resizeHandler);
element.__ro__.observe(element);
}
element.__resizeListeners__.push(fn);
};
/* istanbul ignore next */
var removeResizeListener = function removeResizeListener(element, fn) {
if (!element || !element.__resizeListeners__) return;
element.__resizeListeners__.splice(element.__resizeListeners__.indexOf(fn), 1);
if (!element.__resizeListeners__.length) {
element.__ro__.disconnect();
}
};
/***/ }),
/* 7 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _extends; });
function _extends() {
_extends = Object.assign ? Object.assign.bind() : function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
/***/ }),
/* 8 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return getScrollTop; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return scrollTo; });
function getScrollTop(target) {
var result = 0;
if (target === window) {
result = target.pageYOffset;
} else if (target) {
result = target.scrollTop;
}
return result;
}
function scrollTo(target, scrollTop) {
if (target === window) {
window.scrollTo(window.pageYOffset, scrollTop);
} else if (target) {
target.scrollTop = scrollTop;
}
}
/***/ }),
/* 9 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return smooth; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return smoothScroll; });
/* harmony import */ var _scroll_top__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(8);
function smooth(_ref) {
var currentScrollTop = _ref.currentScrollTop,
scrollToTop = _ref.scrollToTop,
scrollFn = _ref.scrollFn,
_ref$percent = _ref.percent,
percent = _ref$percent === void 0 ? 10 : _ref$percent,
onScrollEnd = _ref.onScrollEnd;
var scrollWay = scrollToTop > currentScrollTop ? 'down' : 'up';
var step = (scrollToTop - currentScrollTop) * (percent / 100);
var id;
var scroll = function scroll() {
currentScrollTop += step;
if (scrollWay === 'down' && currentScrollTop >= scrollToTop || scrollWay === 'up' && currentScrollTop <= scrollToTop) {
scrollFn(scrollToTop);
window.cancelAnimationFrame(id);
if (onScrollEnd) window.requestAnimationFrame(onScrollEnd);
} else {
scrollFn(currentScrollTop);
window.requestAnimationFrame(scroll);
}
};
window.requestAnimationFrame(scroll);
}
function smoothScroll(_ref2) {
var scrollTarget = _ref2.scrollTarget,
scrollToTop = _ref2.scrollToTop,
_ref2$percent = _ref2.percent,
percent = _ref2$percent === void 0 ? 10 : _ref2$percent,
onScrollEnd = _ref2.onScrollEnd;
var currentScrollTop = Object(_scroll_top__WEBPACK_IMPORTED_MODULE_0__[/* getScrollTop */ "a"])(scrollTarget);
smooth({
currentScrollTop: currentScrollTop,
scrollToTop: scrollToTop,
scrollFn: function scrollFn(scrollTop) {
return Object(_scroll_top__WEBPACK_IMPORTED_MODULE_0__[/* scrollTo */ "b"])(scrollTarget, scrollTop);
},
percent: percent,
onScrollEnd: onScrollEnd
});
}
/***/ }),
/* 10 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
// EXTERNAL MODULE: external {"root":"Vue","commonjs":"vue","commonjs2":"vue","amd":"vue"}
var external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_ = __webpack_require__(0);
// EXTERNAL MODULE: ./src/utils/resize-event.js
var resize_event = __webpack_require__(6);
// CONCATENATED MODULE: ./src/utils/scrollbar-width.js
// Modified from https://github.com/ElemeFE/element/blob/dev/src/utils/scrollbar-width.js
var scrollBarWidth;
var isServer = typeof window === 'undefined';
/* harmony default export */ var scrollbar_width = (function () {
if (isServer) return 0;
if (scrollBarWidth !== undefined) return scrollBarWidth;
var outer = document.createElement('div');
outer.className = 'scrollbar__wrap';
outer.style.visibility = 'hidden';
outer.style.width = '100px';
outer.style.position = 'absolute';
outer.style.top = '-9999px';
document.body.appendChild(outer);
var widthNoScroll = outer.offsetWidth;
outer.style.overflow = 'scroll';
var inner = document.createElement('div');
inner.style.width = '100%';
outer.appendChild(inner);
var widthWithScroll = inner.offsetWidth;
outer.parentNode.removeChild(outer);
scrollBarWidth = widthNoScroll - widthWithScroll;
return scrollBarWidth;
});
// EXTERNAL MODULE: ./src/utils/util.js
var util = __webpack_require__(2);
// CONCATENATED MODULE: ./src/components/scrollbar/util.js
// Modified from https://github.com/ElemeFE/element/tree/dev/packages/scrollbar
var BAR_MAP = {
vertical: {
offset: 'offsetHeight',
scroll: 'scrollTop',
scrollSize: 'scrollHeight',
size: 'height',
key: 'vertical',
axis: 'Y',
client: 'clientY',
direction: 'top'
},
horizontal: {
offset: 'offsetWidth',
scroll: 'scrollLeft',
scrollSize: 'scrollWidth',
size: 'width',
key: 'horizontal',
axis: 'X',
client: 'clientX',
direction: 'left'
}
};
function renderThumbStyle(_ref) {
var move = _ref.move,
size = _ref.size,
bar = _ref.bar;
var style = {};
var translate = "translate" + bar.axis + "(" + move + "%)";
style[bar.size] = size;
style.transform = translate;
style.msTransform = translate;
style.webkitTransform = translate;
return style;
}
// CONCATENATED MODULE: ./src/components/scrollbar/bar.js
// Modified from https://github.com/ElemeFE/element/tree/dev/packages/scrollbar
/* istanbul ignore next */
/* harmony default export */ var scrollbar_bar = ({
name: 'Bar',
props: {
vertical: Boolean,
size: String,
move: Number
},
computed: {
bar: function bar() {
return BAR_MAP[this.vertical ? 'vertical' : 'horizontal'];
},
wrap: function wrap() {
return this.$parent.wrap;
}
},
render: function render() {
var size = this.size,
move = this.move,
bar = this.bar;
return Object(external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_["createVNode"])("div", {
"class": ['scrollbar__bar', 'is-' + bar.key],
"onMousedown": this.clickTrackHandler,
"onClick": function onClick(e) {
return e.stopPropagation();
}
}, [Object(external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_["createVNode"])("div", {
"ref": "thumb",
"class": "scrollbar__thumb",
"onMousedown": this.clickThumbHandler,
"style": renderThumbStyle({
size: size,
move: move,
bar: bar
})
}, null)]);
},
methods: {
clickThumbHandler: function clickThumbHandler(e) {
// prevent click event of right button
if (e.ctrlKey || e.button === 2) {
return;
}
this.startDrag(e);
this[this.bar.axis] = e.currentTarget[this.bar.offset] - (e[this.bar.client] - e.currentTarget.getBoundingClientRect()[this.bar.direction]);
},
clickTrackHandler: function clickTrackHandler(e) {
var offset = Math.abs(e.target.getBoundingClientRect()[this.bar.direction] - e[this.bar.client]);
var thumbHalf = this.$refs.thumb[this.bar.offset] / 2;
var thumbPositionPercentage = (offset - thumbHalf) * 100 / this.$el[this.bar.offset];
this.wrap[this.bar.scroll] = thumbPositionPercentage * this.wrap[this.bar.scrollSize] / 100;
},
startDrag: function startDrag(e) {
e.stopImmediatePropagation();
this.cursorDown = true;
document.addEventListener('mousemove', this.mouseMoveDocumentHandler, false);
document.addEventListener('mouseup', this.mouseUpDocumentHandler, false);
document.onselectstart = function () {
return false;
};
},
mouseMoveDocumentHandler: function mouseMoveDocumentHandler(e) {
if (this.cursorDown === false) return;
var prevPage = this[this.bar.axis];
if (!prevPage) return;
var offset = (this.$el.getBoundingClientRect()[this.bar.direction] - e[this.bar.client]) * -1;
var thumbClickPosition = this.$refs.thumb[this.bar.offset] - prevPage;
var thumbPositionPercentage = (offset - thumbClickPosition) * 100 / this.$el[this.bar.offset];
this.wrap[this.bar.scroll] = thumbPositionPercentage * this.wrap[this.bar.scrollSize] / 100;
},
mouseUpDocumentHandler: function mouseUpDocumentHandler() {
this.cursorDown = false;
this[this.bar.axis] = 0;
document.removeEventListener('mousemove', this.mouseMoveDocumentHandler, false);
document.onselectstart = null;
}
},
unmounted: function unmounted() {
document.removeEventListener('mouseup', this.mouseUpDocumentHandler, false);
}
});
// EXTERNAL MODULE: ./src/utils/smooth-scroll.js
var smooth_scroll = __webpack_require__(9);
// CONCATENATED MODULE: ./node_modules/babel-loader/lib??ref--3!./node_modules/vue-loader/dist??ref--2-0!./src/components/scrollbar/index.vue?vue&type=script&lang=js
// Modified from https://github.com/ElemeFE/element/tree/dev/packages/scrollbar
/* harmony default export */ var scrollbarvue_type_script_lang_js = ({
name: 'scrollbar',
components: {
Bar: scrollbar_bar
},
props: {
native: Boolean,
disabled: Boolean,
wrapStyle: null,
wrapClass: null,
viewClass: null,
viewStyle: null,
noresize: Boolean,
// 如果 container 尺寸不会发生变化,最好设置它可以优化性能
tag: {
type: String,
default: 'div'
}
},
emits: ['scroll'],
data: function data() {
return {
sizeWidth: '0',
sizeHeight: '0',
moveX: 0,
moveY: 0
};
},
computed: {
wrap: function wrap() {
return this.$refs.wrap;
}
},
mounted: function mounted() {
if (this.native || this.disabled) return;
this.$nextTick(this.update);
!this.noresize && Object(resize_event["a" /* addResizeListener */])(this.$refs.resize, this.update);
},
beforeUnmount: function beforeUnmount() {
if (this.native || this.disabled) return;
!this.noresize && Object(resize_event["b" /* removeResizeListener */])(this.$refs.resize, this.update);
},
methods: {
getScrollInfo: function getScrollInfo() {
var wrap = this.wrap;
return {
left: wrap.scrollLeft,
top: wrap.scrollTop,
width: wrap.scrollWidth,
height: wrap.scrollHeight,
clientWidth: wrap.clientWidth,
clientHeight: wrap.clientHeight
};
},
scrollTo: function scrollTo(scrollTop) {
Object(smooth_scroll["a" /* default */])({
scrollTarget: this.wrap,
scrollToTop: scrollTop
});
},
handleScroll: function handleScroll() {
var wrap = this.wrap;
this.moveY = wrap.scrollTop * 100 / wrap.clientHeight;
this.moveX = wrap.scrollLeft * 100 / wrap.clientWidth;
this.$emit('scroll');
},
update: function update() {
var wrap = this.wrap;
if (!wrap) return;
var heightPercentage = wrap.clientHeight * 100 / wrap.scrollHeight;
var widthPercentage = wrap.clientWidth * 100 / wrap.scrollWidth;
this.sizeHeight = heightPercentage < 100 ? heightPercentage + '%' : '';
this.sizeWidth = widthPercentage < 100 ? widthPercentage + '%' : '';
}
},
render: function render() {
if (this.disabled) return this.$slots.default();
var gutter = scrollbar_width();
var style = this.wrapStyle;
if (gutter) {
var scrollView = this.$refs.resize;
var wrapper = this.$refs.wrap;
var scrollViewHeight = scrollView == null ? void 0 : scrollView.scrollHeight;
var scrollViewWidth = scrollView == null ? void 0 : scrollView.scrollWidth;
var wrapperHeight = wrapper == null ? void 0 : wrapper.clientHeight;
var wrapperWidth = wrapper == null ? void 0 : wrapper.clientWidth;
var gutterWith = "-" + gutter + "px";
var marginBottom = scrollViewWidth > wrapperWidth ? gutterWith : 0;
var marginRight = scrollViewHeight > wrapperHeight ? gutterWith : 0;
var gutterStyle = "margin-bottom: " + marginBottom + "; margin-right: " + marginRight + ";";
if (Array.isArray(this.wrapStyle)) {
style = Object(util["a" /* arraytoObject */])(this.wrapStyle);
style.marginRight = gutterWith;
style.marginBottom = gutterWith;
} else if (typeof this.wrapStyle === 'string') {
style += gutterStyle;
} else {
style = gutterStyle;
}
}
var view = Object(external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_["h"])(this.tag, {
class: ['scrollbar__view', this.viewClass],
style: this.viewStyle,
ref: 'resize'
}, this.$slots.default());
var wrap = Object(external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_["createVNode"])("div", {
"ref": "wrap",
"style": style,
"onScroll": this.handleScroll,
"class": [this.wrapClass, 'scrollbar__wrap', gutter ? '' : 'scrollbar__wrap--hidden-default']
}, [[view]]);
var nodes;
if (!this.native) {
nodes = [wrap, Object(external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_["createVNode"])(scrollbar_bar, {
"move": this.moveX,
"size": this.sizeWidth
}, null), Object(external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_["createVNode"])(scrollbar_bar, {
"vertical": true,
"move": this.moveY,
"size": this.sizeHeight
}, null)];
} else {
nodes = [Object(external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_["createVNode"])("div", {
"ref": "wrap",
"class": [this.wrapClass, 'scrollbar__wrap'],
"style": style
}, [[view]])];
}
return Object(external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_["h"])('div', {
class: 'scrollbar'
}, nodes);
}
});
// CONCATENATED MODULE: ./src/components/scrollbar/index.vue?vue&type=script&lang=js
// EXTERNAL MODULE: ./src/components/scrollbar/index.vue?vue&type=style&index=0&id=887b7bde&lang=scss
var scrollbarvue_type_style_index_0_id_887b7bde_lang_scss = __webpack_require__(32);
// CONCATENATED MODULE: ./src/components/scrollbar/index.vue
const __exports__ = scrollbarvue_type_script_lang_js;
/* harmony default export */ var scrollbar = __webpack_exports__["a"] = (__exports__);
/***/ }),
/* 11 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/extends.js
var esm_extends = __webpack_require__(7);
// EXTERNAL MODULE: ./node_modules/xss/lib/index.js
var lib = __webpack_require__(14);
var lib_default = /*#__PURE__*/__webpack_require__.n(lib);
// CONCATENATED MODULE: ./src/utils/xss/svg.js
/* harmony default export */ var svg = ({
svg: [],
altGlyph: [],
altGlyphDef: [],
altGlyphItem: [],
animate: [],
animateColor: [],
animateMotion: [],
animateTransform: [],
circle: [],
clipPath: [],
'color-profile': [],
cursor: [],
'definition-src': [],
defs: [],
desc: [],
ellipse: [],
feBlend: [],
feColorMatrix: [],
feComponentTransfer: [],
feComposite: [],
feConvolveMatrix: [],
feDiffuseLighting: [],
feDisplacementMap: [],
feDistantLight: [],
feFlood: [],
feFuncA: [],
feFuncB: [],
feFuncG: [],
feFuncR: [],
feGaussianBlur: [],
feImage: [],
feMerge: [],
feMergeNode: [],
feMorphology: [],
feOffset: [],
fePointLight: [],
feSpecularLighting: [],
feSpotLight: [],
feTile: [],
feTurbulence: [],
filter: [],
font: [],
foreignObject: [],
g: [],
glyph: [],
glyphRef: [],
hkern: [],
image: [],
line: [],
linearGradient: [],
marker: [],
mask: [],
metadata: [],
'missing-glyph': [],
mpath: [],
path: [],
pattern: [],
polygon: [],
polyline: [],
radialGradient: [],
rect: [],
set: [],
stop: [],
style: [],
switch: [],
symbol: [],
text: [],
textPath: [],
title: [],
tref: [],
tspan: [],
use: [],
view: [],
vkern: []
});
// CONCATENATED MODULE: ./src/utils/xss/KaTex.js
/* harmony default export */ var KaTex = ({
math: [],
annotation: [],
semantics: [],
mtext: [],
mn: [],
mo: [],
mi: [],
mspace: [],
mover: [],
munder: [],
munderover: [],
msup: [],
msub: [],
msubsup: [],
mfrac: [],
mroot: [],
msqrt: [],
mtable: [],
mtr: [],
mtd: [],
mlabeledtr: [],
mrow: [],
menclose: [],
mstyle: [],
mpadded: [],
mphantom: [],
mglyph: []
});
// CONCATENATED MODULE: ./src/utils/xss/common.js
var attrWhiteList = ['style', 'align', 'class', 'id', 'title'];
var prefixAttrWhiteList = ['data-'];
var tags = {
input: ['type'],
ol: ['reversed', 'start', 'type'],
button: ['type'],
summary: []
};
// CONCATENATED MODULE: ./src/utils/xss/index.js
var tagWhiteList = Object(esm_extends["a" /* default */])({}, tags, KaTex, svg);
var options = {
whiteList: Object(esm_extends["a" /* default */])({}, lib_default.a.getDefaultWhiteList(), tagWhiteList),
onIgnoreTagAttr: function onIgnoreTagAttr(tag, name, value) {
if (svg[tag] || KaTex[tag] || attrWhiteList.find(function (attr) {
return attr === name;
}) || prefixAttrWhiteList.find(function (prefix) {
return name.startsWith(prefix);
})) {
return name + "=\"" + lib_default.a.escapeAttrValue(value) + "\"";
}
}
};
var xssFilterInstance = new lib_default.a.FilterXSS(options);
xssFilterInstance.extend = function (extendOptions) {
var instanceOptions = xssFilterInstance.options;
Object.keys(extendOptions).forEach(function (optionName) {
// extend whiteList
if (optionName === 'whiteList') {
Object.keys(extendOptions.whiteList).forEach(function (tagName) {
var tagAttrWhiteList = extendOptions.whiteList[tagName];
var instanceWhiteList = instanceOptions.whiteList;
if (instanceWhiteList[tagName]) {
instanceWhiteList[tagName] = [].concat(instanceWhiteList[tagName], tagAttrWhiteList);
} else {
instanceWhiteList[tagName] = tagAttrWhiteList;
}
});
} else if (optionName === 'onIgnoreTagAttr') {
var oldHandler = instanceOptions.onIgnoreTagAttr;
instanceOptions.onIgnoreTagAttr = function () {
var _extendOptions$onIgno;
for (var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++) {
arg[_key] = arguments[_key];
}
var oldReturnVal = oldHandler.call.apply(oldHandler, [this].concat(arg));
var newReturnVal = (_extendOptions$onIgno = extendOptions.onIgnoreTagAttr).call.apply(_extendOptions$onIgno, [this].concat(arg));
return oldReturnVal || newReturnVal;
};
} else {
instanceOptions[optionName] = extendOptions[optionName];
}
});
};
/* harmony default export */ var xss = __webpack_exports__["a"] = (xssFilterInstance);
/***/ }),
/* 12 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// EXTERNAL MODULE: external {"root":"Vue","commonjs":"vue","commonjs2":"vue","amd":"vue"}
var external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_ = __webpack_require__(0);
// CONCATENATED MODULE: ./node_modules/babel-loader/lib??ref--3!./node_modules/vue-loader/dist/templateLoader.js??ref--6!./node_modules/vue-loader/dist??ref--2-0!./src/preview.vue?vue&type=template&id=91b6d566
var _hoisted_1 = ["innerHTML"];
function render(_ctx, _cache, $props, $setup, $data, $options) {
var _component_scrollbar = Object(external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_["resolveComponent"])("scrollbar");
return Object(external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_["openBlock"])(), Object(external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_["createElementBlock"])("div", {
class: "v-md-editor-preview",
style: Object(external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_["normalizeStyle"])({
tabSize: _ctx.tabSize,
'-moz-tab-size': _ctx.tabSize,
'-o-tab-size': _ctx.tabSize
}),
onClick: _cache[0] || (_cache[0] = function () {
return _ctx.handlePreviewClick && _ctx.handlePreviewClick.apply(_ctx, arguments);
})
}, [Object(external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_["createVNode"])(_component_scrollbar, null, {
default: Object(external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_["withCtx"])(function () {
return [Object(external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_["createElementVNode"])("div", {
class: Object(external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_["normalizeClass"])([_ctx.previewClass]),
innerHTML: _ctx.html
}, null, 10 /* CLASS, PROPS */, _hoisted_1)];
}),
_: 1 /* STABLE */
})], 4 /* STYLE */);
}
// CONCATENATED MODULE: ./src/preview.vue?vue&type=template&id=91b6d566
// EXTERNAL MODULE: ./src/utils/xss/index.js + 3 modules
var xss = __webpack_require__(11);
// EXTERNAL MODULE: ./src/utils/lang.js + 1 modules
var lang = __webpack_require__(17);
// CONCATENATED MODULE: ./src/utils/v-md-parser.js
var v_md_parser_VMdParser = /*#__PURE__*/function () {
function VMdParser() {
this.lang = new lang["a" /* default */]();
}
var _proto = VMdParser.prototype;
_proto.defaultMarkdownLoader = function defaultMarkdownLoader(text) {
return text;
};
_proto.use = function use(optionsOrInstall, opt) {
if (typeof optionsOrInstall === 'function') {
optionsOrInstall(this, opt);
} else {
optionsOrInstall.install(this, opt);
}
return this;
};
_proto.theme = function theme(themeConfig) {
this.themeConfig = themeConfig;
};
_proto.extendMarkdown = function extendMarkdown(extender) {
if (!this.themeConfig) {
return console.error('Please use theme before using plugins');
}
var markdownParser = this.themeConfig.markdownParser;
extender(markdownParser);
};
_proto.parse = function parse(text) {
var _markdownParser$rende;
var markdownParser = this.themeConfig.markdownParser;
var markdownLoader = (markdownParser == null ? void 0 : (_markdownParser$rende = markdownParser.render) == null ? void 0 : _markdownParser$rende.bind(markdownParser)) || this.defaultMarkdownLoader;
if (typeof markdownLoader !== 'function' || markdownLoader === this.defaultMarkdownLoader) {
console.error('Please configure your markdown parser');
}
return markdownLoader(text);
};
return VMdParser;
}();
// EXTERNAL MODULE: ./src/mixins/preview.js
var preview = __webpack_require__(21);
// CONCATENATED MODULE: ./node_modules/babel-loader/lib??ref--3!./node_modules/vue-loader/dist??ref--2-0!./src/preview.vue?vue&type=script&lang=js
// mixins
var component = {
name: 'v-md-preview',
mixins: [preview["a" /* default */]],
props: {
text: {
type: String,
default: ''
},
theme: Object,
beforeChange: Function
},
emits: ['change'],
data: function data() {
return {
html: ''
};
},
watch: {
text: function text() {
this.handleTextChange();
},
langConfig: function langConfig() {
this.handleTextChange();
}
},
computed: {
vMdParser: function vMdParser() {
return this.$options.vMdParser;
},
previewClass: function previewClass() {
return this.vMdParser.themeConfig.previewClass;
},
langConfig: function langConfig() {
return this.vMdParser.lang.langConfig;
}
},
created: function created() {
this.handleTextChange();
},
methods: {
handleTextChange: function handleTextChange() {
var _this = this;
var next = function next(text) {
_this.html = xss["a" /* default */].process(_this.$options.vMdParser.parse(text));
_this.$emit('change', text, _this.html);
};
if (this.beforeChange) {
this.beforeChange(this.text, next);
} else {
next(this.text);
}
}
}
};
var vMdParser = new v_md_parser_VMdParser();
vMdParser.lang.config = Object(external_root_Vue_commonjs_vue_commonjs2_vue_amd_vue_["reactive"])(vMdParser.lang.config);
component.vMdParser = new v_md_parser_VMdParser();
/* harmony default export */ var previewvue_type_script_lang_js = (component);
// CONCATENATED MODULE: ./src/preview.vue?vue&type=script&lang=js
// EXTERNAL MODULE: ./src/preview.vue?vue&type=style&index=0&id=91b6d566&lang=css
var previewvue_type_style_index_0_id_91b6d566_lang_css = __webpack_require__(38);
// EXTERNAL MODULE: ./node_modules/vue-loader/dist/exportHelper.js
var exportHelper = __webpack_require__(3);
var exportHelper_default = /*#__PURE__*/__webpack_require__.n(exportHelper);
// CONCATENATED MODULE: ./src/preview.vue
const __exports__ = /*#__PURE__*/exportHelper_default()(previewvue_type_script_lang_js, [['render',render]])
/* harmony default export */ var src_preview = (__exports__);
// EXTERNAL MODULE: ./src/assets/css/font.css
var font = __webpack_require__(24);
// CONCATENATED MODULE: ./src/preview.js
// This file is auto generated by build/build-entry.js
// font css
var version = '1.0.6';
var preview_install = function install(app) {
app.component(src_preview.name, src_preview);
};
src_preview.version = version;
src_preview.install = preview_install;
src_preview.xss = xss["a" /* default */];
src_preview.use = function (optionsOrInstall, opt) {
if (typeof optionsOrInstall === 'function') {
optionsOrInstall(src_preview, opt);
} else {
optionsOrInstall.install(src_preview, opt);
}
return src_preview;
};
/* harmony default export */ var src_preview_0 = __webpack_exports__["default"] = (src_preview);
/***/ }),
/* 13 */,
/* 14 */
/***/ (function(module, exports, __webpack_require__) {
/**
* xss
*
* @author Zongmin Lei<leizongmin@gmail.com>
*/
var DEFAULT = __webpack_require__(26);
var parser = __webpack_require__(29);
var FilterXSS = __webpack_require__(37);
/**
* filter xss function
*
* @param {String} html
* @param {Object} options { whiteList, onTag, onTagAttr, onIgnoreTag, onIgnoreTagAttr, safeAttrValue, escapeHtml }
* @return {String}
*/
function filterXSS(html, options) {
var xss = new FilterXSS(options);
return xss.process(html);
}
exports = module.exports = filterXSS;
exports.filterXSS = filterXSS;
exports.FilterXSS = FilterXSS;
(function () {
for (var i in DEFAULT) {
exports[i] = DEFAULT[i];
}
for (var j in parser) {
exports[j] = parser[j];
}
})();
// using `xss` on the browser, output `filterXSS` to the globals
if (typeof window !== "undefined") {
window.filterXSS = module.exports;
}
// using `xss` on the WebWorker, output `filterXSS` to the globals
function isWorkerEnv() {
return (
typeof self !== "undefined" &&
typeof DedicatedWorkerGlobalScope !== "undefined" &&
self instanceof DedicatedWorkerGlobalScope
);
}
if (isWorkerEnv()) {
self.filterXSS = module.exports;
}
/***/ }),
/* 15 */,
/* 16 */,
/* 17 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
// EXPORTS
__webpack_require__.d(__webpack_exports__, "a", function() { return /* binding */ lang_Lang; });
// EXTERNAL MODULE: ./src/utils/util.js
var util = __webpack_require__(2);
// CONCATENATED MODULE: ./src/utils/deep-assign.js
var deep_assign_hasOwnProperty = Object.prototype.hasOwnProperty;
function assignKey(to, from, key) {
var val = from[key];
if (val === undefined || val === null) {
return;
}
if (!deep_assign_hasOwnProperty.call(to, key) || !Object(util["f" /* isObject */])(val)) {
to[key] = val;
} else {
// eslint-disable-next-line
to[key] = deepAssign(Object(to[key]), from[key]);
}
}
function deepAssign(to, from) {
Object.keys(from).forEach(function (key) {
assignKey(to, from, key);
});
return to;
}
// CONCATENATED MODULE: ./src/utils/lang.js
var lang_Lang = /*#__PURE__*/function () {
function Lang(options) {
if (options === void 0) {
options = {};
}
this.config = {
lang: 'zh-CN',
langConfig: {
'zh-CN': {}
}
};
this.options = options;
}
var _proto = Lang.prototype;
_proto.use = function use(lang, config) {
var _this$add;
this.config.lang = lang;
this.add((_this$add = {}, _this$add[lang] = config, _this$add));
if (this.options.afterUse) this.options.afterUse(lang, config);
};
_proto.add = function add(config) {
if (config === void 0) {
config = {};
}
deepAssign(this.config.langConfig, config);
};
return Lang;
}();
/***/ }),
/* 18 */
/***/ (function(module, exports, __webpack_require__) {
/**
* cssfilter
*
* @author 老雷<leizongmin@gmail.com>
*/
var DEFAULT = __webpack_require__(27);
var FilterCSS = __webpack_require__(35);
/**
* XSS过滤
*
* @param {String} css 要过滤的CSS代码
* @param {Object} options 选项:whiteList, onAttr, onIgnoreAttr
* @return {String}
*/
function filterCSS (html, options) {
var xss = new FilterCSS(options);
return xss.process(html);
}
// 输出
exports = module.exports = filterCSS;
exports.FilterCSS = FilterCSS;
for (var i in DEFAULT) exports[i] = DEFAULT[i];
// 在浏览器端使用
if (typeof window !== 'undefined') {
window.filterCSS = module.exports;
}
/***/ }),
/* 19 */
/***/ (function(module, exports) {
module.exports = {
indexOf: function (arr, item) {
var i, j;
if (Array.prototype.indexOf) {
return arr.indexOf(item);
}
for (i = 0, j = arr.length; i < j; i++) {
if (arr[i] === item) {
return i;
}
}
return -1;
},
forEach: function (arr, fn, scope) {
var i, j;
if (Array.prototype.forEach) {
return arr.forEach(fn, scope);
}
for (i = 0, j = arr.length; i < j; i++) {
fn.call(scope, arr[i], i, arr);
}
},
trim: function (str) {
if (String.prototype.trim) {
return str.trim();
}
return str.replace(/(^\s*)|(\s*$)/g, "");
},
spaceIndex: function (str) {
var reg = /\s|\n|\t/;
var match = reg.exec(str);
return match ? match.index : -1;
},
};
/***/ }),
/* 20 */
/***/ (function(module, exports, __webpack_require__) {
// extracted by mini-css-extract-plugin
/***/ }),
/* 21 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony import */ var _utils_scroll_top__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(8);
/* harmony import */ var _utils_smooth_scroll__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(9);
/* harmony import */ var _components_scrollbar_index__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(10);
/* harmony import */ var _utils_constants_markup__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(4);
var _components;
/* harmony default export */ __webpack_exports__["a"] = ({
components: (_components = {}, _components[_components_scrollbar_index__WEBPACK_IMPORTED_MODULE_2__[/* default */ "a"].name] = _components_scrollbar_index__WEBPACK_IMPORTED_MODULE_2__[/* default */ "a"], _components),
props: {
tabSize: {
type: Number,
default: 2
},
scrollContainer: {
type: Function,
default: function _default() {
return window;
}
},
top: {
type: Number,
default: 0
}
},
emits: ['image-click'],
methods: {
handlePreviewClick: function handlePreviewClick(e) {
var target = e.target;
// image preview
if (target.tagName === 'IMG') {
var src = target.getAttribute('src');
if (!src) return;
var imageEls = Array.from(this.$el.querySelectorAll('img'));
var images = imageEls.map(function (el) {
return el.getAttribute('src');
}).filter(function (src) {
return src;
});
var imagePreviewInitIndex = imageEls.indexOf(target);
this.$emit('image-click', images, imagePreviewInitIndex);
return;
}
var scrollToTargetId = target.getAttribute(_utils_constants_markup__WEBPACK_IMPORTED_MODULE_3__[/* ANCHOR_MARKUP */ "a"]);
var scrollToTarget = this.$el.querySelector("[" + _utils_constants_markup__WEBPACK_IMPORTED_MODULE_3__[/* HEADING_MARKUP */ "b"] + "=\"" + scrollToTargetId + "\"]");
if (scrollToTarget) {
this.scrollToTarget({
target: scrollToTarget
});
}
},
getOffsetTop: function getOffsetTop(target, container) {
var rect = target.getBoundingClientRect();
if (container === window || container === document.documentElement) {
return rect.top;
}
return rect.top - container.getBoundingClientRect().top;
},
scrollToTarget: function scrollToTarget(_ref) {
var target = _ref.target,
_ref$scrollContainer = _ref.scrollContainer,
scrollContainer = _ref$scrollContainer === void 0 ? this.scrollContainer() : _ref$scrollContainer,
_ref$top = _ref.top,
top = _ref$top === void 0 ? this.top : _ref$top,
onScrollEnd = _ref.onScrollEnd;
var offsetTop = this.getOffsetTop(target, scrollContainer);
var scrollTop = Object(_utils_scroll_top__WEBPACK_IMPORTED_MODULE_0__[/* getScrollTop */ "a"])(scrollContainer) + offsetTop - top;
Object(_utils_smooth_scroll__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"])({
scrollTarget: scrollContainer,
scrollToTop: scrollTop,
onScrollEnd: onScrollEnd
});
},
scrollToLine: function scrollToLine(_ref2) {
var lineIndex = _ref2.lineIndex,
onScrollEnd = _ref2.onScrollEnd;
if (lineIndex) {
var target = this.$el.querySelector("[" + _utils_constants_markup__WEBPACK_IMPORTED_MODULE_3__[/* LINE_MARKUP */ "c"] + "=\"" + lineIndex + "\"]");
if (target) this.scrollToTarget({
target: target,
onScrollEnd: onScrollEnd
});
}
}
}
});
/***/ }),
/* 22 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* WEBPACK VAR INJECTION */(function(global) {/**
* A collection of shims that provide minimal functionality of the ES6 collections.
*
* These implementations are not meant to be used outside of the ResizeObserver
* modules as they cover only a limited range of use cases.
*/
/* eslint-disable require-jsdoc, valid-jsdoc */
var MapShim = (function () {
if (typeof Map !== 'undefined') {
return Map;
}
/**
* Returns index in provided array that matches the specified key.
*
* @param {Array<Array>} arr
* @param {*} key
* @returns {number}
*/
function getIndex(arr, key) {
var result = -1;
arr.some(function (entry, index) {
if (entry[0] === key) {
result = index;
return true;
}
return false;
});
return result;
}
return /** @class */ (function () {
function class_1() {
this.__entries__ = [];
}
Object.defineProperty(class_1.prototype, "size", {
/**
* @returns {boolean}
*/
get: function () {
return this.__entries__.length;
},
enumerable: true,
configurable: true
});
/**
* @param {*} key
* @returns {*}
*/
class_1.prototype.get = function (key) {
var index = getIndex(this.__entries__, key);
var entry = this.__entries__[index];
return entry && entry[1];
};
/**
* @param {*} key
* @param {*} value
* @returns {void}
*/
class_1.prototype.set = function (key, value) {
var index = getIndex(this.__entries__, key);
if (~index) {
this.__entries__[index][1] = value;
}
else {
this.__entries__.push([key, value]);
}
};
/**
* @param {*} key
* @returns {void}
*/
class_1.prototype.delete = function (key) {
var entries = this.__entries__;
var index = getIndex(entries, key);
if (~index) {
entries.splice(index, 1);
}
};
/**
* @param {*} key
* @returns {void}
*/
class_1.prototype.has = function (key) {
return !!~getIndex(this.__entries__, key);
};
/**
* @returns {void}
*/
class_1.prototype.clear = function () {
this.__entries__.splice(0);
};
/**
* @param {Function} callback
* @param {*} [ctx=null]
* @returns {void}
*/
class_1.prototype.forEach = function (callback, ctx) {
if (ctx === void 0) { ctx = null; }
for (var _i = 0, _a = this.__entries__; _i < _a.length; _i++) {
var entry = _a[_i];
callback.call(ctx, entry[1], entry[0]);
}
};
return class_1;
}());
})();
/**
* Detects whether window and document objects are available in current environment.
*/
var isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined' && window.document === document;
// Returns global object of a current environment.
var global$1 = (function () {
if (typeof global !== 'undefined' && global.Math === Math) {
return global;
}
if (typeof self !== 'undefined' && self.Math === Math) {
return self;
}
if (typeof window !== 'undefined' && window.Math === Math) {
return window;
}
// eslint-disable-next-line no-new-func
return Function('return this')();
})();
/**
* A shim for the requestAnimationFrame which falls back to the setTimeout if
* first one is not supported.
*
* @returns {number} Requests' identifier.
*/
var requestAnimationFrame$1 = (function () {
if (typeof requestAnimationFrame === 'function') {
// It's required to use a bounded function because IE sometimes throws
// an "Invalid calling object" error if rAF is invoked without the global
// object on the left hand side.
return requestAnimationFrame.bind(global$1);
}
return function (callback) { return setTimeout(function () { return callback(Date.now()); }, 1000 / 60); };
})();
// Defines minimum timeout before adding a trailing call.
var trailingTimeout = 2;
/**
* Creates a wrapper function which ensures that provided callback will be
* invoked only once during the specified delay period.
*
* @param {Function} callback - Function to be invoked after the delay period.
* @param {number} delay - Delay after which to invoke callback.
* @returns {Function}
*/
function throttle (callback, delay) {
var leadingCall = false, trailingCall = false, lastCallTime = 0;
/**
* Invokes the original callback function and schedules new invocation if
* the "proxy" was called during current request.
*
* @returns {void}
*/
function resolvePending() {
if (leadingCall) {
leadingCall = false;
callback();
}
if (trailingCall) {
proxy();
}
}
/**
* Callback invoked after the specified delay. It will further postpone
* invocation of the original function delegating it to the
* requestAnimationFrame.
*
* @returns {void}
*/
function timeoutCallback() {
requestAnimationFrame$1(resolvePending);
}
/**
* Schedules invocation of the original function.
*
* @returns {void}
*/
function proxy() {
var timeStamp = Date.now();
if (leadingCall) {
// Reject immediately following calls.
if (timeStamp - lastCallTime < trailingTimeout) {
return;
}
// Schedule new call to be in invoked when the pending one is resolved.
// This is important for "transitions" which never actually start
// immediately so there is a chance that we might miss one if change
// happens amids the pending invocation.
trailingCall = true;
}
else {
leadingCall = true;
trailingCall = false;
setTimeout(timeoutCallback, delay);
}
lastCallTime = timeStamp;
}
return proxy;
}
// Minimum delay before invoking the update of observers.