UNPKG

vue-egret

Version:
238 lines (203 loc) 141 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if(typeof define === 'function' && define.amd) define([], factory); else if(typeof exports === 'object') exports["prerender"] = factory(); else root["prerender"] = factory(); })(this, function() { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); /******/ } /******/ }; /******/ /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ /******/ // create a fake namespace object /******/ // mode & 1: value is a module id, require it /******/ // mode & 2: merge all properties of value into the ns /******/ // mode & 4: return value when already ns object /******/ // mode & 8|1: behave like require /******/ __webpack_require__.t = function(value, mode) { /******/ if(mode & 1) value = __webpack_require__(value); /******/ if(mode & 8) return value; /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; /******/ var ns = Object.create(null); /******/ __webpack_require__.r(ns); /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); /******/ return ns; /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = "./packages/prerender/index.ts"); /******/ }) /************************************************************************/ /******/ ({ /***/ "./node_modules/process/browser.js": /*!*****************************************!*\ !*** ./node_modules/process/browser.js ***! \*****************************************/ /*! no static exports found */ /***/ (function(module, exports) { eval("// shim for using process in browser\nvar process = module.exports = {};\n\n// cached from whatever global is present so that test runners that stub it\n// don't break things. But we need to wrap it in a try catch in case it is\n// wrapped in strict mode code which doesn't define any globals. It's inside a\n// function because try/catches deoptimize in certain engines.\n\nvar cachedSetTimeout;\nvar cachedClearTimeout;\n\nfunction defaultSetTimout() {\n throw new Error('setTimeout has not been defined');\n}\nfunction defaultClearTimeout () {\n throw new Error('clearTimeout has not been defined');\n}\n(function () {\n try {\n if (typeof setTimeout === 'function') {\n cachedSetTimeout = setTimeout;\n } else {\n cachedSetTimeout = defaultSetTimout;\n }\n } catch (e) {\n cachedSetTimeout = defaultSetTimout;\n }\n try {\n if (typeof clearTimeout === 'function') {\n cachedClearTimeout = clearTimeout;\n } else {\n cachedClearTimeout = defaultClearTimeout;\n }\n } catch (e) {\n cachedClearTimeout = defaultClearTimeout;\n }\n} ())\nfunction runTimeout(fun) {\n if (cachedSetTimeout === setTimeout) {\n //normal enviroments in sane situations\n return setTimeout(fun, 0);\n }\n // if setTimeout wasn't available but was latter defined\n if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {\n cachedSetTimeout = setTimeout;\n return setTimeout(fun, 0);\n }\n try {\n // when when somebody has screwed with setTimeout but no I.E. maddness\n return cachedSetTimeout(fun, 0);\n } catch(e){\n try {\n // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally\n return cachedSetTimeout.call(null, fun, 0);\n } catch(e){\n // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error\n return cachedSetTimeout.call(this, fun, 0);\n }\n }\n\n\n}\nfunction runClearTimeout(marker) {\n if (cachedClearTimeout === clearTimeout) {\n //normal enviroments in sane situations\n return clearTimeout(marker);\n }\n // if clearTimeout wasn't available but was latter defined\n if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {\n cachedClearTimeout = clearTimeout;\n return clearTimeout(marker);\n }\n try {\n // when when somebody has screwed with setTimeout but no I.E. maddness\n return cachedClearTimeout(marker);\n } catch (e){\n try {\n // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally\n return cachedClearTimeout.call(null, marker);\n } catch (e){\n // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.\n // Some versions of I.E. have different rules for clearTimeout vs setTimeout\n return cachedClearTimeout.call(this, marker);\n }\n }\n\n\n\n}\nvar queue = [];\nvar draining = false;\nvar currentQueue;\nvar queueIndex = -1;\n\nfunction cleanUpNextTick() {\n if (!draining || !currentQueue) {\n return;\n }\n draining = false;\n if (currentQueue.length) {\n queue = currentQueue.concat(queue);\n } else {\n queueIndex = -1;\n }\n if (queue.length) {\n drainQueue();\n }\n}\n\nfunction drainQueue() {\n if (draining) {\n return;\n }\n var timeout = runTimeout(cleanUpNextTick);\n draining = true;\n\n var len = queue.length;\n while(len) {\n currentQueue = queue;\n queue = [];\n while (++queueIndex < len) {\n if (currentQueue) {\n currentQueue[queueIndex].run();\n }\n }\n queueIndex = -1;\n len = queue.length;\n }\n currentQueue = null;\n draining = false;\n runClearTimeout(timeout);\n}\n\nprocess.nextTick = function (fun) {\n var args = new Array(arguments.length - 1);\n if (arguments.length > 1) {\n for (var i = 1; i < arguments.length; i++) {\n args[i - 1] = arguments[i];\n }\n }\n queue.push(new Item(fun, args));\n if (queue.length === 1 && !draining) {\n runTimeout(drainQueue);\n }\n};\n\n// v8 likes predictible objects\nfunction Item(fun, array) {\n this.fun = fun;\n this.array = array;\n}\nItem.prototype.run = function () {\n this.fun.apply(null, this.array);\n};\nprocess.title = 'browser';\nprocess.browser = true;\nprocess.env = {};\nprocess.argv = [];\nprocess.version = ''; // empty string to avoid regexp issues\nprocess.versions = {};\n\nfunction noop() {}\n\nprocess.on = noop;\nprocess.addListener = noop;\nprocess.once = noop;\nprocess.off = noop;\nprocess.removeListener = noop;\nprocess.removeAllListeners = noop;\nprocess.emit = noop;\nprocess.prependListener = noop;\nprocess.prependOnceListener = noop;\n\nprocess.listeners = function (name) { return [] }\n\nprocess.binding = function (name) {\n throw new Error('process.binding is not supported');\n};\n\nprocess.cwd = function () { return '/' };\nprocess.chdir = function (dir) {\n throw new Error('process.chdir is not supported');\n};\nprocess.umask = function() { return 0; };\n\n\n//# sourceURL=webpack://%5Bname%5D/./node_modules/process/browser.js?"); /***/ }), /***/ "./packages/prerender/index.ts": /*!*************************************!*\ !*** ./packages/prerender/index.ts ***! \*************************************/ /*! exports provided: default */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var src_helpers_render__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! src/helpers/render */ \"./src/helpers/render.ts\");\n\n/* harmony default export */ __webpack_exports__[\"default\"] = (function (template) {\n return `function(){${Object(src_helpers_render__WEBPACK_IMPORTED_MODULE_0__[\"astStrRender\"])(template)}}`;\n});\n\n\n//# sourceURL=webpack://%5Bname%5D/./packages/prerender/index.ts?"); /***/ }), /***/ "./src/directives/bind.ts": /*!********************************!*\ !*** ./src/directives/bind.ts ***! \********************************/ /*! exports provided: default */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"default\", function() { return bind; });\nfunction bind(data, dir) {\n data.wrapDir.push((code) => {\n return `_b(${code},${dir.expression}${dir.modifiers && dir.modifiers.sync ? ',true' : ''})`;\n });\n}\n\n\n//# sourceURL=webpack://%5Bname%5D/./src/directives/bind.ts?"); /***/ }), /***/ "./src/directives/index.ts": /*!*********************************!*\ !*** ./src/directives/index.ts ***! \*********************************/ /*! exports provided: normalizeDirectives, default */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"normalizeDirectives\", function() { return normalizeDirectives; });\n/* harmony import */ var _on__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./on */ \"./src/directives/on.ts\");\n/* harmony import */ var _bind__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./bind */ \"./src/directives/bind.ts\");\n\n\nfunction normalizeDirectives(dirs) {\n return dirs.reduce((obj, dir) => ((obj[dir.name] = dir), obj), {});\n}\n/* harmony default export */ __webpack_exports__[\"default\"] = ({\n on: _on__WEBPACK_IMPORTED_MODULE_0__[\"default\"],\n bind: _bind__WEBPACK_IMPORTED_MODULE_1__[\"default\"],\n});\n\n\n//# sourceURL=webpack://%5Bname%5D/./src/directives/index.ts?"); /***/ }), /***/ "./src/directives/on.ts": /*!******************************!*\ !*** ./src/directives/on.ts ***! \******************************/ /*! exports provided: default */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"default\", function() { return on; });\nfunction on(data, dir) {\n data.wrapDir.push((code) => `_g(${code},${dir.expression})`);\n}\n\n\n//# sourceURL=webpack://%5Bname%5D/./src/directives/on.ts?"); /***/ }), /***/ "./src/helpers/index.ts": /*!******************************!*\ !*** ./src/helpers/index.ts ***! \******************************/ /*! exports provided: parseFor, getBindingAttr, getAndRemoveAttr, getAndRemoveAttrByRegex */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"parseFor\", function() { return parseFor; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"getBindingAttr\", function() { return getBindingAttr; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"getAndRemoveAttr\", function() { return getAndRemoveAttr; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"getAndRemoveAttrByRegex\", function() { return getAndRemoveAttrByRegex; });\nconst FOR_ALIAS_RE = /([\\s\\S]*?)\\s+(?:in|of)\\s+([\\s\\S]*)/;\nconst FOR_ITERATOR_RE = /,([^,\\}\\]]*)(?:,([^,\\}\\]]*))?$/;\nconst STRIP_PARENS_RE = /^\\(|\\)$/g;\nfunction parseFor(exp) {\n const inMatch = exp.match(FOR_ALIAS_RE);\n if (!inMatch)\n return;\n const res = { for: '', alias: '' };\n res.for = inMatch[2].trim();\n const alias = inMatch[1].trim().replace(STRIP_PARENS_RE, '');\n const iteratorMatch = alias.match(FOR_ITERATOR_RE);\n if (iteratorMatch) {\n res.alias = alias.replace(FOR_ITERATOR_RE, '').trim();\n res.iterator1 = iteratorMatch[1].trim();\n if (iteratorMatch[2]) {\n res.iterator2 = iteratorMatch[2].trim();\n }\n }\n else {\n res.alias = alias;\n }\n return res;\n}\nfunction getBindingAttr(node, name) {\n const dynamicValue = getAndRemoveAttr(node, ':' + name) || getAndRemoveAttr(node, 'v-bind:' + name);\n if (dynamicValue != null)\n return dynamicValue;\n const staticValue = getAndRemoveAttr(node, name);\n if (staticValue != null)\n return JSON.stringify(staticValue);\n}\nfunction getAndRemoveAttr(node, name) {\n const val = node.attrsMap[name];\n const list = node.attrsList;\n for (let i = 0, l = list.length; i < l; i++) {\n if (list[i].name === name) {\n list.splice(i, 1);\n break;\n }\n }\n return val;\n}\nfunction getAndRemoveAttrByRegex(node, name) {\n const list = node.attrsList;\n for (let i = 0, l = list.length; i < l; i++) {\n const attr = list[i];\n if (name.test(attr.name)) {\n list.splice(i, 1);\n return attr;\n }\n }\n}\n\n\n//# sourceURL=webpack://%5Bname%5D/./src/helpers/index.ts?"); /***/ }), /***/ "./src/helpers/render.ts": /*!*******************************!*\ !*** ./src/helpers/render.ts ***! \*******************************/ /*! exports provided: astStrRender */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"astStrRender\", function() { return astStrRender; });\n/* harmony import */ var src_render_gen__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! src/render/gen */ \"./src/render/gen.ts\");\n/* harmony import */ var _parser__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../parser */ \"./src/parser/index.ts\");\n\n\nfunction astStrRender(template) {\n // 通过模板解析,将模板转化为AST\n const ast = Object(src_render_gen__WEBPACK_IMPORTED_MODULE_0__[\"genVNode\"])(_parser__WEBPACK_IMPORTED_MODULE_1__[\"default\"].created(template).root);\n return `with(this){ return ${ast};}`;\n}\n\n\n//# sourceURL=webpack://%5Bname%5D/./src/helpers/render.ts?"); /***/ }), /***/ "./src/index.ts": /*!**********************!*\ !*** ./src/index.ts ***! \**********************/ /*! exports provided: Component, default */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; eval("__webpack_require__.r(__webpack_exports__);\n/* WEBPACK VAR INJECTION */(function(process) {/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"Component\", function() { return Component; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"default\", function() { return VueEgret; });\n/* harmony import */ var _render__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./render */ \"./src/render/index.ts\");\n/* harmony import */ var _observer_watcher__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./observer/watcher */ \"./src/observer/watcher.ts\");\n/* harmony import */ var _observer_index__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./observer/index */ \"./src/observer/index.ts\");\n/* harmony import */ var _observer_dep__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./observer/dep */ \"./src/observer/dep.ts\");\n/* harmony import */ var _util_index__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./util/index */ \"./src/util/index.ts\");\n/* harmony import */ var _util_props__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./util/props */ \"./src/util/props.ts\");\n/* harmony import */ var _util_next_tick__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./util/next-tick */ \"./src/util/next-tick.ts\");\n/* harmony import */ var _util_tween__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./util/tween */ \"./src/util/tween.ts\");\n/*\n * vue-egret\n * @author Hsuna\n */\n///<reference path=\"../types/egret.d.ts\" />\n///<reference path=\"../types/tween.d.ts\" />\n\n\n\n\n\n\n\n\n/**\n * 组件类\n * @author Hsuna\n * @param { ComponentOptions } options 组件配置\n * @param { ComponentParentOptions } parentOptions 继承配置\n */\nclass Component {\n constructor(options = {}, parentOptions = {}) {\n /** 子组件集合 */\n this.$children = [];\n /** 获取注册列表 */\n this.$refs = {};\n // 全局方法\n /** 设置对象的 property */\n this.$set = _observer_index__WEBPACK_IMPORTED_MODULE_2__[\"set\"];\n /** 删除对象的 property */\n this.$delete = _observer_index__WEBPACK_IMPORTED_MODULE_2__[\"del\"];\n /** 回调延迟到下次更新 */\n this.$nextTick = function (fn) {\n return Object(_util_next_tick__WEBPACK_IMPORTED_MODULE_6__[\"nextTick\"])(fn, this);\n };\n /** Tween方法 */\n this.$tween = _util_tween__WEBPACK_IMPORTED_MODULE_7__[\"tween\"];\n // private __tickHandler: ComponentMap<Function> = [];\n this._global = {};\n this._data = {};\n this._props = {};\n this._hasHookEvent = false;\n // 状态值\n this._isVue = true;\n this._isMounted = false;\n this._isBeingDestroyed = false;\n this._isDestroyed = false;\n this._watchers = [];\n this._events = {};\n this._components = {};\n this._directives = {};\n this.$options = options;\n this._parentOptions = parentOptions;\n this._init();\n }\n _init() {\n this.$parent = this._parentOptions.parent;\n if (this.$parent)\n this.$parent.$children.push(this);\n this.$root = this.$parent ? this.$parent.$root : this;\n this._initMethods(this.$options.methods);\n this.$callHook('beforeCreate');\n this._initGlobal();\n this._initData(this.$options.data);\n this._initProps(this.$options.props, this._parentOptions.propsData);\n this._initComputed(this.$options.computed);\n this._initWatch(this.$options.watch);\n this._initComponents(this.$options.components);\n this._initDirectives(this.$options.directives);\n this.$callHook('created');\n this._render = new _render__WEBPACK_IMPORTED_MODULE_0__[\"default\"](this);\n this._initEvent();\n }\n _initEvent() {\n /* 添加到显示列表时触发挂载 */\n this.$el.once(egret.Event.ADDED, () => this._render.inserted(), this.$el);\n /* 添加到舞台时触发挂载 */\n this.$el.once(egret.Event.ADDED_TO_STAGE, () => {\n this.$callHook('beforeMount');\n this._global.stage = this.$el.stage;\n this._watcher = new _observer_watcher__WEBPACK_IMPORTED_MODULE_1__[\"default\"](this, () => {\n if (!this._render)\n return; // 防止渲染器销毁时,进程依然回调方法\n if (this._isMounted)\n this.$callHook('beforeUpdate');\n this._render.update();\n }, _util_index__WEBPACK_IMPORTED_MODULE_4__[\"noop\"]);\n this._isMounted = true;\n this.$callHook('mounted');\n }, this.$el);\n /* 从舞台移除时销毁该示例 */\n this.$el.once(egret.Event.REMOVED_FROM_STAGE, () => this.$destroy(), this.$el);\n }\n /** 初始化全局参数,用于全局方便获取 */\n _initGlobal() {\n this._global = {\n stage: new egret.Stage(),\n };\n // 监听数据\n Object(_observer_index__WEBPACK_IMPORTED_MODULE_2__[\"observe\"])(this._global, true);\n }\n _initProps(propsOptions = {}, propsData = {}) {\n const props = Object(_util_props__WEBPACK_IMPORTED_MODULE_5__[\"normalizeProp\"])(propsOptions); // normalizeProp\n for (const key in props) {\n this._props[key] = Object(_util_index__WEBPACK_IMPORTED_MODULE_4__[\"hasOwn\"])(propsData, key) ? propsData[key] : Object(_util_props__WEBPACK_IMPORTED_MODULE_5__[\"validateProp\"])(props[key], this);\n Object.defineProperty(this, key, {\n get() {\n return this._props[key];\n },\n set(val) {\n console.error('The props data not set!');\n },\n });\n }\n // 监听数据\n Object(_observer_index__WEBPACK_IMPORTED_MODULE_2__[\"observe\"])(this._props, true);\n }\n _initData(data) {\n this._data = typeof data === 'function' ? this._getData(data) : data || {};\n for (const key in this._data) {\n Object.defineProperty(this, key, {\n get() {\n return this._data[key];\n },\n set(val) {\n this._data[key] = val;\n },\n });\n }\n // 监听数据\n Object(_observer_index__WEBPACK_IMPORTED_MODULE_2__[\"observe\"])(this._data, true);\n }\n _initMethods(methods = {}) {\n // 将methods上的方法赋值到vm实例上\n for (const e in methods) {\n this[e] = methods[e];\n }\n }\n _initComputed(computed = {}) {\n let propertyDefinition;\n for (const key in computed) {\n const userDef = computed[key] || _util_index__WEBPACK_IMPORTED_MODULE_4__[\"noop\"];\n propertyDefinition =\n typeof userDef === 'function'\n ? { get: userDef, set: _util_index__WEBPACK_IMPORTED_MODULE_4__[\"noop\"] }\n : { get: userDef.get, set: userDef.set };\n Object.defineProperty(this, key, propertyDefinition);\n }\n }\n _initWatch(watch = {}) {\n for (const key in watch) {\n const handler = watch[key];\n if (Array.isArray(handler)) {\n handler.forEach((h) => this._createWatcher(key, h));\n }\n else {\n this._createWatcher(key, handler);\n }\n }\n }\n _initComponents(components = {}) {\n for (const name in components) {\n this._components[name] = VueEgret.extend(components[name]);\n }\n }\n _initDirectives(directives = {}) {\n for (const name in directives) {\n this._directives[name] = directives[name];\n }\n }\n _getData(data) {\n Object(_observer_dep__WEBPACK_IMPORTED_MODULE_3__[\"pushTarget\"])();\n try {\n return data.call(this, this);\n }\n catch (e) {\n console.log(e);\n return {};\n }\n finally {\n Object(_observer_dep__WEBPACK_IMPORTED_MODULE_3__[\"popTarget\"])();\n }\n }\n _createWatcher(expOrFn, handler, options) {\n if (Object(_util_index__WEBPACK_IMPORTED_MODULE_4__[\"isPlainObject\"])(handler)) {\n options = handler;\n handler = handler.handler;\n }\n if (typeof handler === 'string') {\n handler = this[handler];\n }\n return this.$watch(expOrFn, handler, options);\n }\n $on(event, fn) {\n if (Array.isArray(event)) {\n event.forEach((evt) => this.$on(evt, fn));\n }\n else {\n const events = this._events[event] || (this._events[event] = []);\n events.push(fn);\n // optimize hook:event cost by using a boolean flag marked at registration\n // instead of a hash lookup\n if (Object(_util_index__WEBPACK_IMPORTED_MODULE_4__[\"isHook\"])(event)) {\n this._hasHookEvent = true;\n }\n }\n return this;\n }\n $once(event, fn) {\n const on = (...args) => {\n this.$off(event, on);\n return fn.apply(this, args);\n };\n on.fn = fn;\n this.$on(event, on);\n return this;\n }\n $off(event, fn) {\n // all\n if (!arguments.length) {\n this._events = Object.create(null);\n this._hasHookEvent = false;\n return this;\n }\n // array of events\n if (Array.isArray(event)) {\n event.forEach((evt) => this.$off(evt, fn));\n return this;\n }\n // specific event\n const cbs = this._events[event];\n if (!cbs) {\n return this;\n }\n if (!fn) {\n this._events[event] = null;\n return this;\n }\n if (fn) {\n // specific handler\n let cb;\n let i = cbs.length;\n while (i--) {\n cb = cbs[i];\n if (cb === fn) {\n cbs.splice(i, 1);\n break;\n }\n }\n }\n return this;\n }\n $emit(event, ...args) {\n const cbs = this._events[event];\n if (cbs) {\n [...cbs].forEach((cb) => cb.apply(this.$parent, args));\n }\n return this;\n }\n /**\n *\n * @param expOrFn\n * @param cb\n * @param options\n */\n $watch(expOrFn, cb, options) {\n if (Object(_util_index__WEBPACK_IMPORTED_MODULE_4__[\"isPlainObject\"])(cb)) {\n return this._createWatcher(expOrFn, cb, options);\n }\n options = options || {};\n const watcher = new _observer_watcher__WEBPACK_IMPORTED_MODULE_1__[\"default\"](this, expOrFn, cb, options);\n return function unwatchFn() {\n watcher.teardown();\n };\n }\n $callHook(name, ...rest) {\n // 阻断所有数据变动\n Object(_observer_dep__WEBPACK_IMPORTED_MODULE_3__[\"pushTarget\"])();\n if ('function' === typeof this.$options[name]) {\n this.$options[name].call(this, ...rest);\n }\n if (this._hasHookEvent) {\n this.$emit('hook:' + name);\n }\n Object(_observer_dep__WEBPACK_IMPORTED_MODULE_3__[\"popTarget\"])();\n }\n /**\n * 强制刷新\n */\n $forceUpdate() {\n if (this._watcher) {\n this._watcher.update();\n }\n }\n /**\n * 挂载\n * @param { egret.DisplayObjectContainer } parent 挂载对象\n * @return { Component }\n */\n $mount(parent) {\n if (parent instanceof egret.DisplayObjectContainer && this.$el) {\n parent.addChild(this.$el);\n }\n return this;\n }\n /**\n * 销毁\n * @description 销毁对象\n * @author Hsuna\n */\n $destroy() {\n if (this._isBeingDestroyed)\n return;\n this.$callHook('beforeDestroy');\n this._isBeingDestroyed = true;\n // 从parent列表中移除\n if (this.$parent && !this.$parent._isBeingDestroyed) {\n const index = this.$parent.$children.indexOf(this);\n if (index > -1)\n this.$parent.$children.splice(index, 1);\n }\n // 销毁观察器\n if (this._watcher) {\n this._watcher.teardown();\n this._watcher = null;\n this._watchers = null;\n }\n // 销毁渲染器\n if (this._render) {\n this._render.destroy();\n this._render = null;\n }\n // 销毁内部事件\n if (this._events) {\n this._events = null;\n }\n this._isDestroyed = true;\n this.$callHook('destroyed');\n }\n /**\n * 通过挂载名或者组件,获取实际的显示对象\n * @param { ComponentRef } ref 显示对象名\n * @param { boolean } isAll 是否返回全部,如果选是,则返回数组对象\n * @return { TArray<egret.DisplayObject> }\n */\n $displayObject(ref, isAll) {\n if ('string' === typeof ref) {\n // 挂载名\n const refs = this.$refs[ref];\n if (Array.isArray(refs)) {\n if (isAll)\n return refs.map((ref) => this.$displayObject(ref));\n return this.$displayObject(refs[0]);\n }\n return this.$displayObject(refs);\n }\n else if (ref instanceof Component) {\n // 组件\n return ref.$el;\n }\n else if (ref instanceof egret.DisplayObject) {\n // 显示对象本身\n return ref;\n }\n return null;\n }\n /**\n * 碰撞检测\n * @description 用于检测两个显示对象间是否存在碰撞\n * @author Hsuna\n * @param { ComponentRef } ref1 显示对象1\n * @param { ComponentRef } ref2 显示对象2\n * @return { boolean }\n */\n $hitTest(ref1, ref2) {\n const disObj1 = this.$displayObject(ref1);\n const disObj2 = this.$displayObject(ref2);\n if (!disObj1 || !disObj2)\n return true;\n const rect1 = disObj1.getBounds();\n const rect2 = disObj2.getBounds();\n (rect1.x = disObj1.x), (rect1.y = disObj1.y);\n (rect2.x = disObj2.x), (rect2.y = disObj2.y);\n return rect1.intersects(rect2);\n }\n /**\n * 坐标点碰撞检测\n * @description 用于检测坐标点是否在对象内\n * @author Hsuna\n * @param { ComponentRef } ref 显示对象\n * @param { number } x 坐标X\n * @param { number } y 坐标Y\n * @param { boolean } shapeFlag 是否采用像素值检测\n * @return { boolean }\n */\n $hitTestPoint(ref, x, y, shapeFlag) {\n const disObj = this.$displayObject(ref);\n return disObj ? disObj.hitTestPoint(x, y, shapeFlag) : false;\n }\n /**\n * 将全局坐标转化为本地坐标\n * @param { ComponentRef } ref 显示对象\n * @param { number } stateX 全局坐标X\n * @param { number } stateY 全局坐标Y\n * @return { egret.Point } 本地坐标\n */\n $globalToLocal(ref, stateX, stateY) {\n const disObj = this.$displayObject(ref);\n const resultPoint = new egret.Point(stateX, stateY);\n disObj && disObj.globalToLocal(stateX, stateY, resultPoint);\n return resultPoint;\n }\n /**\n * 将本地坐标转化为全局坐标\n * @param { ComponentRef } ref 显示对象\n * @param { number } localX 本地坐标X\n * @param { number } localY 本地坐标Y\n * @return { egret.Point } 全局坐标\n */\n $localToGlobal(ref, localX, localY) {\n const disObj = this.$displayObject(ref);\n const resultPoint = new egret.Point(localX, localY);\n disObj && disObj.localToGlobal(localX, localY, resultPoint);\n return resultPoint;\n }\n /**\n * 获取舞台信息\n * @return { egret.Stage }\n */\n get $stage() {\n return this._global.stage;\n }\n /**\n * 获取舞台宽度\n * @return { number }\n */\n get $stageWidth() {\n return this._global.stage.stageWidth;\n }\n /**\n * 获取舞台高度\n * @return { number }\n */\n get $stageHeight() {\n return this._global.stage.stageHeight;\n }\n get $data() {\n return this._data;\n }\n get $props() {\n return this._props;\n }\n /** 获取属性 */\n get $attrs() {\n return this._parentOptions.attrs || _util_index__WEBPACK_IMPORTED_MODULE_4__[\"emptyObject\"];\n }\n /** 获取事件 */\n get $listeners() {\n return this._parentOptions.listeners || _util_index__WEBPACK_IMPORTED_MODULE_4__[\"emptyObject\"];\n }\n}\n/**\n * VueEgret类\n * @description\n * @author Hsuna\n */\nclass VueEgret extends Component {\n constructor(options) {\n super(options);\n }\n /**\n * 设置全局组件\n * @param { string } name 组件名 用于全局定义\n * @param { ComponentOptions } options 组件配置\n */\n static component(name, options) {\n if (options)\n return (VueEgret._components[name] = VueEgret.extend(options));\n return VueEgret._components[name];\n }\n /**\n * 设置全局指令\n */\n static directive(name, definition) {\n if (definition)\n return (VueEgret._directives[name] =\n typeof definition === 'function' ? { bind: definition, update: definition } : definition);\n return VueEgret._directives[name];\n }\n /**\n * 通过配置,获取组件类型\n * @param { ComponentOptions } options\n */\n static extend(options) {\n var _a;\n if ('function' === typeof options)\n return options;\n return _a = class extends Component {\n constructor(parentOptions = {}) {\n super(options, parentOptions);\n }\n },\n _a.cid = VueEgret.cid++,\n _a.options = options,\n _a;\n }\n /**\n * 通过配置,获取主类\n * 由于egret启动是需要实例化Main类\n * @param { ComponentOptions } options\n */\n static classMain(options) {\n return class extends egret.DisplayObjectContainer {\n constructor() {\n super();\n this.vm = new VueEgret(options);\n this.vm.$mount(this);\n }\n };\n }\n}\n/** 组件id */\nVueEgret.cid = 0;\n/** 版本号 */\nVueEgret.version = process.env.VERSION;\n/** 组件库缓存 */\nVueEgret._components = {};\n/** 指令缓存 */\nVueEgret._directives = {};\nVueEgret.set = _observer_index__WEBPACK_IMPORTED_MODULE_2__[\"set\"];\nVueEgret.delete = _observer_index__WEBPACK_IMPORTED_MODULE_2__[\"del\"];\nVueEgret.nextTick = _util_next_tick__WEBPACK_IMPORTED_MODULE_6__[\"nextTick\"];\n\n/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../node_modules/process/browser.js */ \"./node_modules/process/browser.js\")))\n\n//# sourceURL=webpack://%5Bname%5D/./src/index.ts?"); /***/ }), /***/ "./src/observer/array.ts": /*!*******************************!*\ !*** ./src/observer/array.ts ***! \*******************************/ /*! exports provided: arrayMethods, arrayKeys */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"arrayMethods\", function() { return arrayMethods; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"arrayKeys\", function() { return arrayKeys; });\n/* harmony import */ var _util_index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../util/index */ \"./src/util/index.ts\");\n/*\n * not type checking this file because flow doesn't play well with\n * dynamically accessing methods on Array prototype\n */\n\nconst arrayProto = Array.prototype;\nconst arrayMethods = Object.create(arrayProto);\nconst arrayKeys = Object.getOwnPropertyNames(arrayMethods);\nconst methodsToPatch = ['push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse'];\n/**\n * Intercept mutating methods and emit events\n */\nmethodsToPatch.forEach(function (method) {\n // cache original method\n const original = arrayProto[method];\n Object(_util_index__WEBPACK_IMPORTED_MODULE_0__[\"def\"])(arrayMethods, method, function mutator(...args) {\n const result = original.apply(this, args);\n const ob = this.__ob__;\n let inserted;\n switch (method) {\n case 'push':\n case 'unshift':\n inserted = args;\n break;\n case 'splice':\n inserted = args.slice(2);\n break;\n }\n if (inserted)\n ob.observeArray(inserted);\n // notify change\n ob.dep.notify();\n return result;\n });\n});\n\n\n//# sourceURL=webpack://%5Bname%5D/./src/observer/array.ts?"); /***/ }), /***/ "./src/observer/dep.ts": /*!*****************************!*\ !*** ./src/observer/dep.ts ***! \*****************************/ /*! exports provided: default, pushTarget, popTarget */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"default\", function() { return Dep; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"pushTarget\", function() { return pushTarget; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"popTarget\", function() { return popTarget; });\n// dep实例的ID\nlet uid = 0;\nclass Dep {\n constructor() {\n this.id = uid++;\n this.subs = [];\n }\n depend() {\n if (Dep.target) {\n Dep.target.addDep(this);\n }\n }\n addSub(sub) {\n this.subs.push(sub);\n }\n removeSub(sub) {\n const index = this.subs.indexOf(sub);\n if (index > -1) {\n this.subs.splice(index, 1);\n }\n }\n notify() {\n this.subs.forEach((e) => {\n e.update();\n });\n }\n}\n// The current target watcher being evaluated.\n// This is globally unique because only one watcher\n// can be evaluated at a time.\nDep.target = null;\nconst targetStack = [];\nfunction pushTarget(target) {\n targetStack.push(target);\n Dep.target = target;\n}\nfunction popTarget() {\n targetStack.pop();\n Dep.target = targetStack[targetStack.length - 1];\n}\n\n\n//# sourceURL=webpack://%5Bname%5D/./src/observer/dep.ts?"); /***/ }), /***/ "./src/observer/index.ts": /*!*******************************!*\ !*** ./src/observer/index.ts ***! \*******************************/ /*! exports provided: default, defineReactive, observe, set, del */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"default\", function() { return Observer; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"defineReactive\", function() { return defineReactive; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"observe\", function() { return observe; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"set\", function() { return set; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"del\", function() { return del; });\n/* harmony import */ var _util_index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../util/index */ \"./src/util/index.ts\");\n/* harmony import */ var _array__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./array */ \"./src/observer/array.ts\");\n/* harmony import */ var _dep__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./dep */ \"./src/observer/dep.ts\");\n\n\n\nclass Observer {\n constructor(value) {\n this.value = value;\n this.dep = new _dep__WEBPACK_IMPORTED_MODULE_2__[\"default\"]();\n this.vmCount = 0;\n Object(_util_index__WEBPACK_IMPORTED_MODULE_0__[\"def\"])(value, '__ob__', this);\n if (Array.isArray(value)) {\n if (_util_index__WEBPACK_IMPORTED_MODULE_0__[\"hasProto\"]) {\n protoAugment(value, _array__WEBPACK_IMPORTED_MODULE_1__[\"arrayMethods\"]);\n }\n else {\n copyAugment(value, _array__WEBPACK_IMPORTED_MODULE_1__[\"arrayMethods\"], _array__WEBPACK_IMPORTED_MODULE_1__[\"arrayKeys\"]);\n }\n value.forEach((item) => observe(item));\n }\n else {\n this.walk(value);\n }\n }\n /**\n * Walk through all properties and convert them into\n * getter/setters. This method should only be called when\n * value type is Object.\n */\n walk(obj) {\n for (const key in obj) {\n defineReactive(obj, key);\n }\n }\n /**\n * Observe a list of Array items.\n */\n observeArray(items) {\n items.forEach((item) => observe(item));\n }\n}\n/**\n * Define a reactive property on an Object.\n */\nfunction defineReactive(obj, key, val) {\n const dep = new _dep__WEBPACK_IMPORTED_MODULE_2__[\"default\"]();\n const property = Object.getOwnPropertyDescriptor(obj, key);\n if (property && property.configurable === false) {\n return;\n }\n // cater for pre-defined getter/setters\n const getter = property && property.get;\n const setter = property && property.set;\n if ((!getter || setter) && arguments.length === 2) {\n val = obj[key];\n }\n let childOb = observe(val);\n Object.defineProperty(obj, key, {\n enumerable: true,\n configurable: true,\n get() {\n const value = getter ? getter.call(obj) : val;\n if (_dep__WEBPACK_IMPORTED_MODULE_2__[\"default\"].target) {\n dep.depend();\n if (childOb) {\n childOb.dep.depend();\n if (Array.isArray(value)) {\n dependArray(value);\n }\n }\n }\n return value;\n },\n set(newVal) {\n const value = getter ? getter.call(obj) : val;\n /* eslint-disable no-self-compare */\n if (newVal === value || (newVal !== newVal && value !== value)) {\n return;\n }\n /* try {\n if (\n (Array.isArray(newVal) || isPlainObject(newVal)) &&\n Object.isExtensible(newVal) &&\n !(newVal instanceof egret.HashObject) &&\n !newVal._isVue\n ) {\n // 复杂类型的比较,如果复杂类型数据没有不同,只是引用不一的话,则不更新\n return;\n }\n } catch (e) {\n // TODO\n console.log(e);\n } */\n // #7981: for accessor properties without setter\n if (getter && !setter)\n return;\n if (setter) {\n setter.call(obj, newVal);\n }\n else {\n val = newVal;\n }\n childOb = observe(newVal);\n dep.notify();\n },\n });\n}\n/**\n * Attempt to create an observer instance for a value,\n * returns the new observer if successfully observed,\n * or the existing observer if the value already has one.\n */\nfunction observe(value, asRootData) {\n if (!Object(_util_index__WEBPACK_IMPORTED_MODULE_0__[\"isObject\"])(value))\n return;\n let ob;\n if (Object(_util_index__WEBPACK_IMPORTED_MODULE_0__[\"hasOwn\"])(value, '__ob__') && value.__ob__ instanceof Observer) {\n ob = value.__ob__;\n }\n else if ((Array.isArray(value) || Object(_util_index__WEBPACK_IMPORTED_MODULE_0__[\"isPlainObject\"])(value)) &&\n Object.isExtensible(value) &&\n !(value instanceof egret.HashObject) &&\n !value._isVue) {\n ob = new Observer(value);\n }\n if (asRootData && ob) {\n ob.vmCount++;\n }\n return ob;\n}\n/**\n * Set a property on an object. Adds the new property and\n * triggers change notification if the property doesn't\n * already exist.\n */\nfunction set(target, key, val) {\n if (Array.isArray(target) && Object(_util_index__WEBPACK_IMPORTED_MODULE_0__[\"isValidArrayIndex\"])(key)) {\n target.length = Math.max(target.length, key);\n target.splice(key, 1, val);\n return val;\n }\n if (key in target && !(key in Object.prototype)) {\n target[key] = val;\n return val;\n }\n const ob = target.__ob__;\n if (target._isVue || (ob && ob.vmCount)) {\n console.warn('Avoid adding reactive properties to a Vue instance or its root $data at runtime - declare it upfront in the data option.');\n return val;\n }\n if (!ob) {\n target[key] = val;\n return val;\n }\n defineReactive(ob.value, key, val);\n ob.dep.notify();\n return val;\n}\n/**\n * Delete a property and trigger change if necessary.\n */\nfunction del(target, key) {\n if (Array.isArray(target) && Object(_util_index__WEBPACK_IMPORTED_MODULE_0__[\"isValidArrayIndex\"])(key)) {\n target.splice(key, 1);\n return;\n }\n const ob = target.__ob__;\n if (target._isVue || (ob && ob.vmCount)) {\n console.warn('Avoid deleting properties on a Vue instance or its root $data - just set it to null.');\n return;\n }\n if (!Object(_util_index__WEBPACK_IMPORTED_MODULE_0__[\"hasOwn\"])(target, key)) {\n return;\n }\n delete target[key];\n if (!ob) {\n return;\n }\n ob.dep.notify();\n}\n/**\n * Collect dependencies on array elements when the array is touched, since\n * we cannot intercept array element access like property getters.\n */\nfunction dependArray(arr) {\n arr.forEach((e) => {\n e && e.__ob__ && e.__ob__.dep.depend();\n if (Array.isArray(e)) {\n dependArray(e);\n }\n });\n}\n/**\n * Augment a target Object or Array by intercepting\n * the prototype chain using __proto__\n */\nfunction protoAugment(target, src) {\n /* eslint-disable no-proto */\n target.__proto__ = src;\n /* eslint-enable no-proto */\n}\n/**\n * Augment a target Object or Array by defining\n * hidden properties.\n */\n/* istanbul ignore next */\nfunction copyAugment(target, src, keys) {\n for (let i = 0, l = keys.length; i < l; i++) {\n const key = keys[i];\n Object(_util_index__WEBPACK_IMPORTED_MODULE_0__[\"def\"])(target, key, src[key]);\n }\n}\n\n\n//# sourceURL=webpack://%5Bname%5D/./src/observer/index.ts?"); /***/ }), /***/ "./src/observer/scheduler.ts": /*!***********************************!*\ !*** ./src/observer/scheduler.ts ***! \***********************************/ /*! exports provided: MAX_UPDATE_COUNT, currentFlushTimestamp, queueWatcher */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"MAX_UPDATE_COUNT\", function() { return MAX_UPDATE_COUNT; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"currentFlushTimestamp\", function() { return currentFlushTimestamp; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"queueWatcher\", function() { return queueWatcher; });\n/* harmony import */ var src_util_next_tick__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! src/util/next-tick */ \"./src/util/next-tick.ts\");\n\nconst MAX_UPDATE_COUNT = 100;\nconst queue = [];\nconst activatedChildren = [];\nlet has = {};\nlet waiting = false;\nlet flushing = false;\nlet index = 0;\n/**\n * Reset the scheduler's state.\n */\nfunction resetSchedulerState() {\n index = queue.length = activatedChildren.length = 0;\n has = {};\n waiting = flushing = false;\n}\n// Async edge case #6566 requires saving the timestamp when event listeners are\n// attached. However, calling performance.now() has a perf overhead especially\n// if the page has thousands of event listeners. Instead, we take a timestamp\n// every time the scheduler flushes and use that for all event listeners\n// attached during that flush.\nlet currentFlushTimestamp = 0;\n// Async edge case fix requires storing an event listener's attach timestamp.\nconst getNow = Date.now;\n/**\n * Flush both queues and run the watchers.\n */\nfunction flushSchedulerQueue() {\n currentFlushTimestamp = getNow();\n flushing = true;\n let watcher, id;\n // Sort queue before flush.\n // This ensures that:\n // 1. Components are updated from parent to child. (because parent is always\n // created before the child)\n // 2. A component's user watchers are run before its render watcher (because\n // user watchers are created before the render watcher)\n // 3. If a component is destroyed during a parent component's watcher run,\n // its watchers can be ski