/*! * Mditor embed version 1.3.3 * Homepage: http://mditor.com */ /******/ (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] = { /******/ exports: {}, /******/ id: moduleId, /******/ loaded: false /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.loaded = 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; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(0); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var mokit = __webpack_require__(1); var Toolbar = __webpack_require__(84); var Editor = __webpack_require__(89); var Viewer = __webpack_require__(94); var Finder = __webpack_require__(97); var Shortcut = __webpack_require__(100); var Parser = __webpack_require__(102); __webpack_require__(151); __webpack_require__(158); __webpack_require__(159); __webpack_require__(160); var HIDDEN_CLASS_NAME = 'mditor-hidden'; var Mditor = new mokit.Component({ template: __webpack_require__(162), /*istanbul ignore next*/onInit: function onInit() { this.PLATFORM = navigator.platform.toLowerCase(); this.EOL = this.PLATFORM == 'win32' ? '\r\n' : '\n'; this.CMD = this.PLATFORM.indexOf('mac') > -1 ? 'command' : 'ctrl'; this.INDENT = ' '; this.shortcut = new Shortcut(this); this.Parser = Parser; this.parser = new Parser(this); }, /*istanbul ignore next*/onReady: function onReady() { /*istanbul ignore next*/var _this = this; this.shortcut.bind('tab', this.editor.addIndent.bind(this.editor)); this.shortcut.bind('shift+tab', this.editor.removeIndent.bind(this.editor)); this.shortcut.bind('enter', function (event) { /*istanbul ignore next*/_this._ulAndQuoteAutoComplete(event); /*istanbul ignore next*/_this._olAutoComplete(event); /*istanbul ignore next*/_this._keepIndent(event); }, true); setTimeout(function () { /*istanbul ignore next*/_this.$emit('ready'); }, 0); }, components: { Toolbar: Toolbar, Editor: Editor, Viewer: Viewer, Finder: Finder }, props: { height: '400px', width: 'auto', preview: false, split: true, fullscreen: false }, /*istanbul ignore next*/data: function data() { return { self: this, value: '' }; }, /*istanbul ignore next*/find: function find(text) { this.finder.show(text); }, /*istanbul ignore next*/syncScroll: function syncScroll() { if (!this.split || this.preview) return; var offsetHeight = this.editor.textarea.offsetHeight; var editorScrollHeight = this.editor.textarea.scrollHeight; var viewerScrollHeight = this.viewer.$element.scrollHeight; var editorScrollTop = this.editor.textarea.scrollTop; var viewerScrollTop = editorScrollTop * (viewerScrollHeight - offsetHeight) / (editorScrollHeight - offsetHeight); this.viewer.$element.scrollTop = viewerScrollTop; }, /*istanbul ignore next*/onChanged: function onChanged(event) { this.$emit('changed', event); this.syncScroll(); }, /*istanbul ignore next*/onInput: function onInput(event) { this.$emit('input', event); }, /*istanbul ignore next*/onPaste: function onPaste(event) { this.$emit('paste', event); this.syncScroll(); }, /*istanbul ignore next*/onHeadDblClick: function onHeadDblClick(event) { if (event.target.tagName == 'I') return; this.$emit('head-dblclick', event); }, /*istanbul ignore next*/_keepIndent: function _keepIndent(event) { var text = this.editor.getBeforeTextInLine(); var parts = text.split(this.INDENT); if (parts.length < 2) return; var count = 0; var buffer = [this.EOL]; while (parts[count] === '' && count < parts.length - 1) { count++; buffer.push(this.INDENT); } this.editor.insertBeforeText(buffer.join('')); event.preventDefault(); }, /*istanbul ignore next*/_ulAndQuoteAutoComplete: function _ulAndQuoteAutoComplete(event) { var text = this.editor.getBeforeTextInLine(); var prefix = text.substr(0, 2); if (prefix != '- ' && prefix != '* ' && prefix != '> ') return; if (text.length > prefix.length) { this.editor.insertBeforeText(this.EOL + prefix); } else { this.editor.selectBeforeText(prefix.length); this.editor.setSelectText(''); } event.preventDefault(); }, /*istanbul ignore next*/_olAutoComplete: function _olAutoComplete(event) { var exp = /^\d+\./; var text = this.editor.getBeforeTextInLine(); var trimedText = text.trim(); if (!exp.test(trimedText)) return; var num = trimedText.split('.')[0]; if (trimedText.length > num.length + 1) { this.editor.insertBeforeText(this.EOL + (parseInt(num) + 1) + '. '); } else { this.editor.selectBeforeText(text.length); this.editor.setSelectText(''); } event.preventDefault(); }, /*istanbul ignore next*/focus: function focus() { if (this.preview) { this.$element.focus(); } else { this.editor.focus(); } }, /*istanbul ignore next*/blur: function blur() { this.editor.blur(); }, /*istanbul ignore next*/addCommand: function addCommand(item) { if (!item.name || !item.handler) return; this.commands = this.commands || {}; this.commands[item.name] = item; if (item.key) { this.shortcut.bind(item.key, item.name, item.allowDefault, item.owner); } }, /*istanbul ignore next*/removeCommand: function removeCommand(name) { this.commands = this.commands || {}; var item = this.commands[name]; if (!item) return; this.shortcut.unbind(item.key); this.commands[name] = null; delete this.commands[name]; }, /*istanbul ignore next*/execCommand: function execCommand(name, event) { event = event || {}; event.mditor = this; event.toolbar = this.toolbar; event.editor = this.editor; this.commands[name].handler.call(this, event); } }); Mditor.fromTextarea = function (textarea) { textarea.classList.add(HIDDEN_CLASS_NAME); var mditor = new Mditor(); mditor.value = textarea.value; mditor.$watch('value', function () { textarea.value = mditor.value; }); mditor.$mount(textarea); mditor.switchTextarea = function () { if (textarea.classList.contains(HIDDEN_CLASS_NAME)) { textarea.value = mditor.value; mditor.$element.classList.add(HIDDEN_CLASS_NAME); textarea.classList.remove(HIDDEN_CLASS_NAME); } else { mditor.value = textarea.value; textarea.classList.add(HIDDEN_CLASS_NAME); mditor.$element.classList.remove(HIDDEN_CLASS_NAME); } }; return mditor; }; Mditor.Parser = Parser; module.exports = window.Mditor = Mditor; /***/ }), /* 1 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var info = __webpack_require__(2); var utils = __webpack_require__(3); var Class = __webpack_require__(4); var Watcher = __webpack_require__(5); var Observer = __webpack_require__(6); var Template = __webpack_require__(51); var Component = __webpack_require__(79); var EventEmitter = __webpack_require__(50); //持载模板相关对象 utils.copy(Template, Component); Component.version = info.version; Component.Template = Template; Component.Watcher = Watcher; Component.Observer = Observer; Component.EventEmitter = EventEmitter; Component.utils = utils; Component.Class = Class; //定义安装插件的方法 Component.use = function (plugin) { var install = plugin.install || plugin; if (!utils.isFunction(install)) { throw new Error('Invalid Plugin'); } return install.call(plugin, this); }; //安装内置的路由插件 //Component.use(Router); module.exports = Component; /***/ }), /* 2 */ /***/ (function(module, exports) { module.exports = {"name":"mokit","version":"3.1.3"} /***/ }), /* 3 */ /***/ (function(module, exports, __webpack_require__) { (function (ntils) { /** * 空函数 */ ntils.noop = function () { }; /** * 验证一个对象是否为NULL * @method isNull * @param {Object} obj 要验证的对象 * @return {Boolean} 结果 * @static */ ntils.isNull = function (obj) { return obj === null || typeof obj === "undefined"; }; /** * 除去字符串两端的空格 * @method trim * @param {String} str 源字符串 * @return {String} 结果字符串 * @static */ ntils.trim = function (str) { if (this.isNull(str)) return str; if (str.trim) { return str.trim(); } else { return str.replace(/(^[\\s]*)|([\\s]*$)/g, ""); } }; /** * 替换所有 * @method replace * @param {String} str 源字符串 * @param {String} str1 要替换的字符串 * @param {String} str2 替换为的字符串 * @static */ ntils.replace = function (str, str1, str2) { if (this.isNull(str)) return str; return str.replace(new RegExp(str1, 'g'), str2); }; /** * 从字符串开头匹配 * @method startWith * @param {String} str1 源字符串 * @param {String} str2 要匹配的字符串 * @return {Boolean} 匹配结果 * @static */ ntils.startWith = function (str1, str2) { if (this.isNull(str1) || this.isNull(str2)) return false; return str1.indexOf(str2) === 0; }; /** * 是否包含 * @method contains * @param {String} str1 源字符串 * @param {String} str2 检查包括字符串 * @return {Boolean} 结果 * @static */ ntils.contains = function (str1, str2) { var self = this; if (this.isNull(str1) || this.isNull(str2)) return false; return str1.indexOf(str2) > -1; }; /** * 从字符串结束匹配 * @method endWidth * @param {String} str1 源字符串 * @param {String} str2 匹配字符串 * @return {Boolean} 匹配结果 * @static */ ntils.endWith = function (str1, str2) { if (this.isNull(str1) || this.isNull(str2)) return false; return str1.indexOf(str2) === (str1.length - str2.length); }; /** * 是否包含属性 * @method hasProperty * @param {Object} obj 对象 * @param {String} name 属性名 * @return {Boolean} 结果 * @static */ ntils.has = ntils.hasProperty = function (obj, name) { if (this.isNull(obj) || this.isNull(name)) return false; return (name in obj) || (obj.hasOwnProperty(name)); }; /** * 验证一个对象是否为Function * @method isFunction * @param {Object} obj 要验证的对象 * @return {Boolean} 结果 * @static */ ntils.isFunction = function (obj) { if (this.isNull(obj)) return false; return typeof obj === "function"; }; /** * 验证一个对象是否为String * @method isString * @param {Object} obj 要验证的对象 * @return {Boolean} 结果 * @static */ ntils.isString = function (obj) { if (this.isNull(obj)) return false; return typeof obj === 'string' || obj instanceof String; }; /** * 验证一个对象是否为Number * @method isNumber * @param {Object} obj 要验证的对象 * @return {Boolean} 结果 * @static */ ntils.isNumber = function (obj) { if (this.isNull(obj)) return false; return typeof obj === 'number' || obj instanceof Number; }; /** * 验证一个对象是否为Boolean * @method isBoolean * @param {Object} obj 要验证的对象 * @return {Boolean} 结果 * @static */ ntils.isBoolean = function (obj) { if (this.isNull(obj)) return false; return typeof obj === 'boolean' || obj instanceof Boolean; }; /** * 验证一个对象是否为HTML Element * @method isElement * @param {Object} obj 要验证的对象 * @return {Boolean} 结果 * @static */ ntils.isElement = function (obj) { if (this.isNull(obj)) return false; if (window.Element) { return obj instanceof Element; } else { return (obj.tagName && obj.nodeType && obj.nodeName && obj.attributes && obj.ownerDocument); } }; /** * 验证一个对象是否为HTML Text Element * @method isText * @param {Object} obj 要验证的对象 * @return {Boolean} 结果 * @static */ ntils.isText = function (obj) { if (this.isNull(obj)) return false; return obj instanceof Text; }; /** * 验证一个对象是否为Object * @method isObject * @param {Object} obj 要验证的对象 * @return {Boolean} 结果 * @static */ ntils.isObject = function (obj) { if (this.isNull(obj)) return false; return typeof obj === "object"; }; /** * 验证一个对象是否为Array或伪Array * @method isArray * @param {Object} obj 要验证的对象 * @return {Boolean} 结果 * @static */ ntils.isArray = function (obj) { if (this.isNull(obj)) return false; var v1 = Object.prototype.toString.call(obj) === '[object Array]'; var v2 = obj instanceof Array; var v3 = !this.isString(obj) && this.isNumber(obj.length) && this.isFunction(obj.splice); var v4 = !this.isString(obj) && this.isNumber(obj.length) && obj[0]; return v1 || v2 || v3 || v4; }; /** * 验证是不是一个日期对象 * @method isDate * @param {Object} val 要检查的对象 * @return {Boolean} 结果 * @static */ ntils.isDate = function (val) { if (this.isNull(val)) return false; return val instanceof Date; }; /** * 验证是不是一个正则对象 * @method isDate * @param {Object} val 要检查的对象 * @return {Boolean} 结果 * @static */ ntils.isRegexp = function (val) { return val instanceof RegExp; }; /** * 转换为数组 * @method toArray * @param {Array|Object} array 伪数组 * @return {Array} 转换结果数组 * @static */ ntils.toArray = function (array) { if (this.isNull(array)) return []; return Array.prototype.slice.call(array); }; /** * 转为日期格式 * @method toDate * @param {Number|String} val 日期字符串或整型数值 * @return {Date} 日期对象 * @static */ ntils.toDate = function (val) { var self = this; if (self.isNumber(val)) return new Date(val); else if (self.isString(val)) return new Date(self.replace(self.replace(val, '-', '/'), 'T', ' ')); else if (self.isDate(val)) return val; else return null; }; /** * 遍历一个对像或数组 * @method each * @param {Object or Array} obj 要遍历的数组或对象 * @param {Function} fn 处理函数 * @return {void} 无返回值 * @static */ ntils.each = function (list, handler, scope) { if (this.isNull(list) || this.isNull(handler)) return; if (this.isArray(list)) { var listLength = list.length; for (var i = 0; i < listLength; i++) { var rs = handler.call(scope || list[i], i, list[i]); if (!this.isNull(rs)) return rs; } } else { for (var key in list) { var rs = handler.call(scope || list[key], key, list[key]); if (!this.isNull(rs)) return rs; } } }; /** * 格式化日期 * @method formatDate * @param {Date|String|Number} date 日期 * @param {String} format 格式化字符串 * @param {object} dict 反译字典 * @return {String} 格式化结果 * @static */ ntils.formatDate = function (date, format, dict) { if (this.isNull(format) || this.isNull(date)) return date; date = this.toDate(date); dict = dict || {}; var placeholder = { "M+": date.getMonth() + 1, //month "d+": date.getDate(), //day "h+": date.getHours(), //hour "m+": date.getMinutes(), //minute "s+": date.getSeconds(), //second "w+": date.getDay(), //week "q+": Math.floor((date.getMonth() + 3) / 3), //quarter "S": date.getMilliseconds() //millisecond } if (/(y+)/.test(format)) { format = format.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length)); } for (var key in placeholder) { if (new RegExp("(" + key + ")").test(format)) { var value = placeholder[key]; value = dict[value] || value; format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? value : ("00" + value).substr(("" + value).length)); } } return format; }; /** * 拷贝对象 * @method copy * @param {Object} src 源对象 * @param {Object} dst 目标对象 * @static */ ntils.copy = function (src, dst, igonres) { dst = dst || (this.isArray(src) ? [] : {}); this.each(src, function (key) { if (igonres && igonres.indexOf(key) > -1) return; delete dst[key]; if (Object.getOwnPropertyDescriptor) { try { Object.defineProperty(dst, key, Object.getOwnPropertyDescriptor(src, key)); } catch (ex) { dst[key] = src[key]; } } else { dst[key] = src[key]; } }) return dst; }; /** * 深度克隆对象 * @method clone * @param {Object} src 源对象 * @return {Object} 新对象 * @static */ ntils.clone = function (src, igonres) { if (this.isNull(src) || this.isString(src) || this.isNumber(src) || this.isBoolean(src) || this.isDate(src)) { return src; } var objClone = src; try { objClone = new src.constructor(); } catch (ex) { } this.each(src, function (key, value) { if (objClone[key] != value && !this.contains(igonres, key)) { if (this.isObject(value)) { objClone[key] = this.clone(value, igonres); } else { objClone[key] = value; } } }, this); ['toString', 'valueOf'].forEach(function (key) { if (this.contains(igonres, key)) return; this.defineFreezeProp(objClone, key, src[key]); }, this); return objClone; }; /** * 合并对象 * @method mix * @return 合并后的对象 * @param {Object} dst 目标对象 * @param {Object} src 源对象 * @param {Array} igonres 忽略的属性名, * @param {Number} mode 模式 */ ntils.mix = function (dst, src, igonres, mode, igonreNull) { //根据模式来判断,默认是Obj to Obj的 if (mode) { switch (mode) { case 1: // proto to proto return ntils.mix(dst.prototype, src.prototype, igonres, 0); case 2: // object to object and proto to proto ntils.mix(dst.prototype, src.prototype, igonres, 0); break; // pass through case 3: // proto to static return ntils.mix(dst, src.prototype, igonres, 0); case 4: // static to proto return ntils.mix(dst.prototype, src, igonres, 0); default: // object to object is what happens below } } //--- src = src || {}; dst = dst || (this.isArray(src) ? [] : {}); this.keys(src).forEach(function (key) { if (this.contains(igonres, key)) return; if (igonreNull && this.isNull(src[key])) return; if (this.isObject(src[key]) && (src[key].constructor == Object || src[key].constructor == Array || src[key].constructor == null)) { dst[key] = ntils.mix(dst[key], src[key], igonres, 0, igonreNull); } else { dst[key] = src[key]; } }, this); return dst; }; /** * 定义不可遍历的属性 **/ ntils.defineFreezeProp = function (obj, name, value) { try { Object.defineProperty(obj, name, { value: value, enumerable: false, configurable: true, //能不能重写定义 writable: false //能不能用「赋值」运算更改 }); } catch (err) { obj[name] = value; } }; /** * 获取所有 key */ ntils.keys = function (obj) { if (Object.keys) return Object.keys(obj); var keys = []; this.each(obj, function (key) { keys.push(key); }); return keys; }; /** * 创建一个对象 */ ntils.create = function (proto, props) { if (Object.create) return Object.create(proto, props); var Cotr = function () { }; Cotr.prototype = proto; var obj = new Cotr(); if (props) this.copy(props, obj); return obj; }; /** * 设置 proto * 在不支持 setPrototypeOf 也不支持 __proto__ 的浏览器 * 中,会采用 copy 方式 */ ntils.setPrototypeOf = function (obj, proto) { if (Object.setPrototypeOf) { return Object.setPrototypeOf(obj, proto || this.create(null)); } else { if (!('__proto__' in Object)) this.copy(proto, obj); obj.__proto__ = proto; } }; /** * 获取 proto */ ntils.getPrototypeOf = function (obj) { if (obj.__proto__) return obj.__proto__; if (Object.getPrototypeOf) return Object.getPrototypeOf(obj); if (obj.constructor) return obj.constructor.prototype; }; /** * 是否深度相等 */ ntils.deepEqual = function (a, b) { if (a === b) return true; if (!this.isObject(a) || !this.isObject(b)) return false; var aKeys = this.keys(a); var bKeys = this.keys(b); if (aKeys.length !== bKeys.length) return false; var allKeys = aKeys.concat(bKeys); var checkedMap = this.create(null); var result = true; this.each(allKeys, function (i, key) { if (checkedMap[key]) return; if (!this.deepEqual(a[key], b[key])) result = false; checkedMap[key] = true; }, this); return result; }; /** * 从一个数值循环到别一个数 * @param {number} fromNum 开始数值 * @param {Number} toNum 结束数值 * @param {Number} step 步长值 * @param {function} handler 执行函数 * @returns {void} 无返回 */ ntils.fromTo = function (fromNum, toNum, step, handler) { if (!handler) handler = [step, step = handler][0]; step = Math.abs(step || 1); if (fromNum < toNum) { for (var i = fromNum; i <= toNum; i += step) handler(i); } else { for (var i = fromNum; i >= toNum; i -= step) handler(i); } }; /** * 生成一个Guid * @method newGuid * @return {String} GUID字符串 * @static */ ntils.newGuid = function () { var S4 = function () { return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1); }; return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4()); }; /** * 对象变换 **/ ntils.map = function (list, fn) { var buffer = this.isArray(list) ? [] : {}; this.each(list, function (name, value) { buffer[name] = fn(name, value); }); return buffer; }; /** * 通过路径设置属性值 */ ntils.setByPath = function (obj, path, value) { if (this.isNull(obj) || this.isNull(path) || path === '') { return; } if (!this.isArray(path)) { path = path.replace(/\[/, '.').replace(/\]/, '.').split('.'); } this.each(path, function (index, name) { if (this.isNull(name) || name.length < 1) return; if (index === path.length - 1) { obj[name] = value; } else { obj[name] = obj[name] || {}; obj = obj[name]; } }, this); }; /** * 通过路径获取属性值 */ ntils.getByPath = function (obj, path) { if (this.isNull(obj) || this.isNull(path) || path === '') { return obj; } if (!this.isArray(path)) { path = path.replace(/\[/, '.').replace(/\]/, '.').split('.'); } this.each(path, function (index, name) { if (this.isNull(name) || name.length < 1) return; if (!this.isNull(obj)) obj = obj[name]; }, this); return obj; }; /** * 数组去重 **/ ntils.unique = function (array) { if (this.isNull(array)) return array; var newArray = []; this.each(array, function (i, value) { if (newArray.indexOf(value) > -1) return; newArray.push(value); }); return newArray; }; /** * 解析 function 的参数列表 **/ ntils.getFunctionArgumentNames = function (fn) { if (!fn) return []; var src = fn.toString(); var parts = src.split(')')[0].split('=>')[0].split('('); return (parts[1] || parts[0]).split(',').map(function (name) { return name.trim(); }).filter(function (name) { return name != 'function'; }); }; /** * 缩短字符串 */ ntils.short = function (str, maxLength) { if (!str) return str; maxLength = maxLength || 40; var strLength = str.length; var trimLength = maxLength / 2; return strLength > maxLength ? str.substr(0, trimLength) + '...' + str.substr(strLength - trimLength) : str; }; /** * 首字母大写 */ ntils.firstUpper = function (str) { if (this.isNull(str)) return; return str.substring(0, 1).toUpperCase() + str.substring(1); }; /** * 编码正则字符串 */ ntils.escapeRegExp = function (str) { return str.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); }; /** * 解析字符串为 dom * @param {string} str 字符串 * @returns {HTMLNode} 解析后的 DOM */ ntils.parseDom = function (str) { this._PDD_ = this._PDD_ || document.createElement('div'); this._PDD_.innerHTML = ntils.trim(str); var firstNode = this._PDD_.childNodes[0]; //先 clone 一份再通过 innerHTML 清空 //否则 IE9 下,清空时会导出返回的 DOM 没有子结点 if (firstNode) firstNode = firstNode.cloneNode(true); this._PDD_.innerHTML = ''; return firstNode; }; })(( false) ? (window.ntils = {}) : exports); /***/ }), /* 4 */ /***/ (function(module, exports, __webpack_require__) { const utils = __webpack_require__(3); function ClassFactory(options) { //处理 options options = options || utils.create(null); options.$name = options.$name || 'Class'; options.$extends = options.$extends || ClassFactory; options.$static = options.$static || utils.create(null); //处理父类 prototype var superPrototype = utils.isFunction(options.$extends) ? options.$extends.prototype : options.$extends; //定义新类 var Class = function () { //处理 super if (!this.$super) { utils.defineFreezeProp(this, '$super', function () { if (this._super_called_) return this._super_ret_; this._super_called_ = true; if (utils.isFunction(options.$extends)) { this._super_ret_ = options.$extends.apply(this, arguments); //这几行确保可继承于数组 if (this._super_ret_) { var proto = utils.getPrototypeOf(this); utils.setPrototypeOf(proto, this._super_ret_); } } else { this._super_ret_ = options.$extends; } return this._super_ret_; }); for (var name in superPrototype) { var value = superPrototype[name]; if (utils.isFunction(value)) { this.$super[name] = value.bind(this); } else { this.$super[name] = value; } } } //调用构造 if (utils.isFunction(options.constructor) && options.constructor !== Object) { return options.constructor.apply(this, arguments); } else { //如果没有实现 constructor 则调用父类构造 this.$super.apply(this, arguments); } }; //处理 prototype Class.prototype = utils.create(superPrototype); utils.copy(options, Class.prototype); utils.defineFreezeProp(Class.prototype, '$class', Class); //处理静态成员 utils.copy(options.$static, Class); if (utils.isFunction(options.$extends)) { utils.setPrototypeOf(Class, options.$extends); } if (!options.$extends.$extend) { utils.copy(ClassFactory, Class); } utils.defineFreezeProp(Class, '$super', options.$extends); //-- return Class; } //定义扩展方法 ClassFactory.$extend = function (options) { options.$extends = this; return new ClassFactory(options); }; ClassFactory.Class = ClassFactory; module.exports = ClassFactory; /***/ }), /* 5 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var Class = __webpack_require__(4); var utils = __webpack_require__(3); /** * Watcher 类 * 通过「计算函数」、「执行函数」可以创建一个 Watcher 实例 */ var Watcher = new Class({ /** * 通过「计算函数」、「执行函数」构建一个 Watcher 实例 * @param {function} calcor 计算函数 * @param {function} handler 处理函数 * @param {boolean} first 是否自动执行第一次 * @returns {void} 无返回 */ constructor: function /*istanbul ignore next*/constructor(calcor, handler, first) { if (!utils.isFunction(calcor) || !utils.isFunction(handler)) { throw new Error('Invalid parameters'); } this.calcor = calcor; this.handler = handler; if (first) this.calc(true); }, /** * 执行计算 * @param {boolean} force 是否强制触发「计算函数」 * @returns {Object} 计算后的值 */ calc: function /*istanbul ignore next*/calc(force) { var newValue = this.calcor(); if (force || !utils.deepEqual(newValue, this.value)) { this.handler(newValue, this.value); } this.value = utils.clone(newValue); } }); module.exports = Watcher; /***/ }), /* 6 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; /*istanbul ignore next*/var _keys = __webpack_require__(7); var _keys2 = _interopRequireDefault(_keys); var _getOwnPropertyDescriptor = __webpack_require__(42); var _getOwnPropertyDescriptor2 = _interopRequireDefault(_getOwnPropertyDescriptor); var _defineProperty = __webpack_require__(47); var _defineProperty2 = _interopRequireDefault(_defineProperty); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var Class = __webpack_require__(4); var utils = __webpack_require__(3); var EventEmitter = __webpack_require__(50); var OBSERVER_PROP_NAME = '_observer_'; var CHANGE_EVENT_NAME = 'change'; var EVENT_MAX_DISPATCH_LAYER = 10; var IGNORE_REGEXPS = [/^\_(.*)\_$/i, /^\_\_/i]; /** * 对象观察类,可以监控对象变化 * 目前方案问题: * 对于父子关系和事件冒泡,目前方案如果用 delete 删除一个属性,无关真实删除关系, * 即便调用 clearReference 也无法再清除关系,子对象的 parents 中会一直有一个引用,当前方案最高效 * 其它方法一: * 将「关系」放入全局数组中,然后将 ob.parents 变成一个「属性」从全局数组件中 filter 出来, * 基本和目前方法类似,但是关系在外部存领教,所以 clearReference 可清除。 * 其它方案二: * 构造时添加到全局数组,每一个 observer change 时都让放到全局的 observer 遍历自身的, * 检果事件源是不是自已的子对象,如果是则触发自身 change 事件,这样 ob 对象本身没有相关引用 * clearReference 时只从全局清除掉就行了,并且 delete 操作也不会影响,但效率稍差。 * 其它方案三: * 给构造函数添加一个 deep 属性,只有 deep 的 ob 对象,才放入到全局数组中,检查时逻辑同方案二 * 但是因为要检查的对象会少很多,效率会更高一点。 */ var Observer = new Class({ $extends: EventEmitter, /** * 通过目标对象构造一个观察对象 * @param {Object} target 目标对象 * @param {Object} options 选项 * @returns {void} 无返回 */ constructor: function /*istanbul ignore next*/constructor(target, options) { if (utils.isNull(target)) { throw new Error('Invalid target'); } options = options || {}; var observer = target[OBSERVER_PROP_NAME]; if (observer) { utils.copy(options, observer.options); //当时一个组件 A 的为组件 B 的 prop 时,A 更新不会触发 B 更新 //所在暂注释这里,另一种方法是更新 prop 指令,重写 excute 方法,而不是现在的 update 方法 // if (observer.options.root) { // observer.parents.length = 0; // } observer.apply(); return observer; } EventEmitter.call(this); utils.defineFreezeProp(this, 'options', options); utils.defineFreezeProp(this, 'shadow', {}); utils.defineFreezeProp(this, 'target', target); utils.defineFreezeProp(this, 'parents', []); utils.defineFreezeProp(target, OBSERVER_PROP_NAME, this); this.apply(); }, /** * 添加一个属性,动态添中的属性,无法被观察, * 但是通过 set 方法添加的属性可能被观察。 * @param {string} name 名称 * @param {Object} value 值 * @returns {void} 无返回 */ set: function /*istanbul ignore next*/set(name, value) { if (utils.isFunction(value) || Observer.isIgnore(name)) { return; } /*istanbul ignore next*/(0, _defineProperty2.default)(this.target, name, { get: function /*istanbul ignore next*/get() { return this[OBSERVER_PROP_NAME].shadow[name]; }, set: function /*istanbul ignore next*/set(value) { var observer = this[OBSERVER_PROP_NAME]; var oldValue = observer.shadow[name]; if (oldValue === value) return; if (utils.isObject(value)) { var childObserver = new Observer(value); observer.addChild(childObserver, name); } //移除旧值的父引用 //如果用 delete 删除属性将无法移除父子引用 if (oldValue && oldValue[OBSERVER_PROP_NAME]) { observer.removeChild(oldValue[OBSERVER_PROP_NAME], name); } observer.shadow[name] = value; observer.emitChange({ path: name, value: value }); }, configurable: true, enumerable: true }); this.target[name] = value; }, /** * 自动应用所有动态添加的属性 * @returns {void} 无返回 */ apply: function /*istanbul ignore next*/apply() { if (utils.isArray(this.target)) { this._wrapArray(this.target); } var names = this._getPropertyNames(this.target); names.forEach(function (name) { var desc = /*istanbul ignore next*/(0, _getOwnPropertyDescriptor2.default)(this.target, name); if (!('value' in desc)) return; this.set(name, this.target[name]); }, this); }, /** * 清除所有父子引用 * @returns {void} 无返回 */ clearReference: function /*istanbul ignore next*/clearReference() { utils.each(this.target, function (name, value) { if (utils.isNull(value)) return; var child = value[OBSERVER_PROP_NAME]; if (child) this.removeChild(child); }, this); }, /** * 派发一个事件,事件会向父级对象冒泡 * @param {string} eventName 事件名称 * @param {Object} event 事件对象 * @returns {void} 无返回 */ dispatch: function /*istanbul ignore next*/dispatch(eventName, event) { if (event._src_ === this) return; event._src_ = event._src_ || this; event._layer_ = event._layer_ || 0; if (event._layer_++ >= EVENT_MAX_DISPATCH_LAYER) return; this.emit(eventName, event); if (!this.parents || this.parents.length < 1) return; this.parents.forEach(function (item) { if (!(item.name in item.parent.target)) { return item.parent.removeChild(this); } var parentEvent = utils.copy(event); parentEvent.path = item.name + '.' + event.path; item.parent.dispatch(eventName, parentEvent); }, this); }, /** * 添子观察者对象 * @param {Object} child 父对象 * @param {String} name 属性名 * @returns {void} 无返回 */ addChild: function /*istanbul ignore next*/addChild(child, name) { if (utils.isNull(child) || utils.isNull(name)) { throw new Error('Invalid paramaters'); } if (child.options.root) return; child.parents.push({ parent: this, name: name }); }, /** * 移除子对象 * @param {Object} child 父对象 * @param {String} name 属性名 * @returns {void} 无返回 */ removeChild: function /*istanbul ignore next*/removeChild(child, name) { if (utils.isNull(child)) { throw new Error('Invalid paramaters'); } var foundIndex = -1; child.parents.forEach(function (item, index) { if (item.parent === this && item.name === name) { foundIndex = index; } }, this); if (foundIndex > -1) { child.parents.splice(foundIndex, 1); } }, /** * 触发 change 事件 * @param {Object} event 事件对象 * @returns {void} 无返回 */ emitChange: function /*istanbul ignore next*/emitChange(event) { this.dispatch(CHANGE_EVENT_NAME, event); }, /** * 获取所有成员名称列表 * @returns {Array} 所有成员名称列表 */ _getPropertyNames: function /*istanbul ignore next*/_getPropertyNames() { var names = utils.isArray(this.target) ? this.target.map(function (item, index) { return index; }) : /*istanbul ignore next*/(0, _keys2.default)(this.target); return names.filter(function (name) { return name !== OBSERVER_PROP_NAME; }); }, /** * 包裹数组 * @param {array} array 源数组 * @returns {array} 处理后的数组 */ _wrapArray: function /*istanbul ignore next*/_wrapArray(array) { utils.defineFreezeProp(array, 'push', function () { var items = [].slice.call(arguments); items.forEach(function (item) { //这里也会触发对应 index 的 change 事件 this[OBSERVER_PROP_NAME].set(array.length, item); }, this); this[OBSERVER_PROP_NAME].emitChange({ path: 'length', value: this.length }); }); utils.defineFreezeProp(array, 'pop', function () { var item = [].pop.apply(this, arguments); this[OBSERVER_PROP_NAME].emitChange({ path: this.length, value: item }); this[OBSERVER_PROP_NAME].emitChange({ path: 'length', value: this.length }); return item; }); utils.defineFreezeProp(array, 'unshift', function () { var items = [].slice.call(arguments); items.forEach(function (item) { //这里也会触发对应 index 的 change 事件 this[OBSERVER_PROP_NAME].set(0, item); }, this); this[OBSERVER_PROP_NAME].emitChange({ path: 'length', value: this.length }); }); utils.defineFreezeProp(array, 'shift', function () { var item = [].shift.apply(this, arguments); this[OBSERVER_PROP_NAME].emitChange({ path: 0, value: item }); this[OBSERVER_PROP_NAME].emitChange({ path: 'length', value: this.length }); return item; }); utils.defineFreezeProp(array, 'splice', function () { var startIndex = arguments[0]; var endIndex = utils.isNull(arguments[1]) ? startIndex + arguments[1] : this.length - 1; var items = [].splice.apply(this, arguments); for (var i = startIndex; i <= endIndex; i++) { this[OBSERVER_PROP_NAME].emitChange({ path: i, value: items[i - startIndex] }); } this[OBSERVER_PROP_NAME].emitChange({ path: 'length', value: this.length }); return items; }); utils.defineFreezeProp(array, 'set', function (index, value) { if (index >= this.length) { this[OBSERVER_PROP_NAME].emitChange({ path: 'length', value: this.length }); } this[OBSERVER_PROP_NAME].set(index, value); }); } }); /** * 观察一个对象 * @param {Object} target 目标对象 * @return {Observer} 观察者对象 */ Observer.observe = function (target) { return new Observer(target); }; /** * 检查是不是忽略的属性名 * @param {string} word 待检查的字符串 * @returns {void} 无返回 */ Observer.isIgnore = function (word) { return IGNORE_REGEXPS.some(function (re) /*istanbul ignore next*/{ return re.test(word); }); }; module.exports = Observer; /***/ }), /* 7 */ /***/ (function(module, exports, __webpack_require__) { module.exports = { "default": __webpack_require__(8), __esModule: true }; /***/ }), /* 8 */ /***/ (function(module, exports, __webpack_require__) { __webpack_require__(9); module.exports = __webpack_require__(29).Object.keys; /***/ }), /* 9 */ /***/ (function(module, exports, __webpack_require__) { // 19.1.2.14 Object.keys(O) var toObject = __webpack_require__(10); var $keys = __webpack_require__(12); __webpack_require__(27)('keys', function () { return function keys(it) { return $keys(toObject(it)); }; }); /***/ }), /* 10 */ /***/ (function(module, exports, __webpack_require__) { // 7.1.13 ToObject(argument) var defined = __webpack_require__(11); module.exports = function (it) { return Object(defined(it)); }; /***/ }), /* 11 */ /***/ (function(module, exports) { // 7.2.1 RequireObjectCoercible(argument) module.exports = function (it) { if (it == undefined) throw TypeError("Can't call method on " + it); return it; }; /***/ }), /* 12 */ /***/ (function(module, exports, __webpack_require__) { // 19.1.2.14 / 15.2.3.14 Object.keys(O) var $keys = __webpack_require__(13); var enumBugKeys = __webpack_require__(26); module.exports = Object.keys || function keys(O) { return $keys(O, enumBugKeys); }; /***/ }), /* 13 */ /***/ (function(module, exports, __webpack_require__) { var has = __webpack_require__(14); var toIObject = __webpack_require__(15); var arrayIndexOf = __webpack_require__(18)(false); var IE_PROTO = __webpack_require__(22)('IE_PROTO'); module.exports = function (object, names) { var O = toIObject(object); var i = 0; var result = []; var key; for (key in O) if (key != IE_PROTO) has(O, key) && result.push(key); // Don't enum bug & hidden keys while (names.length > i) if (has(O, key = names[i++])) { ~arrayIndexOf(result, key) || result.push(key); } return result; }; /***/ }), /* 14 */ /***/ (function(module, exports) { var hasOwnProperty = {}.hasOwnProperty; module.exports = function (it, key) { return hasOwnProperty.call(it, key); }; /***/ }), /* 15 */ /***/ (function(module, exports, __webpack_require__) { // to indexed object, toObject with fallback for non-array-like ES3 strings var IObject = __webpack_require__(16); var defined = __webpack_require__(11); module.exports = function (it) { return IObject(defined(it)); }; /***/ }), /* 16 */ /***/ (function(module, exports, __webpack_require__) { // fallback for non-array-like ES3 and non-enumerable old V8 strings var cof = __webpack_require__(17); // eslint-disable-next-line no-prototype-builtins module.exports = Object('z').propertyIsEnumerable(0) ? Object : function (it) { return cof(it) == 'String' ? it.split('') : Object(it); }; /***/ }), /* 17 */ /***/ (function(module, exports) { var toString = {}.toString; module.exports = function (it) { return toString.call(it).slice(8, -1); }; /***/ }), /* 18 */ /***/ (function(module, exports, __webpack_require__) { // false -> Array#indexOf // true -> Array#includes var toIObject = __webpack_require__(15); var toLength = __webpack_require__(19); var toAbsoluteIndex = __webpack_require__(21); module.exports = function (IS_INCLUDES) { return function ($this, el, fromIndex) { var O = toIObject($this); var length = toLength(O.length); var index = toAbsoluteIndex(fromIndex, length); var value; // Array#includes uses SameValueZero equality algorithm // eslint-disable-next-line no-self-compare if (IS_INCLUDES && el != el) while (length > index) { value = O[index++]; // eslint-disable-next-line no-self-compare if (value != value) return true; // Array#indexOf ignores holes, Array#includes - not } else for (;length > index; index++) if (IS_INCLUDES || index in O) { if (O[index] === el) return IS_INCLUDES || index || 0; } return !IS_INCLUDES && -1; }; }; /***/ }), /* 19 */ /***/ (function(module, exports, __webpack_require__) { // 7.1.15 ToLength var toInteger = __webpack_require__(20); var min = Math.min; module.exports = function (it) { return it > 0 ? min(toInteger(it), 0x1fffffffffffff) : 0; // pow(2, 53) - 1 == 9007199254740991 }; /***/ }), /* 20 */ /***/ (function(module, exports) { // 7.1.4 ToInteger var ceil = Math.ceil; var floor = Math.floor; module.exports = function (it) { return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it); }; /***/ }), /* 21 */ /***/ (function(module, exports, __webpack_require__) { var toInteger = __webpack_require__(20); var max = Math.max; var min = Math.min; module.exports = function (index, length) { index = toInteger(index); return index < 0 ? max(index + length, 0) : min(index, length); }; /***/ }), /* 22 */ /***/ (function(module, exports, __webpack_require__) { var shared = __webpack_require__(23)('keys'); var uid = __webpack_require__(25); module.exports = function (key) { return shared[key] || (shared[key] = uid(key)); }; /***/ }), /* 23 */ /***/ (function(module, exports, __webpack_require__) { var global = __webpack_require__(24); var SHARED = '__core-js_shared__'; var store = global[SHARED] || (global[SHARED] = {}); module.exports = function (key) { return store[key] || (store[key] = {}); }; /***/ }), /* 24 */ /***/ (function(module, exports) { // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028 var global = module.exports = typeof window != 'undefined' && window.Math == Math ? window : typeof self != 'undefined' && self.Math == Math ? self // eslint-disable-next-line no-new-func : Function('return this')(); if (typeof __g == 'number') __g = global; // eslint-disable-line no-undef /***/ }), /* 25 */ /***/ (function(module, exports) { var id = 0; var px = Math.random(); module.exports = function (key) { return 'Symbol('.concat(key === undefined ? '' : key, ')_', (++id + px).toString(36)); }; /***/ }), /* 26 */ /***/ (function(module, exports) { // IE 8- don't enum bug keys module.exports = ( 'constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf' ).split(','); /***/ }), /* 27 */ /***/ (function(module, exports, __webpack_require__) { // most Object methods by ES6 should accept primitives var $export = __webpack_require__(28); var core = __webpack_require__(29); var fails = __webpack_require__(38); module.exports = function (KEY, exec) { var fn = (core.Object || {})[KEY] || Object[KEY]; var exp = {}; exp[KEY] = exec(fn); $export($export.S + $export.F * fails(function () { fn(1); }), 'Object', exp); }; /***/ }), /* 28 */ /***/ (function(module, exports, __webpack_require__) { var global = __webpack_require__(24); var core = __webpack_require__(29); var ctx = __webpack_require__(30); var hide = __webpack_require__(32); var PROTOTYPE = 'prototype'; var $export = function (type, name, source) { var IS_FORCED = type & $export.F; var IS_GLOBAL = type & $export.G; var IS_STATIC = type & $export.S; var IS_PROTO = type & $export.P; var IS_BIND = type & $export.B; var IS_WRAP = type & $export.W; var exports = IS_GLOBAL ? core : core[name] || (core[name] = {}); var expProto = exports[PROTOTYPE]; var target = IS_GLOBAL ? global : IS_STATIC ? global[name] : (global[name] || {})[PROTOTYPE]; var key, own, out; if (IS_GLOBAL) source = name; for (key in source) { // contains in native own = !IS_FORCED && target && target[key] !== undefined; if (own && key in exports) continue; // export native or passed out = own ? target[key] : source[key]; // prevent global pollution for namespaces exports[key] = IS_GLOBAL && typeof target[key] != 'function' ? source[key] // bind timers to global for call from export context : IS_BIND && own ? ctx(out, global) // wrap global constructors for prevent change them in library : IS_WRAP && target[key] == out ? (function (C) { var F = function (a, b, c) { if (this instanceof C) { switch (arguments.length) { case 0: return new C(); case 1: return new C(a); case 2: return new C(a, b); } return new C(a, b, c); } return C.apply(this, arguments); }; F[PROTOTYPE] = C[PROTOTYPE]; return F; // make static versions for prototype methods })(out) : IS_PROTO && typeof out == 'function' ? ctx(Function.call, out) : out; // export proto methods to core.%CONSTRUCTOR%.methods.%NAME% if (IS_PROTO) { (exports.virtual || (exports.virtual = {}))[key] = out; // export proto methods to core.%CONSTRUCTOR%.prototype.%NAME% if (type & $export.R && expProto && !expProto[key]) hide(expProto, key, out); } } }; // type bitmap $export.F = 1; // forced $export.G = 2; // global $export.S = 4; // static $export.P = 8; // proto $export.B = 16; // bind $export.W = 32; // wrap $export.U = 64; // safe $export.R = 128; // real proto method for `library` module.exports = $export; /***/ }), /* 29 */ /***/ (function(module, exports) { var core = module.exports = { version: '2.5.1' }; if (typeof __e == 'number') __e = core; // eslint-disable-line no-undef /***/ }), /* 30 */ /***/ (function(module, exports, __webpack_require__) { // optional / simple context binding var aFunction = __webpack_require__(31); module.exports = function (fn, that, length) { aFunction(fn); if (that === undefined) return fn; switch (length) { case 1: return function (a) { return fn.call(that, a); }; case 2: return function (a, b) { return fn.call(that, a, b); }; case 3: return function (a, b, c) { return fn.call(that, a, b, c); }; } return function (/* ...args */) { return fn.apply(that, arguments); }; }; /***/ }), /* 31 */ /***/ (function(module, exports) { module.exports = function (it) { if (typeof it != 'function') throw TypeError(it + ' is not a function!'); return it; }; /***/ }), /* 32 */ /***/ (function(module, exports, __webpack_require__) { var dP = __webpack_require__(33); var createDesc = __webpack_require__(41); module.exports = __webpack_require__(37) ? function (object, key, value) { return dP.f(object, key, createDesc(1, value)); } : function (object, key, value) { object[key] = value; return object; }; /***/ }), /* 33 */ /***/ (function(module, exports, __webpack_require__) { var anObject = __webpack_require__(34); var IE8_DOM_DEFINE = __webpack_require__(36); var toPrimitive = __webpack_require__(40); var dP = Object.defineProperty; exports.f = __webpack_require__(37) ? Object.defineProperty : function defineProperty(O, P, Attributes) { anObject(O); P = toPrimitive(P, true); anObject(Attributes); if (IE8_DOM_DEFINE) try { return dP(O, P, Attributes); } catch (e) { /* empty */ } if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported!'); if ('value' in Attributes) O[P] = Attributes.value; return O; }; /***/ }), /* 34 */ /***/ (function(module, exports, __webpack_require__) { var isObject = __webpack_require__(35); module.exports = function (it) { if (!isObject(it)) throw TypeError(it + ' is not an object!'); return it; }; /***/ }), /* 35 */ /***/ (function(module, exports) { module.exports = function (it) { return typeof it === 'object' ? it !== null : typeof it === 'function'; }; /***/ }), /* 36 */ /***/ (function(module, exports, __webpack_require__) { module.exports = !__webpack_require__(37) && !__webpack_require__(38)(function () { return Object.defineProperty(__webpack_require__(39)('div'), 'a', { get: function () { return 7; } }).a != 7; }); /***/ }), /* 37 */ /***/ (function(module, exports, __webpack_require__) { // Thank's IE8 for his funny defineProperty module.exports = !__webpack_require__(38)(function () { return Object.defineProperty({}, 'a', { get: function () { return 7; } }).a != 7; }); /***/ }), /* 38 */ /***/ (function(module, exports) { module.exports = function (exec) { try { return !!exec(); } catch (e) { return true; } }; /***/ }), /* 39 */ /***/ (function(module, exports, __webpack_require__) { var isObject = __webpack_require__(35); var document = __webpack_require__(24).document; // typeof document.createElement is 'object' in old IE var is = isObject(document) && isObject(document.createElement); module.exports = function (it) { return is ? document.createElement(it) : {}; }; /***/ }), /* 40 */ /***/ (function(module, exports, __webpack_require__) { // 7.1.1 ToPrimitive(input [, PreferredType]) var isObject = __webpack_require__(35); // instead of the ES6 spec version, we didn't implement @@toPrimitive case // and the second argument - flag - preferred type is a string module.exports = function (it, S) { if (!isObject(it)) return it; var fn, val; if (S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it))) return val; if (typeof (fn = it.valueOf) == 'function' && !isObject(val = fn.call(it))) return val; if (!S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it))) return val; throw TypeError("Can't convert object to primitive value"); }; /***/ }), /* 41 */ /***/ (function(module, exports) { module.exports = function (bitmap, value) { return { enumerable: !(bitmap & 1), configurable: !(bitmap & 2), writable: !(bitmap & 4), value: value }; }; /***/ }), /* 42 */ /***/ (function(module, exports, __webpack_require__) { module.exports = { "default": __webpack_require__(43), __esModule: true }; /***/ }), /* 43 */ /***/ (function(module, exports, __webpack_require__) { __webpack_require__(44); var $Object = __webpack_require__(29).Object; module.exports = function getOwnPropertyDescriptor(it, key) { return $Object.getOwnPropertyDescriptor(it, key); }; /***/ }), /* 44 */ /***/ (function(module, exports, __webpack_require__) { // 19.1.2.6 Object.getOwnPropertyDescriptor(O, P) var toIObject = __webpack_require__(15); var $getOwnPropertyDescriptor = __webpack_require__(45).f; __webpack_require__(27)('getOwnPropertyDescriptor', function () { return function getOwnPropertyDescriptor(it, key) { return $getOwnPropertyDescriptor(toIObject(it), key); }; }); /***/ }), /* 45 */ /***/ (function(module, exports, __webpack_require__) { var pIE = __webpack_require__(46); var createDesc = __webpack_require__(41); var toIObject = __webpack_require__(15); var toPrimitive = __webpack_require__(40); var has = __webpack_require__(14); var IE8_DOM_DEFINE = __webpack_require__(36); var gOPD = Object.getOwnPropertyDescriptor; exports.f = __webpack_require__(37) ? gOPD : function getOwnPropertyDescriptor(O, P) { O = toIObject(O); P = toPrimitive(P, true); if (IE8_DOM_DEFINE) try { return gOPD(O, P); } catch (e) { /* empty */ } if (has(O, P)) return createDesc(!pIE.f.call(O, P), O[P]); }; /***/ }), /* 46 */ /***/ (function(module, exports) { exports.f = {}.propertyIsEnumerable; /***/ }), /* 47 */ /***/ (function(module, exports, __webpack_require__) { module.exports = { "default": __webpack_require__(48), __esModule: true }; /***/ }), /* 48 */ /***/ (function(module, exports, __webpack_require__) { __webpack_require__(49); var $Object = __webpack_require__(29).Object; module.exports = function defineProperty(it, key, desc) { return $Object.defineProperty(it, key, desc); }; /***/ }), /* 49 */ /***/ (function(module, exports, __webpack_require__) { var $export = __webpack_require__(28); // 19.1.2.4 / 15.2.3.6 Object.defineProperty(O, P, Attributes) $export($export.S + $export.F * !__webpack_require__(37), 'Object', { defineProperty: __webpack_require__(33).f }); /***/ }), /* 50 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var utils = __webpack_require__(3); var Class = __webpack_require__(4); /** * 事件触发器基类 */ var EventEmitter = new Class({ $extends: Function, /** * 构建一个一个事修的触发器对象 * @param {object} target 将代理的目标对象可以省略 * @returns {void} 无返回 */ constructor: function /*istanbul ignore next*/constructor(target) { target = target || this; var emitter = target._emitter_; if (emitter) return emitter; utils.defineFreezeProp(this, '_target_', target); utils.defineFreezeProp(target, '_emitter_', this); this._isNative_ = this._isNativeObject(this._target_); this._listeners_ = this._listeners_ || {}; this.on = this.$on = this.$addListener = this.addListener; this.off = this.$off = this.$removeListener = this.removeListener; this.$emit = this.emit; }, /** * 检查是否原生支持事件 * @param {object} obj 对象 * @returns {void} 检查结果 */ _isNativeObject: function /*istanbul ignore next*/_isNativeObject(obj) { return obj.addEventListener && obj.removeEventListener && obj.dispatchEvent; }, /** * 添加一个事件监听函数 * @param {string} name 事件名称 * @param {function} listener 事件处理函数 * @param {capture} capture 是否是捕获阶段事件(只在代理 dom 对象时有效) * @returns {void} 无返回 */ addListener: function /*istanbul ignore next*/addListener(name, listener, capture) { if (this._isNative_) { this._addNativeEventListener(name, listener, capture); } this._listeners_[name] = this._listeners_[name] || []; this._listeners_[name].push(listener); if (this._listeners_[name].length > EventEmitter._maxListeners) { throw new Error('The `' + name + '` event listener is not more than 10'); } }, /** * 移除「一个/一组/所有」事件监听函数 * @param {string} name 事件名称 * @param {function} listener 事件处理函数 * @param {capture} capture 是否是捕获阶段事件(只在代理 dom 对象时有效) * @returns {void} 无返回 */ removeListener: function /*istanbul ignore next*/removeListener(name, listener, capture) { if (name && listener) { if (this._isNative_) { this._removeNativeEventListener(name, listener, capture); } if (!this._listeners_[name]) return; var index = this._listeners_[name].indexOf(listener); this._listeners_[name].splice(index, 1); } else if (name) { if (this._isNative_ && this._listeners_[name]) { this._listeners_[name].forEach(function (_listener) { this.removeListener(name, _listener, capture); }, this); } delete this._listeners_[name]; } else { utils.each(this._listeners_, function (name) { this.removeListener(name, null, capture); }, this); this._listeners_ = {}; } }, /** * 触发自身的一个事件 * @param {string} name 事件名称 * @param {object} data 传递的对象 * @param {string} canBubble 能否冒泡(只在代理 dom 对象时有效) * @param {object} cancelAble 能否取消(只在代理 dom 对象时有效) * @returns {void} 无返回 */ emit: function /*istanbul ignore next*/emit(name, data, canBubble, cancelAble) { if (this._isNative_) { return this._emitNativeEvent(name, data, canBubble, cancelAble); } if (!this._listeners_[name]) return; var stopPropagation = false; this._listeners_[name].forEach(function (handler) { var rs = handler.call(this._target_, data); if (rs === false) stopPropagation = true; }, this); return stopPropagation; }, /** * 添加 DOM 元素事件 * @param {string} name 事件名称 * @param {function} listener 事件处理函数 * @param {capture} capture 是否是捕获阶段事件 * @returns {void} 无返回 */ _addNativeEventListener: function /*istanbul ignore next*/_addNativeEventListener(name, listener, capture) { this._target_.addEventListener(name, listener, capture); //如果存在已注册的自定义 “组合事件” var descriptor = EventEmitter._events[name]; if (descriptor) { descriptor.addListener = descriptor.addListener || descriptor.on; descriptor.addListener(this, name, listener, capture); } }, /** * 移除 DOM 元素事件 * @param {string} name 事件名称 * @param {function} listener 事件处理函数 * @param {capture} capture 是否是捕获阶段事件 * @returns {void} 无返回 */ _removeNativeEventListener: function /*istanbul ignore next*/_removeNativeEventListener(name, listener, capture) { this._target_.removeEventListener(name, listener, capture); //如果存在已注册的自定义 “组合事件” var descriptor = EventEmitter._events[name]; if (descriptor) { descriptor.removeListener = descriptor.removeListener || descriptor.off; descriptor.removeListener(this, name, listener, capture); } }, /** * 触发 DOM 元素事件 * @param {string} name 事件名称 * @param {object} data 传递的对象 * @param {string} canBubble 能否冒泡 * @param {object} cancelAble 能否取消 * @returns {void} 无返回 */ _emitNativeEvent: function /*istanbul ignore next*/_emitNativeEvent(name, data, canBubble, cancelAble) { var event = document.createEvent('HTMLEvents'); event.initEvent(name, canBubble, cancelAble); utils.copy(data, event, ['data']); event.data = data; return this._target_.dispatchEvent(event); } }); //最多添加多少个 listener EventEmitter._maxListeners = 10; //所有自定义事件 EventEmitter._events = []; /** * 注册自定义事件(只在代理 dom 对象时有效) * @param {object} descriptor 事件定义 * @returns {void} 无返回 */ EventEmitter.register = function (descriptor) { var names = descriptor.name; if (!names) return; if (!utils.isArray(names)) names = names.split(','); names.forEach(function (name) { this._events[name] = descriptor; }, this); }; module.exports = EventEmitter; /***/ }), /* 51 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var Compiler = __webpack_require__(52); var Directive = __webpack_require__(53); var Expression = __webpack_require__(54); var Template = __webpack_require__(78); var directives = __webpack_require__(55); Template.Template = Template; Template.Compiler = Compiler; Template.Directive = Directive; Template.directives = directives; Template.Expression = Expression; module.exports = Template; /***/ }), /* 52 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var Class = __webpack_require__(4); var Directive = __webpack_require__(53); var utils = __webpack_require__(3); var Expression = __webpack_require__(54); var commonDirectives = __webpack_require__(55); var DEFAULT_PREFIX = 'm'; /** * 模板编译器 * 可以通过指定「前缀」或「指令集」构建实例 */ var Compiler = new Class({ /** * 构造一个编译器 * @param {Object} options 选项 * @returns {void} 无返回 */ constructor: function /*istanbul ignore next*/constructor(options) { options = options || {}; this.prefix = options.prefix || DEFAULT_PREFIX; this.elementDirectives = {}; this.attributeDirectives = {}; this.registerDirectives(commonDirectives); this.registerDirectives(options.directives); }, /** * 将字符串转成「驼峰」式 * @param {string} str 原始字符串 * @param {number} mode 1 大驼峰,0 小驼峰 * @return {string} 转换后的字符串 */ toCamelCase: function /*istanbul ignore next*/toCamelCase(str, mode) { if (str) { str = str.replace(/\-[a-z0-9]/g, function ($1) /*istanbul ignore next*/{ return $1.slice(1).toUpperCase(); }); str = str.replace(/^[a-z]/i, function ($1) { return mode ? $1.toUpperCase() : $1.toLowerCase(); }); } return str; }, /** * 将字符串转成分隔形式 * @param {string} str 原始字符串 * @return {string} 转换后的字符串 */ toSplitCase: function /*istanbul ignore next*/toSplitCase(str) { if (str) { str = str.replace(/([A-Z])/g, '-$1'); if (str[0] == '-') str = str.slice(1); } return str; }, /** * 添加指令 * @param {Object} directives 指令集 * @returns {void} 无返回 */ registerDirectives: function /*istanbul ignore next*/registerDirectives(directives) { utils.each(directives, function (name, directive) { name = this.toSplitCase(name); var fullName = directive.options.prefix === false ? name : /*istanbul ignore next*/this.prefix + ':' + name; if (directive.options.type == Directive.TE) { this.elementDirectives[fullName.toUpperCase()] = directive; } else { this.attributeDirectives[fullName.toLowerCase()] = directive; } }, this); }, /** * 解析要 attr 指令信息 * @param {string} attrName 要解析的名称字符串 * @returns {Object} 解析后的对象 */ _parseAttrInfo: function /*istanbul ignore next*/_parseAttrInfo(attrName) { /*istanbul ignore next*/var _this = this; var parts = attrName.toLowerCase().split(':'); var info = {}; if (parts.length > 1) { info.name = /*istanbul ignore next*/parts[0] + ':' + parts[1]; info.decorates = parts.slice(2).map(function (item) /*istanbul ignore next*/{ return (/*istanbul ignore next*/_this.toCamelCase(item) ); }); } else { info.name = parts[0]; info.decorates = []; } return info; }, /** * 创建一个指令实例 * @param {Directive} Directive 指令类 * @param {Object} options 指令构建选项 * @returns {Directive} 指令实例 */ _createDirectiveInstance: function /*istanbul ignore next*/_createDirectiveInstance(Directive, options) { options.compiler = this; options.prefix = this.prefix; return new Directive(options); }, /** * 初始化一个编译完成的 handler * @param {function} handler 编译后的的模板函数 * @returns {void} 无返回 */ _bindHandler: function /*istanbul ignore next*/_bindHandler(handler) { //排序 directives handler.directives = handler.directives.sort(function (a, b) { return b.level - a.level; }); //初始化 directives var boundDirectives = []; utils.each(handler.directives, function (index, directive) { directive.index = index; directive.bind(); boundDirectives.push(directive); //移除完成绑定的指令对应的 attribute if (directive.remove !== false && directive.attribute) { directive.node.removeAttribute(directive.attribute.name); } //如果遇到一个「终态」指令,停止向下初始化 if (directive.final) { return handler.final = true; } }, this); handler.directives = boundDirectives; }, /** * 编译一个元素本身 * @param {function} handler 当前模板函数 * @param {HTMLNode} node 当前 HTML 结点 * @returns {void} 无返回 */ _compileElement: function /*istanbul ignore next*/_compileElement(handler, node) { var ElementDirective = this.elementDirectives[node.nodeName.toUpperCase()]; if (!ElementDirective) return; handler.directives.push(this._createDirectiveInstance(ElementDirective, { handler: handler, node: node })); }, /** * 编译一个元素所有 attributes * @param {function} handler 当前模板函数 * @param {HTMLNode} node 当前 HTML 结点 * @returns {void} 无返回 */ _compileAttributes: function /*istanbul ignore next*/_compileAttributes(handler, node) { utils.toArray(node.attributes).forEach(function (attribute) { var attrInfo = this._parseAttrInfo(attribute.name); var AttrDirective = this.attributeDirectives[attrInfo.name] || this.attributeDirectives['*']; if (!AttrDirective) return; var directiveOptions = AttrDirective.options; handler.directives.push(this._createDirectiveInstance(AttrDirective, { handler: handler, node: node, attribute: attribute, expression: directiveOptions.literal ? attribute.value : new Expression(attribute.value, directiveOptions.mixed), decorates: attrInfo.decorates })); }, this); }, /** * 编译所有子结点 * @param {function} handler 当前模板函数 * @param {HTMLNode} node 当前 HTML 结点 * @returns {void} 无返回 */ _compileChildren: function /*istanbul ignore next*/_compileChildren(handler, node) { if (handler.final) return; utils.toArray(node.childNodes).forEach(function (childNode) { if (childNode._compiled_) return; var childHandler = this.compile(childNode); childHandler.parent = this; handler.children.push(childHandler); }, this); }, /** * 编译一个模板 * @param {HTMLNode} node 模板根元素 * @param {Object} options 选项 * @returns {function} 模板函数 */ compile: function /*istanbul ignore next*/compile(node, options) { if (!node) { throw new Error('Invalid node for compile'); } node._compiled_ = true; options = options || {}; //定义编译结果函数 var handler = function handler(scope) { if (utils.isNull(scope)) scope = {}; handler.directives.forEach(function (directive) { directive.scope = scope; directive.execute(scope); }, this); handler.children.forEach(function (childHandler) { childHandler(scope); }, this); }; //-- handler.dispose = function () { handler.directives.forEach(function (directive) { directive.unbind(); }, this); handler.children.forEach(function (childHandler) { childHandler.dispose(); }, this); }; handler.node = node; //定义 children & directives handler.directives = []; handler.children = []; //编译相关指令 if (options.element !== false) this._compileElement(handler, node); if (options.attribute !== false) this._compileAttributes(handler, node); this._bindHandler(handler); if (options.children !== false) this._compileChildren(handler, node); //返回编译后函数 return handler; } }); module.exports = Compiler; /***/ }), /* 53 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var Class = __webpack_require__(4); var utils = __webpack_require__(3); var Expression = __webpack_require__(54); /** * 指令定义工场函数 * @param {Object} classOptions 选项 * @returns {Directive} 指令类 */ function Directive(classOptions) { //处理指令选项 classOptions = classOptions || {}; classOptions.type = classOptions.type || Directive.TA; classOptions.level = classOptions.level || Directive.LG; //生成指令类 var DirectiveClass = new Class({ $extends: classOptions, //指令构建函数 constructor: function /*istanbul ignore next*/constructor(instanceOptions) { utils.copy(instanceOptions, this); }, //挂载实例上的 options options: classOptions, //挂载实例核心方法 bind: classOptions.bind || utils.noop, execute: classOptions.execute || function (scope) { this.scope = scope; if (this.options.type === Directive.TE) { return this.update(); } var newValue = this.options.literal ? this.attribute.value : this.expression.execute(scope); if (!utils.deepEqual(this._value_, newValue)) { this.update(newValue, this._value_); this._value_ = newValue; } }, update: classOptions.update || utils.noop, unbind: classOptions.unbind || utils.noop, //挂载指令常用的类型 utils: utils, Expression: Expression }); //向指令类添加「指令定义信息」 DirectiveClass.options = classOptions; utils.setPrototypeOf(DirectiveClass, classOptions); return DirectiveClass; } //指令类型 Directive.TA = 'A'; Directive.TE = 'E'; //指令级别 Directive.LP = 3000; //prevent Directive.LS = 2000; //statement Directive.LE = 1000; //eleemtn Directive.LG = 0; //general Directive.LA = -1000; //any attribute Directive.LC = -2000; //cloak module.exports = Directive; /***/ }), /* 54 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var Class = __webpack_require__(4); var utils = __webpack_require__(3); /** * 表达式类型,将字符串构析为可执行表达式实例 */ var Expression = new Class({ /** * 通过字符串构造一个表达式实例 * @param {string} code 代码字符串 * @param {boolean} mix 是否是混合代码 * @returns {void} 无返回 */ constructor: function /*istanbul ignore next*/constructor(code, mix) { this.func = mix ? this._compileMixedCode(code) : this._compileCode(code); }, /** * 编译普通表达式代码 * @param {string} code 代码字符串 * @returns {function} 编辑后的函数 */ _compileCode: function /*istanbul ignore next*/_compileCode(code) { code = this._escapeEOL(this._wrapCode(code)); return this._createFunction(code); }, /** * 编辑混合的表达式代码 * @param {string} code 代码字符串 * @returns {function} 编辑后的函数 */ _compileMixedCode: function /*istanbul ignore next*/_compileMixedCode(code) { var statements = this._parseMixedCode(code); code = this._escapeEOL(statements.join('+')); return this._createFunction(code); }, /** * 通过符串代码创建一个可执行函数 * @param {string} code 代码字符串 * @returns {function} 创建的函数 */ _createFunction: function /*istanbul ignore next*/_createFunction(code) { var func = new Function('utils', 'scope', 'with(scope){return ' + code + '}'); return func.bind(null, utils); }, /** * 解析混合代码字符串 * @param {string} code 混合代码字符串 * @returns {Array} 解析后的「token」列表 */ _parseMixedCode: function /*istanbul ignore next*/_parseMixedCode(code) { var index = 0, length = code.length; var token = '', isExpr = false, tokens = []; while (index <= length) { var char = code[index++]; var nextChar = code[index]; if (utils.isNull(char)) { if (token.length > 0) { tokens.push('"' + this._escapeCode(token) + '"'); } token = ''; isExpr = false; } else if (!isExpr && char + nextChar == '{{') { if (token.length > 0) { tokens.push('"' + this._escapeCode(token) + '"'); } token = ''; isExpr = true; index++; } else if (isExpr && char + nextChar == '}}') { if (token.length > 0) { tokens.push(this._wrapCode(token)); } token = ''; isExpr = false; index++; } else { token += char; } } return tokens; }, /** * 转义处理代码字符串 * @param {string} code 源字符串 * @returns {string} 处理后的字符串 */ _escapeCode: function /*istanbul ignore next*/_escapeCode(code) { return code.replace(/"/, '\\"').replace('\r\n', '\\r\\n').replace('\n', '\\n'); }, /** * 转义换行符 * @param {string} code 源字符串 * @returns {string} 处理后的字符串 */ _escapeEOL: function /*istanbul ignore next*/_escapeEOL(code) { return code.replace(/\n/gm, '\\\n'); }, /** * 通过闭包和 try/cache 包裹代码 * 将模板中错误的代码直接显示在「模板中用到的位置」,更易于定位错误。 * @param {string} code 源字符串 * @returns {string} 处理后的字符串 */ _wrapCode: function /*istanbul ignore next*/_wrapCode(code) { return '((function(){try{return (' + code + ')}catch(err){console.error(err);return err;}})())'; }, /** * 通过 scope 对象执行表达式 * @param {Object} scope 上下文对象 * @returns {Object} 执行结果 */ execute: function /*istanbul ignore next*/execute(scope) { if (utils.isNull(scope)) { scope = {}; } return this.func.call(scope, scope); } }); module.exports = Expression; /***/ }), /* 55 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; module.exports = { '#text': __webpack_require__(56), 'each': __webpack_require__(57), 'if': __webpack_require__(59), 'prop': __webpack_require__(60), 'attr': __webpack_require__(61), 'on': __webpack_require__(62), 'html': __webpack_require__(63), 'text': __webpack_require__(64), 'prevent': __webpack_require__(65), 'id': __webpack_require__(66), 'cloak': __webpack_require__(67), 'show': __webpack_require__(68), 'model': __webpack_require__(69), 'focus': __webpack_require__(76), '*': __webpack_require__(77) //处理所有未知 attr }; /***/ }), /* 56 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var Directive = __webpack_require__(53); var Expression = __webpack_require__(54); module.exports = new Directive({ type: Directive.TE, prefix: false, /** * 初始化指令 * @returns {void} 无返回 */ bind: function /*istanbul ignore next*/bind() { this.expr = new Expression(this.node.nodeValue, true); this.node.nodeValue = ''; }, execute: function /*istanbul ignore next*/execute(scope) { this.scope = scope; var newValue = this.expr.execute(scope); if (this.node.nodeValue !== newValue) { this.node.nodeValue = newValue; } } }); /***/ }), /* 57 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; /*istanbul ignore next*/var _defineProperty = __webpack_require__(47); var _defineProperty2 = _interopRequireDefault(_defineProperty); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var Directive = __webpack_require__(53); var utils = __webpack_require__(3); var Scope = __webpack_require__(58); module.exports = new Directive({ level: Directive.LS + 1, //比 if 要高一个权重 final: true, literal: true, /** * 初始化指令 * @returns {void} 无返回 */ bind: function /*istanbul ignore next*/bind() { this.mountNode = document.createTextNode(''); this.node.parentNode.insertBefore(this.mountNode, this.node); //虽然,bind 完成后,也会进行 attribute 的移除, //但 each 指令必须先移除,否再进行 item 编译时 each 还会生效 this.node.removeAttribute(this.attribute.name); this.node.parentNode.removeChild(this.node); this.parseExpr(); this.eachItems = {}; }, parseExpr: function /*istanbul ignore next*/parseExpr() { this.eachType = this.attribute.value.indexOf(' in ') > -1 ? 'in' : 'of'; var tokens = this.attribute.value.split(' ' + this.eachType + ' '); var fnText = /*istanbul ignore next*/'with(scope){utils.each(' + tokens[1] + ',fn.bind(this,' + tokens[1] + '))}'; this.each = new Function('utils', 'scope', 'fn', fnText).bind(null, this.utils); var names = tokens[0].split(',').map(function (name) { return name.trim(); }); if (this.eachType == 'in') { this.keyName = names[0]; this.valueName = names[1]; } else { this.keyName = names[1]; this.valueName = names[0]; } }, execute: function /*istanbul ignore next*/execute(scope) { /*istanbul ignore next*/var _this = this; var currentEachKeys = []; var itemsFragment = document.createDocumentFragment(); var self = this; this.each(scope, function (eachTarget, key) { //创建新 scope,必须选创建再设置 prototype 或采用定义「属性」的方式 //因为指令参数指定的名称有可能和 scope 原有变量冲突 //将导致针对 watch 变量的赋值,从引用发循环 var newScope = new Scope(this.scope); if (self.keyName) { /*istanbul ignore next*/(0, _defineProperty2.default)(newScope, self.keyName, { /*istanbul ignore next*/get: function get() { return key; } }); } //value 采用「属性」进行代理,否则将会使「双向」绑定无把回设值 if (self.valueName) { /*istanbul ignore next*/(0, _defineProperty2.default)(newScope, self.valueName, { /*istanbul ignore next*/get: function get() { return eachTarget[key]; }, /*istanbul ignore next*/set: function set(value) { eachTarget[key] = value; } }); } var oldItem = this.eachItems[key]; if (oldItem) { oldItem.handler(newScope); } else { var newItem = {}; //创建新元素 newItem.node = this.node.cloneNode(true); itemsFragment.appendChild(newItem.node); newItem.handler = this.compiler.compile(newItem.node); newItem.handler(newScope); this.eachItems[key] = newItem; } currentEachKeys.push(key); }.bind(this)); utils.each(this.eachItems, function (key, item) { if (currentEachKeys.some(function (k) /*istanbul ignore next*/{ return k == key; })) return; if (item.node.parentNode) { item.node.parentNode.removeChild(item.node); } delete /*istanbul ignore next*/_this.eachItems[key]; }, this); if (itemsFragment.childNodes.length > 0) { this.mountNode.parentNode.insertBefore(itemsFragment, this.mountNode); } } }); /***/ }), /* 58 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var utils = __webpack_require__(3); var Scope = function Scope(parent, props) { //新的 scope 因为「继承」了 _observer_ //所以在新 scope 上进行双向绑定时,将将值成功回写 //如果有天不须用 utils.cteate 继承法,需要注意 _observer_ //或在新 scope 上 defineProperty 代理 parentScope var scope = utils.create(parent); utils.copy(props, scope); //将 func 绑定到原 scope 上; utils.each(parent, function (key, value) { if (!utils.isFunction(value)) return; scope[key] = value.bind(parent); }); return scope; }; module.exports = Scope; /***/ }), /* 59 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var Directive = __webpack_require__(53); module.exports = new Directive({ level: Directive.LS, final: true, /** * 初始化指令 * @returns {void} 无返回 */ bind: function /*istanbul ignore next*/bind() { this.mountNode = document.createTextNode(''); this.node.parentNode.insertBefore(this.mountNode, this.node); //虽然,bind 完成后,也会进行 attribute 的移除, //但 if 指令必须先移除,否再进行 item 编译时 if 还会生效 this.node.removeAttribute(this.attribute.name); this.node.parentNode.removeChild(this.node); }, execute: function /*istanbul ignore next*/execute(scope) { var newValue = this.expression.execute(scope); if (newValue) { //如果新计算的结果为 true 才执行 this._handler = this._handler || this.compiler.compile(this.node); this._handler(scope); var node = this.node.$substitute || this.node; if (!node.parentNode) { this.mountNode.parentNode.insertBefore(node, this.mountNode); } } else { var _node = this.node.$substitute || this.node; if (_node.parentNode) _node.parentNode.removeChild(_node); } } }); /***/ }), /* 60 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var Directive = __webpack_require__(53); module.exports = new Directive({ update: function /*istanbul ignore next*/update(value) { var target = this.node.$target || this.node; target[this.decorates[0]] = value; } // execute: function (scope) { // this.scope = scope; // let newValue = this.expression.execute(scope); // let target = this.node.$target || this.node; // target[this.decorates[0]] = newValue; // } }); /***/ }), /* 61 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var Directive = __webpack_require__(53); module.exports = new Directive({ update: function /*istanbul ignore next*/update(value) { var target = this.node.$target || this.node; if (target.setAttribute) { target.setAttribute(this.decorates[0], value); } else { target[this.decorates[0]] = value; } } }); /***/ }), /* 62 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var Directive = __webpack_require__(53); var EventEmitter = __webpack_require__(50); var Scope = __webpack_require__(58); module.exports = new Directive({ literal: true, /** * 初始化指令 * @returns {void} 无返回 */ bind: function /*istanbul ignore next*/bind() { var attrValue = this.attribute.value || ''; if (attrValue.indexOf('(') < 0 && attrValue.indexOf(')') < 0) { attrValue += '($event)'; } this.expr = new this.Expression(attrValue); var eventTarget = this.node.$target || this.node; this.emiter = new EventEmitter(eventTarget); this.emiter.addListener(this.decorates[0], function (event) { if (this.utils.isNull(this.scope)) return; this.expr.execute(new Scope(this.scope, { $event: event })); }.bind(this), false); }, unbind: function /*istanbul ignore next*/unbind() { this.emiter.removeListener(); }, execute: function /*istanbul ignore next*/execute(scope) { this.scope = scope; } }); /***/ }), /* 63 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var Directive = __webpack_require__(53); module.exports = new Directive({ update: function /*istanbul ignore next*/update(newValue) { this.node.innerHTML = newValue; } }); /***/ }), /* 64 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var Directive = __webpack_require__(53); module.exports = new Directive({ update: function /*istanbul ignore next*/update(newValue) { this.node.innerText = newValue; } }); /***/ }), /* 65 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var Directive = __webpack_require__(53); module.exports = new Directive({ level: Directive.LP, final: true }); /***/ }), /* 66 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var Directive = __webpack_require__(53); module.exports = new Directive({ literal: true, update: function /*istanbul ignore next*/update(id) { if (id in this.scope) { throw new Error('Conflicting component id `' + id + '`'); } this.scope[id] = this.node.$target || this.node; } }); /***/ }), /* 67 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var Directive = __webpack_require__(53); module.exports = new Directive({ level: Directive.LC, literal: true, prefix: false, bind: function /*istanbul ignore next*/bind() { this.node.removeAttribute(this.attribute.name); } }); /***/ }), /* 68 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var Directive = __webpack_require__(53); module.exports = new Directive({ update: function /*istanbul ignore next*/update(value) { this.node.style.display = value ? '' : 'none'; } }); /***/ }), /* 69 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var SelectDirective = __webpack_require__(70); var EditableDirective = __webpack_require__(71); var InputDirective = __webpack_require__(72); var RadioDirective = __webpack_require__(73); var CheckboxDirective = __webpack_require__(74); var PropDirective = __webpack_require__(75); var Directive = function Directive(options) { var node = options.node; var tagName = node.tagName; if (options.decorates[0]) { return new PropDirective(options); } else if (tagName == 'INPUT') { var type = node.getAttribute('type'); if (type == 'radio') { return new RadioDirective(options); } else if (type == 'checkbox') { return new CheckboxDirective(options); } else { return new InputDirective(options); } } else if (tagName == 'TEXTAREA') { return new InputDirective(options); } else if (tagName == 'SELECT') { return new SelectDirective(options); } else if (node.isContentEditable) { return new EditableDirective(options); } else { throw new Error( /*istanbul ignore next*/'Directive `model` cannot be used on `' + tagName + '`'); } }; //手动添加 classOptions Directive.options = { level: Directive.LA }; module.exports = Directive; /***/ }), /* 70 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var Directive = __webpack_require__(53); var EventEmitter = __webpack_require__(50); var Scope = __webpack_require__(58); module.exports = new Directive({ final: true, /** * 初始化指令 * @returns {void} 无返回 */ bind: function /*istanbul ignore next*/bind() { this.backExpr = new this.Expression( /*istanbul ignore next*/this.attribute.value + '=_value_'); this.node.removeAttribute(this.attribute.name); this._handler = this.compiler.compile(this.node); this.emiter = new EventEmitter(this.node); this.emiter.addListener('change', function () { if (this.utils.isNull(this.scope)) return; var selectedOptions = this.node.selectedOptions; var value = this.node.multiple ? [].slice.call(selectedOptions).map(function (option) { return option.value; }, this) : selectedOptions[0].value; this.backExpr.execute(new Scope(this.scope, { _value_: value })); }.bind(this), false); }, unbind: function /*istanbul ignore next*/unbind() { this.emiter.removeListener(); }, execute: function /*istanbul ignore next*/execute(scope) { this.scope = scope; this._handler(scope); var value = this.expression.execute(scope); if (!this.utils.isArray(value)) value = [value]; [].slice.call(this.node.options).forEach(function (option) { option.selected = value.indexOf(option.value) > -1; }, this); } }); /***/ }), /* 71 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var Directive = __webpack_require__(53); var EventEmitter = __webpack_require__(50); var Scope = __webpack_require__(58); module.exports = new Directive({ /** * 初始化指令 * @returns {void} 无返回 */ bind: function /*istanbul ignore next*/bind() { this.backExpr = new this.Expression( /*istanbul ignore next*/this.attribute.value + '=_value_'); this.emiter = new EventEmitter(this.node); this.emiter.addListener('input', function () { if (this.utils.isNull(this.scope)) return; this.backExpr.execute(new Scope(this.scope, { _value_: this.node.innerHTML })); }.bind(this), false); }, unbind: function /*istanbul ignore next*/unbind() { this.emiter.removeListener(); }, execute: function /*istanbul ignore next*/execute(scope) { var value = this.expression.execute(scope); if (this.node.innerHTML !== value) { this.node.innerHTML = value; } } }); /***/ }), /* 72 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var Directive = __webpack_require__(53); var EventEmitter = __webpack_require__(50); var Scope = __webpack_require__(58); module.exports = new Directive({ /** * 初始化指令 * @returns {void} 无返回 */ bind: function /*istanbul ignore next*/bind() { this.backExpr = new this.Expression( /*istanbul ignore next*/this.attribute.value + '=_value_'); this.emiter = new EventEmitter(this.node); this.emiter.addListener('input', function () { if (this.utils.isNull(this.scope)) return; this.backExpr.execute(new Scope(this.scope, { _value_: this.node.value })); }.bind(this), false); }, unbind: function /*istanbul ignore next*/unbind() { this.emiter.removeListener(); }, execute: function /*istanbul ignore next*/execute(scope) { var value = this.expression.execute(scope); if (this.node.value !== value) { this.node.value = value; } } }); /***/ }), /* 73 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var Directive = __webpack_require__(53); var EventEmitter = __webpack_require__(50); var Scope = __webpack_require__(58); module.exports = new Directive({ /** * 初始化指令 * @returns {void} 无返回 */ bind: function /*istanbul ignore next*/bind() { this.backExpr = new this.Expression( /*istanbul ignore next*/this.attribute.value + '=_value_'); this.emiter = new EventEmitter(this.node); this.emiter.addListener('change', function () { if (this.utils.isNull(this.scope)) return; this.backExpr.execute(new Scope(this.scope, { _value_: this.node.value })); }.bind(this), false); }, unbind: function /*istanbul ignore next*/unbind() { this.emiter.removeListener(); }, execute: function /*istanbul ignore next*/execute(scope) { this.scope = scope; var value = this.expression.execute(scope); this.node.checked = value == this.node.value; } }); /***/ }), /* 74 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var Directive = __webpack_require__(53); var EventEmitter = __webpack_require__(50); var Scope = __webpack_require__(58); module.exports = new Directive({ /** * 初始化指令 * @returns {void} 无返回 */ bind: function /*istanbul ignore next*/bind() { this.backExpr = new this.Expression( /*istanbul ignore next*/this.attribute.value + '=_value_'); this.emiter = new EventEmitter(this.node); this.emiter.addListener('change', function () { if (this.utils.isNull(this.scope)) return; var value = this.expression.execute(this.scope); if (this.utils.isArray(value) && this.node.checked) { value.push(this.node.value); } else if (this.utils.isArray(value) && !this.node.checked) { var index = value.indexOf(this.node.value); value.splice(index, 1); } else { this.backExpr.execute(new Scope(this.scope, { _value_: this.node.checked })); } }.bind(this), false); }, unbind: function /*istanbul ignore next*/unbind() { this.emiter.removeListener(); }, execute: function /*istanbul ignore next*/execute(scope) { this.scope = scope; var value = this.expression.execute(scope); if (this.utils.isArray(value)) { this.node.checked = value.indexOf(this.node.value) > -1; } else { this.node.checked = value; } } }); /***/ }), /* 75 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var Directive = __webpack_require__(53); var Scope = __webpack_require__(58); module.exports = new Directive({ /** * 初始化指令 * @returns {void} 无返回 */ bind: function /*istanbul ignore next*/bind() { /*istanbul ignore next*/var _this = this; this.target = this.node.$target; this.backExpr = new this.Expression( /*istanbul ignore next*/this.attribute.value + '=_value_'); this.bindProp = this.decorates[0]; if (!this.target) { throw new Error( /*istanbul ignore next*/'Directive `model:' + this.bindProp + '` cannot be used on `' + this.node.tagName + '`'); } this.watcher = this.target.$watch(this.bindProp, function (value) { if ( /*istanbul ignore next*/_this.utils.isNull( /*istanbul ignore next*/_this.scope)) return; /*istanbul ignore next*/_this.backExpr.execute(new Scope( /*istanbul ignore next*/_this.scope, { _value_: value })); }); }, unbind: function /*istanbul ignore next*/unbind() { this.target.$unWatch(this.watcher); }, update: function /*istanbul ignore next*/update(value) { this.target[this.bindProp] = value; } }); /***/ }), /* 76 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var Directive = __webpack_require__(53); module.exports = new Directive({ execute: function /*istanbul ignore next*/execute(scope) { /*istanbul ignore next*/var _this = this; var state = this.expression.execute(scope); setTimeout(function () { if (state) /*istanbul ignore next*/_this.node.focus();else /*istanbul ignore next*/_this.node.blur(); }, 0); } }); /***/ }), /* 77 */ /***/ (function(module, exports, __webpack_require__) { /*istanbul ignore next*/'use strict'; var Directive = __webpack_require__(53); /** * 通用的 attribute 指令 * 用于所有 attribute 的处理 * 例如: *
'
+ (escaped ? code : escape(code, true))
+ '\n
';
}
return ''
+ (escaped ? code : escape(code, true))
+ '\n
\n';
};
Renderer.prototype.blockquote = function(quote) {
return '\n' + quote + '\n'; }; Renderer.prototype.html = function(html) { return html; }; Renderer.prototype.heading = function(text, level, raw) { return '
' + text + '
\n'; }; Renderer.prototype.table = function(header, body) { return '' + text + '
';
};
Renderer.prototype.br = function() {
return this.options.xhtml ? 'An error occured:
' + escape(e.message + '', true) + ''; } throw e; } } /** * Options */ marked.options = marked.setOptions = function(opt) { merge(marked.defaults, opt); return marked; }; marked.defaults = { gfm: true, tables: true, breaks: false, pedantic: false, sanitize: false, sanitizer: null, mangle: true, smartLists: false, silent: false, highlight: null, langPrefix: 'lang-', smartypants: false, headerPrefix: '', renderer: new Renderer, xhtml: false }; /** * Expose */ marked.Parser = Parser; marked.parser = Parser.parse; marked.Renderer = Renderer; marked.Lexer = Lexer; marked.lexer = Lexer.lex; marked.InlineLexer = InlineLexer; marked.inlineLexer = InlineLexer.output; marked.parse = marked; if (true) { module.exports = marked; } else if (typeof define === 'function' && define.amd) { define(function() { return marked; }); } else { this.marked = marked; } }).call(function() { return this || (typeof window !== 'undefined' ? window : global); }()); /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }()))) /***/ }), /* 104 */ /***/ (function(module, exports) { /* WEBPACK VAR INJECTION */(function(global) { /* ********************************************** Begin prism-core.js ********************************************** */ var _self = (typeof window !== 'undefined') ? window // if in browser : ( (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) ? self // if in worker : {} // if in node js ); /** * Prism: Lightweight, robust, elegant syntax highlighting * MIT license http://www.opensource.org/licenses/mit-license.php/ * @author Lea Verou http://lea.verou.me */ var Prism = (function(){ // Private helper vars var lang = /\blang(?:uage)?-(\w+)\b/i; var uniqueId = 0; var _ = _self.Prism = { manual: _self.Prism && _self.Prism.manual, util: { encode: function (tokens) { if (tokens instanceof Token) { return new Token(tokens.type, _.util.encode(tokens.content), tokens.alias); } else if (_.util.type(tokens) === 'Array') { return tokens.map(_.util.encode); } else { return tokens.replace(/&/g, '&').replace(/ text.length) { // Something went terribly wrong, ABORT, ABORT! return; } if (str instanceof Token) { continue; } pattern.lastIndex = 0; var match = pattern.exec(str), delNum = 1; // Greedy patterns can override/remove up to two previously matched tokens if (!match && greedy && i != strarr.length - 1) { pattern.lastIndex = pos; match = pattern.exec(text); if (!match) { break; } var from = match.index + (lookbehind ? match[1].length : 0), to = match.index + match[0].length, k = i, p = pos; for (var len = strarr.length; k < len && (p < to || (!strarr[k].type && !strarr[k - 1].greedy)); ++k) { p += strarr[k].length; // Move the index i to the element in strarr that is closest to from if (from >= p) { ++i; pos = p; } } /* * If strarr[i] is a Token, then the match starts inside another Token, which is invalid * If strarr[k - 1] is greedy we are in conflict with another greedy pattern */ if (strarr[i] instanceof Token || strarr[k - 1].greedy) { continue; } // Number of tokens to delete and replace with the new match delNum = k - i; str = text.slice(pos, p); match.index -= pos; } if (!match) { if (oneshot) { break; } continue; } if(lookbehind) { lookbehindLength = match[1].length; } var from = match.index + lookbehindLength, match = match[0].slice(lookbehindLength), to = from + match.length, before = str.slice(0, from), after = str.slice(to); var args = [i, delNum]; if (before) { ++i; pos += before.length; args.push(before); } var wrapped = new Token(token, inside? _.tokenize(match, inside) : match, alias, match, greedy); args.push(wrapped); if (after) { args.push(after); } Array.prototype.splice.apply(strarr, args); if (delNum != 1) _.matchGrammar(text, strarr, grammar, i, pos, true, token); if (oneshot) break; } } } }, tokenize: function(text, grammar, language) { var strarr = [text]; var rest = grammar.rest; if (rest) { for (var token in rest) { grammar[token] = rest[token]; } delete grammar.rest; } _.matchGrammar(text, strarr, grammar, 0, 0, false); return strarr; }, hooks: { all: {}, add: function (name, callback) { var hooks = _.hooks.all; hooks[name] = hooks[name] || []; hooks[name].push(callback); }, run: function (name, env) { var callbacks = _.hooks.all[name]; if (!callbacks || !callbacks.length) { return; } for (var i=0, callback; callback = callbacks[i++];) { callback(env); } } } }; var Token = _.Token = function(type, content, alias, matchedStr, greedy) { this.type = type; this.content = content; this.alias = alias; // Copy of the full string this token was created from this.length = (matchedStr || "").length|0; this.greedy = !!greedy; }; Token.stringify = function(o, language, parent) { if (typeof o == 'string') { return o; } if (_.util.type(o) === 'Array') { return o.map(function(element) { return Token.stringify(element, language, o); }).join(''); } var env = { type: o.type, content: Token.stringify(o.content, language, parent), tag: 'span', classes: ['token', o.type], attributes: {}, language: language, parent: parent }; if (env.type == 'comment') { env.attributes['spellcheck'] = 'true'; } if (o.alias) { var aliases = _.util.type(o.alias) === 'Array' ? o.alias : [o.alias]; Array.prototype.push.apply(env.classes, aliases); } _.hooks.run('wrap', env); var attributes = Object.keys(env.attributes).map(function(name) { return name + '="' + (env.attributes[name] || '').replace(/"/g, '"') + '"'; }).join(' '); return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + (attributes ? ' ' + attributes : '') + '>' + env.content + '' + env.tag + '>'; }; if (!_self.document) { if (!_self.addEventListener) { // in Node.js return _self.Prism; } // In worker _self.addEventListener('message', function(evt) { var message = JSON.parse(evt.data), lang = message.language, code = message.code, immediateClose = message.immediateClose; _self.postMessage(_.highlight(code, _.languages[lang], lang)); if (immediateClose) { _self.close(); } }, false); return _self.Prism; } //Get current script and highlight var script = document.currentScript || [].slice.call(document.getElementsByTagName("script")).pop(); if (script) { _.filename = script.src; if (!_.manual && !script.hasAttribute('data-manual')) { if(document.readyState !== "loading") { if (window.requestAnimationFrame) { window.requestAnimationFrame(_.highlightAll); } else { window.setTimeout(_.highlightAll, 16); } } else { document.addEventListener('DOMContentLoaded', _.highlightAll); } } } return _self.Prism; })(); if (typeof module !== 'undefined' && module.exports) { module.exports = Prism; } // hack for components to work correctly in node.js if (typeof global !== 'undefined') { global.Prism = Prism; } /* ********************************************** Begin prism-markup.js ********************************************** */ Prism.languages.markup = { 'comment': //, 'prolog': /<\?[\s\S]+?\?>/, 'doctype': //i, 'cdata': //i, 'tag': { pattern: /<\/?(?!\d)[^\s>\/=$<]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\\1|\\?(?!\1)[\s\S])*\1|[^\s'">=]+))?)*\s*\/?>/i, inside: { 'tag': { pattern: /^<\/?[^\s>\/]+/i, inside: { 'punctuation': /^<\/?/, 'namespace': /^[^\s>\/:]+:/ } }, 'attr-value': { pattern: /=(?:('|")[\s\S]*?(\1)|[^\s>]+)/i, inside: { 'punctuation': /[=>"']/ } }, 'punctuation': /\/?>/, 'attr-name': { pattern: /[^\s>\/]+/, inside: { 'namespace': /^[^\s>\/:]+:/ } } } }, 'entity': /?[\da-z]{1,8};/i }; Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] = Prism.languages.markup['entity']; // Plugin to make entity title show the real entity, idea by Roman Komarov Prism.hooks.add('wrap', function(env) { if (env.type === 'entity') { env.attributes['title'] = env.content.replace(/&/, '&'); } }); Prism.languages.xml = Prism.languages.markup; Prism.languages.html = Prism.languages.markup; Prism.languages.mathml = Prism.languages.markup; Prism.languages.svg = Prism.languages.markup; /* ********************************************** Begin prism-css.js ********************************************** */ Prism.languages.css = { 'comment': /\/\*[\s\S]*?\*\//, 'atrule': { pattern: /@[\w-]+?.*?(;|(?=\s*\{))/i, inside: { 'rule': /@[\w-]+/ // See rest below } }, 'url': /url\((?:(["'])(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1|.*?)\)/i, 'selector': /[^\{\}\s][^\{\};]*?(?=\s*\{)/, 'string': { pattern: /("|')(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/, greedy: true }, 'property': /(\b|\B)[\w-]+(?=\s*:)/i, 'important': /\B!important\b/i, 'function': /[-a-z0-9]+(?=\()/i, 'punctuation': /[(){};:]/ }; Prism.languages.css['atrule'].inside.rest = Prism.util.clone(Prism.languages.css); if (Prism.languages.markup) { Prism.languages.insertBefore('markup', 'tag', { 'style': { pattern: /(