UNPKG

coolink

Version:

Coocaa Coolink APP JavaScript library

1,313 lines (1,296 loc) 168 kB
// /* eslint-disable */ /****************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } var __assign = function() { __assign = Object.assign || function __assign(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; function __awaiter(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } function __generator(thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } } function __spreadArray(to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); } var MODAL_TAG = 'modal#'; var PageContainer = (function () { function PageContainer(contextId) { this.namesCache = []; this.pageNamesCache = []; this.modalNamesCache = []; this.nodeDataCache = new Map(); this.pagePerformanceInfos = new Map(); this.contextId = contextId; } PageContainer.pageIsModal = function (pageName) { return pageName && pageName.startsWith(MODAL_TAG); }; PageContainer.formatModalName = function (modalName) { return "".concat(MODAL_TAG).concat((modalName || Date.now().toString())); }; Object.defineProperty(PageContainer.prototype, "isEmpty", { get: function () { return this.namesCache.length === 0; }, enumerable: false, configurable: true }); Object.defineProperty(PageContainer.prototype, "canPop", { get: function () { return this.namesCache.length > 1; }, enumerable: false, configurable: true }); Object.defineProperty(PageContainer.prototype, "currentShowIsModal", { get: function () { if (this.isEmpty) return false; return PageContainer.pageIsModal(this.namesCache[0]); }, enumerable: false, configurable: true }); Object.defineProperty(PageContainer.prototype, "currentShowName", { get: function () { if (this.isEmpty) return; return this.namesCache[0]; }, enumerable: false, configurable: true }); Object.defineProperty(PageContainer.prototype, "currentPageName", { get: function () { if (this.isEmpty) return; return this.pageNamesCache[0]; }, enumerable: false, configurable: true }); Object.defineProperty(PageContainer.prototype, "currentPageData", { get: function () { var pageName = this.currentPageName; if (!pageName) return; return this.nodeDataCache.get(pageName); }, enumerable: false, configurable: true }); Object.defineProperty(PageContainer.prototype, "referPageName", { get: function () { if (this.pageNamesCache.length < 2) return; return this.pageNamesCache[1]; }, enumerable: false, configurable: true }); PageContainer.prototype.destroy = function () { var name = this.namesCache.shift(); while (name) { this.nodeDataCache.get(name).invokeLifeCycle(LifeCycle.widgetDidUnmount); name = this.namesCache.shift(); } this.pageNamesCache = []; this.modalNamesCache = []; this.nodeDataCache.clear(); this.pagePerformanceInfos.clear(); }; PageContainer.prototype.hasPage = function (pageName, includeModal) { if (includeModal === void 0) { includeModal = false; } if (!includeModal) return this.pageNamesCache.indexOf(pageName) > -1; return this.namesCache.indexOf(pageName) > -1; }; PageContainer.prototype.pushPage = function (pageName, vnodeTree, createTimestamp) { if (this.namesCache.includes(pageName)) throw new Error("Route name \"".concat(pageName, "\" has already exist!")); this.namesCache.unshift(pageName); this.pageNamesCache.unshift(pageName); this.nodeDataCache.set(pageName, vnodeTree); this.pagePerformanceInfos.set(pageName, { hasReported: false, createTimestamp: createTimestamp, }); }; PageContainer.prototype.showModal = function (modalName, vnodeTree) { if (this.namesCache.includes(modalName)) throw new Error("Route name \"".concat(modalName, "\" has already exist!")); this.namesCache.unshift(modalName); this.nodeDataCache.set(modalName, vnodeTree); this.modalNamesCache.unshift(modalName); }; PageContainer.prototype.removeCurrentShow = function () { if (this.isEmpty) return; var name = this.namesCache.shift(); if (!PageContainer.pageIsModal(name)) this.pageNamesCache.shift(); else this.modalNamesCache.shift(); this.nodeDataCache.delete(name); this.pagePerformanceInfos.delete(name); }; PageContainer.prototype.getPageData = function (pageName) { if (!pageName) return; if (this.nodeDataCache.has(pageName)) return this.nodeDataCache.get(pageName); }; PageContainer.prototype.setPagePerformanceInfo = function (pageName, loadTimestamp) { var currentPerformanceInfo = this.getPagePerformanceInfo(pageName); if (!currentPerformanceInfo || currentPerformanceInfo.hasReported || currentPerformanceInfo.loadTimestamp) return; currentPerformanceInfo.loadTimestamp = loadTimestamp; }; PageContainer.prototype.getPagePerformanceInfo = function (pageName) { return this.pagePerformanceInfos.get(pageName || this.currentPageName || ''); }; return PageContainer; }()); var AppContainer = (function () { function AppContainer() { this._pageId = 0; this.routes = new Map(); this.pageContainerContextIds = []; this.pageContainers = new Map(); } AppContainer.prototype.clear = function () { this._pageId = 0; while (this.currentPageContainer) { this.destroyPageContainer(); } }; AppContainer.prototype.addRoute = function (routeName, pageBuilder) { if (this.routes.has(routeName)) throw new Error("Route name \"".concat(routeName, "\" has already exist!")); this.routes.set(routeName, pageBuilder); }; AppContainer.prototype.hasRoute = function (routeName) { return this.routes.has(routeName); }; AppContainer.prototype.getRoute = function (routeName) { if (!this.hasRoute(routeName)) return; return this.routes.get(routeName); }; Object.defineProperty(AppContainer.prototype, "contextId", { get: function () { if (this.isEmpty) return; return this._contextId || this.pageContainerContextIds[0]; }, set: function (currentId) { if (!currentId) return; if (!this.pageContainerContextIds.includes(currentId)) return; this._contextId = currentId; }, enumerable: false, configurable: true }); Object.defineProperty(AppContainer.prototype, "pageId", { get: function () { return ++this._pageId; }, enumerable: false, configurable: true }); Object.defineProperty(AppContainer.prototype, "isEmpty", { get: function () { return this.pageContainerCount === 0; }, enumerable: false, configurable: true }); Object.defineProperty(AppContainer.prototype, "canPop", { get: function () { var _a; if (this.isEmpty) return false; return ((_a = this.currentPageContainer) === null || _a === void 0 ? void 0 : _a.canPop) || false; }, enumerable: false, configurable: true }); Object.defineProperty(AppContainer.prototype, "pageContainerCount", { get: function () { return this.pageContainers.size; }, enumerable: false, configurable: true }); Object.defineProperty(AppContainer.prototype, "currentPageContainer", { get: function () { if (this.isEmpty) return; return this.pageContainers.get(this.contextId); }, enumerable: false, configurable: true }); Object.defineProperty(AppContainer.prototype, "currentShowIsModal", { get: function () { if (this.isEmpty) return false; return this.currentPageContainer.currentShowIsModal; }, enumerable: false, configurable: true }); Object.defineProperty(AppContainer.prototype, "currentShowName", { get: function () { if (this.isEmpty) return; return this.currentPageContainer.currentShowName; }, enumerable: false, configurable: true }); Object.defineProperty(AppContainer.prototype, "currentPageName", { get: function () { if (this.isEmpty) return; return this.currentPageContainer.currentPageName; }, enumerable: false, configurable: true }); Object.defineProperty(AppContainer.prototype, "currentPageData", { get: function () { if (this.isEmpty) return; return this.currentPageContainer.currentPageData; }, enumerable: false, configurable: true }); Object.defineProperty(AppContainer.prototype, "referPageName", { get: function () { if (this.isEmpty) return; var referPageName = this.currentPageContainer.referPageName; if (referPageName || this.pageContainerCount === 1) return referPageName; var prevContextId = this.pageContainerContextIds[1]; var prevPageContainer = this.pageContainers.get(prevContextId); if (!prevPageContainer) return; return prevPageContainer.currentPageName; }, enumerable: false, configurable: true }); AppContainer.prototype.createPageContainer = function (contextId) { this._contextId = contextId; this.pageContainerContextIds.unshift(contextId); this.pageContainers.set(contextId, new PageContainer(contextId)); }; AppContainer.prototype.destroyPageContainer = function (contextId) { if (!contextId) contextId = this.currentPageContainer.contextId; var targetPageContainer = this.pageContainers.get(contextId); if (targetPageContainer) { targetPageContainer.destroy(); this.pageContainers.delete(contextId); } var index = this.pageContainerContextIds.indexOf(contextId); if (index > -1) this.pageContainerContextIds.splice(index, 1); this._contextId = undefined; }; AppContainer.prototype.pageIsModal = function (pageName) { return PageContainer.pageIsModal(pageName); }; AppContainer.prototype.formatModalName = function (modalName) { return PageContainer.formatModalName(modalName); }; AppContainer.prototype.hasPage = function (pageName, withModal) { if (withModal === void 0) { withModal = false; } if (this.isEmpty) return false; var containerCount = this.pageContainerCount; for (var i = 0; i < containerCount; i++) { var contextId = this.pageContainerContextIds[i]; var targetPageContainer = this.pageContainers.get(contextId); var exist = targetPageContainer.hasPage(pageName, withModal); if (exist) return true; } return false; }; AppContainer.prototype.pushPage = function (pageName, vnodeTree, createTimestamp) { if (this.isEmpty) return; this.currentPageContainer.pushPage(pageName, vnodeTree, createTimestamp); }; AppContainer.prototype.showModal = function (modalName, vnodeTree) { if (this.isEmpty) return; this.currentPageContainer.showModal(modalName, vnodeTree); }; AppContainer.prototype.removeCurrentShow = function () { if (this.isEmpty) return; this.currentPageContainer.removeCurrentShow(); }; AppContainer.prototype.getPageDataWithPageName = function (pageName) { if (this.isEmpty) return; var containerCount = this.pageContainerCount; for (var i = 0; i < containerCount; i++) { var contextId = this.pageContainerContextIds[i]; var targetPageContainer = this.pageContainers.get(contextId); var pageData = targetPageContainer.getPageData(pageName); if (pageData) return pageData; } }; AppContainer.prototype.pageContainerExisted = function (contextId) { return this.pageContainerContextIds.includes(contextId); }; AppContainer.prototype.getPageDataWithContextId = function (contextId) { if (this.isEmpty) return; var targetPageContainer = this.pageContainers.get(contextId); if (!targetPageContainer) return; return targetPageContainer.currentPageData; }; AppContainer.prototype.getPageContainerWithPageName = function (pageName) { if (this.isEmpty) return; var containerCount = this.pageContainerCount; for (var i = 0; i < containerCount; i++) { var contextId = this.pageContainerContextIds[i]; var targetPageContainer = this.pageContainers.get(contextId); var exist = targetPageContainer.hasPage(pageName); if (exist) return targetPageContainer; } return; }; AppContainer.prototype.setPagePerformanceInfo = function (pageName, loadTimestamp) { var targetPageContainer = this.getPageContainerWithPageName(pageName); if (!targetPageContainer) return; targetPageContainer.setPagePerformanceInfo(pageName, loadTimestamp); }; AppContainer.prototype.getPagePerformanceInfo = function (pageName) { var targetPageContainer = pageName ? this.getPageContainerWithPageName(pageName) : this.currentPageContainer; if (!targetPageContainer) return; return targetPageContainer.getPagePerformanceInfo(pageName); }; return AppContainer; }()); var appContainer = new AppContainer(); var Bus = (function () { function Bus() { this._busId = 0; this._pool = {}; } Bus.prototype.register = function (callback, name) { if (!Util$1.isFunc(callback)) return; var busName = name ? name.toString() : (++this._busId).toString(); if (!this._pool[busName]) this._pool[busName] = []; this._pool[busName].push(callback); return busName; }; Bus.prototype.fire = function (name) { var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } if (!name) return; var callbacks = this._pool[name]; if (!callbacks || !callbacks.length) return; return callbacks.map(function (callback) { return callback.apply(void 0, args); }); }; Bus.prototype.has = function (name, callback) { if (!name || !this._pool[name]) return false; if (!callback) return true; var callbacks = this._pool[name]; var index = callbacks.indexOf(callback); return index > -1; }; Bus.prototype.remove = function (name, callback) { if (!name || !this._pool[name]) return; if (!callback) { delete this._pool[name]; return; } var callbacks = this._pool[name]; var index = callbacks.indexOf(callback); if (index > -1) callbacks.splice(index, 1); }; Bus.prototype.clear = function () { this._busId = 0; this._pool = {}; }; return Bus; }()); var bus = new Bus(); var TimerType; (function (TimerType) { TimerType[TimerType["timeout"] = 0] = "timeout"; TimerType[TimerType["interval"] = 1] = "interval"; })(TimerType || (TimerType = {})); var TimerManager = (function () { function TimerManager() { } TimerManager.setTimeout = function (callback, duration) { if (duration === void 0) { duration = 0; } return TimerManager.registerTimer(TimerType.timeout, callback, duration); }; TimerManager.setInterval = function (callback, duration) { if (duration === void 0) { duration = 0; } return TimerManager.registerTimer(TimerType.interval, callback, duration); }; TimerManager.clearTimer = function (timerId) { if (!timerId) return; bus.remove(timerId); methodChannel_timer_operator({ type: 'clear', id: timerId, }); var index = TimerManager._timerIds.indexOf(timerId); if (index > -1) TimerManager._timerIds.splice(index, 1); }; TimerManager.fireTimer = function (timerId) { if (!timerId) return; bus.fire(timerId); }; TimerManager.clearAllTimers = function () { TimerManager._timerIds.forEach(TimerManager.clearTimer); }; TimerManager.registerTimer = function (type, callback, duration) { if (!Util$1.isFunc(callback)) return; if (!duration || duration < 0) duration = 0; var loop = type === TimerType.interval; var timerId = bus.register(loop ? callback : function () { callback(); TimerManager.clearTimer(timerId); }, this.timerId); methodChannel_timer_operator({ type: 'register', id: timerId, duration: duration, loop: loop, }); TimerManager._timerIds.push(timerId); return timerId; }; Object.defineProperty(TimerManager, "timerId", { get: function () { return "timer_".concat(Math.random().toString(16).replace('0', Date.now().toString())); }, enumerable: false, configurable: true }); TimerManager._timerIds = []; return TimerManager; }()); function methodChannel_timer_fire(params) { if (!params) return; var id = params.id; if (!id) return; TimerManager.fireTimer(id); } var ChildrenKey = 'children'; var VNode = (function () { function VNode(_a) { var type = _a.type, props = _a.props, widgetBuilder = _a.widgetBuilder, isBasicWidget = _a.isBasicWidget, childrenMapedName = _a.childrenMapedName, childrenIsArray = _a.childrenIsArray, parent = _a.parent, key = _a.key, ref = _a.ref; this.children = []; this.basicWidgetPropChildren = {}; this.childrenMapedName = ChildrenKey; this.childrenIsArray = true; this.events = {}; this.hasMount = false; this.contextId = appContainer.contextId; this.isPageNode = false; this.isNativeViewNode = false; this.isInputNode = false; this.shouldRender = true; this._refHasMount = false; this.type = type; this.props = props; this.widgetBuilder = widgetBuilder; this.isBasicWidget = isBasicWidget; this.childrenMapedName = childrenMapedName; this.childrenIsArray = childrenIsArray; this.parent = parent; this.key = key; this.ref = ref; this.nodeId = VNode.getNodeId(type); if (isBasicWidget) { this.isPageNode = type === 'Page'; this.isNativeViewNode = type === 'NativeView'; this.isInputNode = type === 'Input'; } if (this.isNativeViewNode) { this.nativeViewId = "".concat(this.nodeId, "#").concat(this.props.type, "#").concat(Date.now()); } this.findVNodeInProps(); } VNode.getNodeId = function (type) { return "".concat(type, "#").concat(++VNode.nodeIdIndex); }; VNode.prototype.findVNodeInProps = function () { var _this = this; var _loop_1 = function (key) { var item = this_1.props[key]; if (item instanceof VNode && this_1.isBasicWidget) { item.parent = this_1; this_1.basicWidgetPropChildren[key] = item; } if (Array.isArray(item)) { item.forEach(function (subItem) { if (subItem instanceof VNode) { subItem.parent = _this; if (key === ChildrenKey) _this.appendChild(subItem); else if (_this.isBasicWidget) _this.appendChildInArrayProps(subItem, key); } }); } }; var this_1 = this; for (var key in this.props) { _loop_1(key); } }; VNode.prototype.findEventsInProps = function () { var _this = this; if (!this.isBasicWidget) return; this.events = {}; var eventId = 0; VNode.eventTypes.forEach(function (key) { var prop = _this.props[key]; if (prop instanceof Function) { var eventCacheId = "event/".concat(++eventId); if (VNode.throttledEventTypes.includes(key)) prop = Util$1.throttle(prop); _this.events[eventCacheId] = prop; _this.props["_".concat(key, "Id")] = eventCacheId; } }); }; VNode.prototype.doRender = function () { if (!this.shouldRender) return; this.shouldRender = false; if (!this.widget) { this.widget = new this.widgetBuilder(this.props); this.widget.__vNode__ = this; } this.widget.props = this.props; if (!this.isBasicWidget) { var node = this.widget.render(); if (!node) throw new Error("Widget's render method must return a widget. Error in: <".concat(this.type, " />")); node.parent = this; this.children = [node]; } }; VNode.prototype.doUpdate = function () { if (!this.widget) { this.widget = new this.widgetBuilder(this.props); this.widget.__vNode__ = this; } var newRenderNode = this.widget.render(); if (!newRenderNode) throw new Error("Widget's render method must return a widget. Error in: <".concat(this.type, " />")); return newRenderNode; }; VNode.prototype.doMerge = function (oldNode) { this.contextId = oldNode.contextId; this.hasMount = true; this.nodeId = oldNode.nodeId; this.nativeViewId = oldNode.nativeViewId; this.widget = oldNode.widget; this.widget.__vNode__ = this; }; VNode.prototype.toRenderData = function (pageName, setStateful) { var _this = this; if (setStateful === void 0) { setStateful = true; } this.pageName = pageName; if (this.pageNode) this.pageNode = void 0; this.findEventsInProps(); this.doRender(); if (!this.isBasicWidget) { if (this.children.length) { var child = this.children[0]; if (Util$1.isNil(child.key)) child.parentKey = this.key || this.parentKey; return child.toRenderData(pageName, true); } } else { var childrenRenderData_1 = {}; this.mapChildren(function (vNode, key, fromArray) { if (!fromArray) childrenRenderData_1[key] = vNode.toRenderData(pageName, false); else { if (!childrenRenderData_1[key]) childrenRenderData_1[key] = []; childrenRenderData_1[key].push(vNode.toRenderData(pageName, false)); } if (key === ChildrenKey && !_this.childrenIsArray) { childrenRenderData_1[_this.childrenMapedName] = childrenRenderData_1[key][0]; delete childrenRenderData_1[key]; } }); if (this.isPageNode) { var rootNode = this.fetchRootNode(); rootNode.pageNode = this; } if (this.isNativeViewNode) { var params = this.props.params || {}; if (!params.__viewId__) { params.__viewId__ = this.nativeViewId; this.props.params = params; } } return { name: this.type, widgetId: this.nodeId, isStateful: setStateful, pageName: pageName, props: this.execPropsProvider(Object.assign({}, this.props, childrenRenderData_1)), key: this.key || this.parentKey }; } }; VNode.prototype.execPropsProvider = function (props) { var propsProviders = threshApp$2.providers.propsProvider || []; var index = propsProviders.length - 1; while (index > -1) { var provider = propsProviders[index--]; var tempProps = provider.propsProvider(props); if (tempProps) props = tempProps; } return props; }; VNode.prototype.fetch = function (targetNodeId) { if (this.nodeId === targetNodeId) return this; var targetVNode; this.mapChildren(function (vNode) { if (vNode.nodeId === targetNodeId) { targetVNode = vNode; return false; } targetVNode = vNode.fetch(targetNodeId); return !targetVNode; }); return targetVNode; }; VNode.prototype.fetchNearlyCanUpdateBasicNode = function () { var node = this.fetchNearlyCustomNode(); var firstChildNode = node.children[0]; while (firstChildNode && !firstChildNode.isBasicWidget) { firstChildNode = firstChildNode.children[0]; } return firstChildNode; }; VNode.prototype.fetchNearlyCustomNode = function () { if (!this.isBasicWidget) return this; var parent = this.parent; if (parent) return parent.fetchNearlyCustomNode(); return this; }; VNode.prototype.fetchNearlyBasicNode = function () { if (this.isBasicWidget) return this; return this.children[0].fetchNearlyBasicNode(); }; VNode.prototype.fetchRootNode = function () { if (!this.parent) return this; var parent = this.parent; if (parent) return parent.fetchRootNode(); return this; }; VNode.prototype.fetchNodePageName = function () { if (this.pageName) return this.pageName; if (this.parent) return this.parent.fetchNodePageName(); return ''; }; VNode.prototype.isSameAs = function (otherNode) { return this.type === otherNode.type && this.key === otherNode.key; }; VNode.prototype.invokeEvent = function (targetNodeId, eventId, eventType, params) { return __awaiter(this, void 0, void 0, function () { var targetNode, eventFn; var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: targetNode = this.fetch(targetNodeId); if (!targetNode) return [2]; eventFn = targetNode.events[eventId]; if (!eventFn) return [2]; if (!(!eventType || !VNode.asyncEventTypes.includes(eventType))) return [3, 1]; eventFn(params); return [3, 4]; case 1: _a.trys.push([1, , 3, 4]); return [4, eventFn(params)]; case 2: _a.sent(); return [3, 4]; case 3: TimerManager.setTimeout(function () { _this.stopAsyncEvent(targetNode, eventType); }, 32); return [7]; case 4: return [2]; } }); }); }; VNode.prototype.stopAsyncEvent = function (node, eventType) { if (!node || !eventType || !VNode.asyncEventTypes.includes(eventType)) return; if (node.type === 'ListView') { node.widget.stopAsyncOperate(eventType === 'onRefresh' ? 'refresh' : 'loadMore'); } }; VNode.prototype.invokeLifeCycle = function (lifeStep) { if (!this.widget || !LifeCycle.isExist(lifeStep)) return; var lifeStepIsDidUnmount = lifeStep === LifeCycle.widgetDidUnmount; if (!lifeStepIsDidUnmount) { this._invokeChildrenLifeCycle(lifeStep); } if (!this.hasMount && lifeStep === LifeCycle.widgetDidUpdate) { this.hasMount = true; this._invokeMountRef(); this.widget.widgetDidMount(); } else { this.hasMount = !lifeStepIsDidUnmount; this._invokeMountRef(); this.widget[lifeStep](); } if (lifeStepIsDidUnmount) { this._invokeChildrenLifeCycle(lifeStep); } }; VNode.prototype._invokeChildrenLifeCycle = function (lifeStep) { this.mapChildren(function (vNode) { vNode.invokeLifeCycle(lifeStep); }); }; VNode.prototype._invokeMountRef = function () { if (!this.ref) return; if (this.hasMount && !this._refHasMount) { this.ref(this.widget); this._refHasMount = true; } else if (!this.hasMount && this._refHasMount) { this.ref(undefined); this._refHasMount = false; } }; VNode.prototype.appendChild = function (child, target) { if (target === void 0) { target = this.children; } if (target.includes(child)) this.removeChild(child); target.push(child); }; VNode.prototype.removeChild = function (child, target) { if (target === void 0) { target = this.children; } var removeIndex = target.indexOf(child); if (removeIndex > -1) target.splice(removeIndex, 1); }; VNode.prototype.appendChildInArrayProps = function (child, propName) { this.appendChild(child, this.getTargetChildrenArrayInPropChildren(propName)); }; VNode.prototype.mapChildren = function (cb, mapTarget) { if (!mapTarget) { for (var i = 0; i < this.children.length; i++) { var item = this.children[i]; if (item instanceof VNode && cb(item, ChildrenKey, true) === false) return; } for (var key in this.basicWidgetPropChildren) { var item = this.basicWidgetPropChildren[key]; if (!Array.isArray(item)) { if (item instanceof VNode && cb(item, key, false) === false) return; } else { for (var i = 0; i < item.length; i++) { if (item[i] instanceof VNode && cb(item[i], key, true) === false) return; } } } } else { if (Util$1.isArray(mapTarget)) { for (var i = 0; i < mapTarget.length; i++) { var item = mapTarget[i]; if (item instanceof VNode && cb(item, '', true) === false) return; } } else { for (var key in mapTarget) { var item = mapTarget[key]; if (!Array.isArray(item)) { if (item instanceof VNode && cb(item, key, false) === false) return; } else { for (var i = 0; i < item.length; i++) { if (item[i] instanceof VNode && cb(item[i], key, true) === false) return; } } } } } }; VNode.prototype.getTargetChildrenArrayInPropChildren = function (propName) { if (!this.basicWidgetPropChildren[propName]) this.basicWidgetPropChildren[propName] = []; return this.basicWidgetPropChildren[propName]; }; VNode.nodeIdIndex = 0; VNode.asyncEventTypes = [ 'onRefresh', 'onLoadMore', 'onStopBack', ]; VNode.eventTypes = __spreadArray([ 'onTap', 'onLongTap', 'onLongTapStart', 'onLongTapEnd', 'onPan', 'onScroll', 'onChange', 'onLoad', 'onLayout', 'onFocus', 'onBlur', 'onActionsOpen', 'onActionsClose', 'willDragStatusChange', 'onDragStatusChange', 'onDragPositionChange', 'onOpen', 'onSubmitted', 'onClicked', 'onEnterClicked', 'onRawKeyFocusChanged', 'dispatchKeyEvent' ], VNode.asyncEventTypes, true); VNode.throttledEventTypes = ['onTap']; return VNode; }()); var LifeCycle = (function () { function LifeCycle() { } LifeCycle.isExist = function (lifeStep) { return LifeCycle.lifes.indexOf(lifeStep) > -1; }; LifeCycle.lifes = [ 'widgetDidMount', 'widgetDidUpdate', 'widgetDidUnmount', 'pageDidPush', 'pageDidPop', 'pageDidPopNext', 'pageDidPushNext', ]; LifeCycle.widgetDidMount = LifeCycle.lifes[0]; LifeCycle.widgetDidUpdate = LifeCycle.lifes[1]; LifeCycle.widgetDidUnmount = LifeCycle.lifes[2]; LifeCycle.pageDidPush = LifeCycle.lifes[3]; LifeCycle.pageDidPop = LifeCycle.lifes[4]; LifeCycle.pageDidPopNext = LifeCycle.lifes[5]; LifeCycle.pageDidPushNext = LifeCycle.lifes[6]; return LifeCycle; }()); var Util = (function () { function Util() { } Object.defineProperty(Util, "isProd", { get: function () { return process.env.NODE_ENV === 'production'; }, enumerable: false, configurable: true }); Util.flutterVersionSmallerThan = function (flutterVersion) { var aimFlutterVersionNumber = Number(flutterVersion.split('.').splice(0, 3).join('')); if (isNaN(aimFlutterVersionNumber)) return true; var flutterVersionNumber = threshApp.flutterVersion ? Number(threshApp.flutterVersion.split('.').splice(0, 3).join('')) : 0; return flutterVersionNumber < aimFlutterVersionNumber; }; Util.randomId = function () { return Math.random().toString(16).replace('0.', ''); }; Util.isObject = function (value) { return Util.type(value) === '[object Object]'; }; Util.isArray = function (value) { return Util.type(value) === '[object Array]'; }; Util.type = function (value) { return Object.prototype.toString.call(value); }; Util.isBaseType = function (value) { return ['number', 'string', 'boolean', 'undefined'].includes(typeof value); }; Util.toFlatWidgetArray = function (source) { if (!source) return []; if (!Array.isArray(source)) return [source]; var target = []; if (source.length) { source.forEach(function (item) { if (!Array.isArray(item) && !Util.isNil(item)) target.push(item); else target = target.concat(Util.toFlatWidgetArray(item)); }); } return target; }; Util.merge = function () { var objectList = []; for (var _i = 0; _i < arguments.length; _i++) { objectList[_i] = arguments[_i]; } if (!objectList.length) return {}; return objectList.reduce(function (last, obj) { return Object.assign(last, Util.isObject(obj) ? obj : {}); }, {}); }; Util.isString = function (value) { return typeof value === 'string'; }; Util.toString = function (value, showUndefined) { var _a; if (showUndefined === void 0) { showUndefined = false; } if (Util.isNil(value)) return !showUndefined ? '' : 'undefined'; var res; if (Util.isString(value)) return value; if (value instanceof VNode) return "Widget ".concat(value.type); if (value instanceof Widget$1) return "Widget ".concat(((_a = value.__vNode__) === null || _a === void 0 ? void 0 : _a.type) || '[unknown]'); try { res = JSON.stringify(value); } catch (e) { res = value.toString(); } finally { if (Util.isNil(res)) res = Util.type(value); } return res; }; Util.anyToRawString = function () { var params = []; for (var _i = 0; _i < arguments.length; _i++) { params[_i] = arguments[_i]; } var content = ''; params.forEach(function (item, index) { var temp; if (item instanceof Error) { temp = Util.formatError(item); } else { temp = Util.toString(item, true); } if (index) temp = '\n\n\n' + temp; content += temp; }); return content; }; Util.isNil = function (value) { return value === undefined || value === null; }; Util.isFunc = function (value) { return value && (typeof value === 'function'); }; Util.formatError = function (error) { var eParams; eParams = { message: error.message, stack: error.stack, }; return Util.anyToRawString(eParams); }; Util.randomNumberInRange = function (max, min, precision) { if (min === void 0) { min = 0; } if (precision === void 0) { precision = 0; } return Number((Math.random() * (max - min + 1) + min).toFixed(precision)); }; Util.filterAllNilProps = function (value) { if (!Util.isObject(value)) return value; walk(value); return value; function walk(data) { for (var key in data) { var p = data[key]; if (Util.isNil(p)) delete data[key]; if (Util.isObject(p)) walk(p); } } }; Util.throttle = function (callback, delay) { if (delay === void 0) { delay = 500; } var last; return function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var current = Date.now(); if (last && current - last < delay) return; last = current; callback.apply(void 0, args); }; }; Util.log = function (content) { var t = Date.now(); BridgeManager$1.invoke({ module: 'base', method: 'log', params: { level: 2, tag: '[[Dynamic Flutter JS Log]]', content: "[".concat(t, "] - ").concat(content) } }); }; Util.promiseResolveHackForIos_10_0_x = function () { return Promise.resolve(); }; return Util; }()); var Util$1 = Util; var InfoType; (function (InfoType) { InfoType["log"] = "log"; InfoType["warn"] = "warn"; InfoType["error"] = "error"; InfoType["network"] = "network"; InfoType["bridge"] = "bridge"; InfoType["event"] = "event"; })(InfoType || (InfoType = {})); var DevtoolsManager = (function () { function DevtoolsManager() { this.pool = {}; } DevtoolsManager.prototype.show = function (type, content, title, contextId) { if (!threshApp$2 || !threshApp$2.debugMode) return; MethodChannel$1.call({ contextId: contextId, method: FlutterMethodChannelType.devtools, params: { type: type, title: title, content: content }, }); }; DevtoolsManager.prototype.log = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } if (!threshApp$2 || !threshApp$2.debugMode) return; this.show(InfoType.log, Util$1.anyToRawString.apply(Util$1, args)); }; DevtoolsManager.prototype.warn = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } if (!threshApp$2 || !threshApp$2.debugMode) return; this.show(InfoType.warn, Util$1.anyToRawString.apply(Util$1, args)); }; DevtoolsManager.prototype.error = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } if (!threshApp$2 || !threshApp$2.debugMode) return; this.show(InfoType.error, Util$1.anyToRawString.apply(Util$1, args)); }; DevtoolsManager.prototype.bridge = function (methodId, data, isRequest) { if (isRequest === void 0) { isRequest = false; } if (!threshApp$2 || !threshApp$2.debugMode) return; var bridgeParams; if (isRequest) { this.pool[methodId] = data; bridgeParams = data; } else { bridgeParams = this.pool[methodId]; delete this.pool[methodId]; } if (!bridgeParams) return; var module = bridgeParams.module, business = bridgeParams.business, method = bridgeParams.method, params = bridgeParams.params; if (BridgeManager$1.isNetworkRequest(bridgeParams)) { var showInfo = void 0; if (isRequest) { showInfo = __assign({ method: params.method }, (params.data || params.query || {})); } else { showInfo = __assign({ code: data.code, reason: data.reason }, ((Util$1.isString(data.data) || Util$1.isNil(data.data) || !Util$1.isObject(data.data)) ? { data: data.data } : data.data)); } this.network(params.url, showInfo, isRequest); return; } if (!threshApp$2 || !threshApp$2.debugMode) return; var logInfos = [isRequest ? 'Request' : 'Response', "Module: ".concat(module)]; if (business) logInfos.push("Business: ".concat(business)); logInfos.push("Method: ".concat(method)); logInfos.push("MethodId: ".concat(methodId)); this.show(InfoType.bridge, Util$1.anyToRawString(data), logInfos.join('\n')); }; DevtoolsManager.prototype.network = function (url, params, isRequest) { if (isRequest === void 0) { isRequest = false; } if (!threshApp$2 || !threshApp$2.debugMode) return; this.show(InfoType.network, Util$1.anyToRawString(params), "".concat(isRequest ? 'Request' : 'Response', "\n").concat(url)); }; return DevtoolsManager; }()); var devtools = new DevtoolsManager(); var BridgeManager = (function () { function BridgeManager() { } BridgeManager.invoke = function (params) { return __awaiter(this, void 0, void 0, function () {