blob: 7a71184032ce2006426636005a1b24c040676001 [file] [log] [blame]
/* WEEX JS RUNTIME 0.22.0, Build 2017-09-20 19:42. */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.WeexRuntime = factory());
}(this, (function () { 'use strict';
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/* eslint-disable */
// Production steps of ECMA-262, Edition 6, 22.1.2.1
// Reference: https://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.from
/* istanbul ignore if */
if (!Array.from) {
Array.from = (function() {
var toStr = Object.prototype.toString;
var isCallable = function(fn) {
return typeof fn === 'function' || toStr.call(fn) === '[object Function]';
};
var toInteger = function(value) {
var number = Number(value);
if (isNaN(number)) {
return 0;
}
if (number === 0 || !isFinite(number)) {
return number;
}
return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number));
};
var maxSafeInteger = Math.pow(2, 53) - 1;
var toLength = function(value) {
var len = toInteger(value);
return Math.min(Math.max(len, 0), maxSafeInteger);
};
// The length property of the from method is 1.
return function from(arrayLike/*, mapFn, thisArg */) {
// 1. Let C be the this value.
var C = this;
// 2. Let items be ToObject(arrayLike).
var items = Object(arrayLike);
// 3. ReturnIfAbrupt(items).
if (arrayLike == null) {
throw new TypeError('Array.from requires an array-like object - not null or undefined');
}
// 4. If mapfn is undefined, then let mapping be false.
var mapFn = arguments.length > 1 ? arguments[1] : void undefined;
var T;
if (typeof mapFn !== 'undefined') {
// 5. else
// 5. a If IsCallable(mapfn) is false, throw a TypeError exception.
if (!isCallable(mapFn)) {
throw new TypeError('Array.from: when provided, the second argument must be a function');
}
// 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined.
if (arguments.length > 2) {
T = arguments[2];
}
}
// 10. Let lenValue be Get(items, "length").
// 11. Let len be ToLength(lenValue).
var len = toLength(items.length);
// 13. If IsConstructor(C) is true, then
// 13. a. Let A be the result of calling the [[Construct]] internal method of C with an argument list containing the single item len.
// 14. a. Else, Let A be ArrayCreate(len).
var A = isCallable(C) ? Object(new C(len)) : new Array(len);
// 16. Let k be 0.
var k = 0;
// 17. Repeat, while k < len… (also steps a - h)
var kValue;
while (k < len) {
kValue = items[k];
if (mapFn) {
A[k] = typeof T === 'undefined' ? mapFn(kValue, k) : mapFn.call(T, kValue, k);
} else {
A[k] = kValue;
}
k += 1;
}
// 18. Let putStatus be Put(A, "length", len, true).
A.length = len;
// 20. Return A.
return A;
};
}());
}
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
var _global = createCommonjsModule(function (module) {
// 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
});
var _core = createCommonjsModule(function (module) {
var core = module.exports = { version: '2.5.0' };
if (typeof __e == 'number') { __e = core; } // eslint-disable-line no-undef
});
var _isObject = function (it) {
return typeof it === 'object' ? it !== null : typeof it === 'function';
};
var isObject = _isObject;
var _anObject = function (it) {
if (!isObject(it)) { throw TypeError(it + ' is not an object!'); }
return it;
};
var _fails = function (exec) {
try {
return !!exec();
} catch (e) {
return true;
}
};
// Thank's IE8 for his funny defineProperty
var _descriptors = !_fails(function () {
return Object.defineProperty({}, 'a', { get: function () { return 7; } }).a != 7;
});
var isObject$1 = _isObject;
var document$1 = _global.document;
// typeof document.createElement is 'object' in old IE
var is = isObject$1(document$1) && isObject$1(document$1.createElement);
var _domCreate = function (it) {
return is ? document$1.createElement(it) : {};
};
var _ie8DomDefine = !_descriptors && !_fails(function () {
return Object.defineProperty(_domCreate('div'), 'a', { get: function () { return 7; } }).a != 7;
});
// 7.1.1 ToPrimitive(input [, PreferredType])
var isObject$2 = _isObject;
// instead of the ES6 spec version, we didn't implement @@toPrimitive case
// and the second argument - flag - preferred type is a string
var _toPrimitive = function (it, S) {
if (!isObject$2(it)) { return it; }
var fn, val;
if (S && typeof (fn = it.toString) == 'function' && !isObject$2(val = fn.call(it))) { return val; }
if (typeof (fn = it.valueOf) == 'function' && !isObject$2(val = fn.call(it))) { return val; }
if (!S && typeof (fn = it.toString) == 'function' && !isObject$2(val = fn.call(it))) { return val; }
throw TypeError("Can't convert object to primitive value");
};
var anObject = _anObject;
var IE8_DOM_DEFINE = _ie8DomDefine;
var toPrimitive = _toPrimitive;
var dP$1 = Object.defineProperty;
var f = _descriptors ? Object.defineProperty : function defineProperty(O, P, Attributes) {
anObject(O);
P = toPrimitive(P, true);
anObject(Attributes);
if (IE8_DOM_DEFINE) { try {
return dP$1(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;
};
var _objectDp = {
f: f
};
var _propertyDesc = function (bitmap, value) {
return {
enumerable: !(bitmap & 1),
configurable: !(bitmap & 2),
writable: !(bitmap & 4),
value: value
};
};
var dP = _objectDp;
var createDesc = _propertyDesc;
var _hide = _descriptors ? function (object, key, value) {
return dP.f(object, key, createDesc(1, value));
} : function (object, key, value) {
object[key] = value;
return object;
};
var hasOwnProperty = {}.hasOwnProperty;
var _has = function (it, key) {
return hasOwnProperty.call(it, key);
};
var id = 0;
var px = Math.random();
var _uid = function (key) {
return 'Symbol('.concat(key === undefined ? '' : key, ')_', (++id + px).toString(36));
};
var _redefine = createCommonjsModule(function (module) {
var global = _global;
var hide = _hide;
var has = _has;
var SRC = _uid('src');
var TO_STRING = 'toString';
var $toString = Function[TO_STRING];
var TPL = ('' + $toString).split(TO_STRING);
_core.inspectSource = function (it) {
return $toString.call(it);
};
(module.exports = function (O, key, val, safe) {
var isFunction = typeof val == 'function';
if (isFunction) { has(val, 'name') || hide(val, 'name', key); }
if (O[key] === val) { return; }
if (isFunction) { has(val, SRC) || hide(val, SRC, O[key] ? '' + O[key] : TPL.join(String(key))); }
if (O === global) {
O[key] = val;
} else if (!safe) {
delete O[key];
hide(O, key, val);
} else if (O[key]) {
O[key] = val;
} else {
hide(O, key, val);
}
// add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative
})(Function.prototype, TO_STRING, function toString() {
return typeof this == 'function' && this[SRC] || $toString.call(this);
});
});
var _aFunction = function (it) {
if (typeof it != 'function') { throw TypeError(it + ' is not a function!'); }
return it;
};
// optional / simple context binding
var aFunction = _aFunction;
var _ctx = 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);
};
};
var global$1 = _global;
var core = _core;
var hide = _hide;
var redefine = _redefine;
var ctx = _ctx;
var PROTOTYPE = 'prototype';
var $export$1 = function (type, name, source) {
var IS_FORCED = type & $export$1.F;
var IS_GLOBAL = type & $export$1.G;
var IS_STATIC = type & $export$1.S;
var IS_PROTO = type & $export$1.P;
var IS_BIND = type & $export$1.B;
var target = IS_GLOBAL ? global$1 : IS_STATIC ? global$1[name] || (global$1[name] = {}) : (global$1[name] || {})[PROTOTYPE];
var exports = IS_GLOBAL ? core : core[name] || (core[name] = {});
var expProto = exports[PROTOTYPE] || (exports[PROTOTYPE] = {});
var key, own, out, exp;
if (IS_GLOBAL) { source = name; }
for (key in source) {
// contains in native
own = !IS_FORCED && target && target[key] !== undefined;
// export native or passed
out = (own ? target : source)[key];
// bind timers to global for call from export context
exp = IS_BIND && own ? ctx(out, global$1) : IS_PROTO && typeof out == 'function' ? ctx(Function.call, out) : out;
// extend global
if (target) { redefine(target, key, out, type & $export$1.U); }
// export
if (exports[key] != out) { hide(exports, key, exp); }
if (IS_PROTO && expProto[key] != out) { expProto[key] = out; }
}
};
global$1.core = core;
// type bitmap
$export$1.F = 1; // forced
$export$1.G = 2; // global
$export$1.S = 4; // static
$export$1.P = 8; // proto
$export$1.B = 16; // bind
$export$1.W = 32; // wrap
$export$1.U = 64; // safe
$export$1.R = 128; // real proto method for `library`
var _export = $export$1;
var toString$1 = {}.toString;
var _cof = function (it) {
return toString$1.call(it).slice(8, -1);
};
// fallback for non-array-like ES3 and non-enumerable old V8 strings
var cof = _cof;
// eslint-disable-next-line no-prototype-builtins
var _iobject = Object('z').propertyIsEnumerable(0) ? Object : function (it) {
return cof(it) == 'String' ? it.split('') : Object(it);
};
// 7.2.1 RequireObjectCoercible(argument)
var _defined = function (it) {
if (it == undefined) { throw TypeError("Can't call method on " + it); }
return it;
};
// to indexed object, toObject with fallback for non-array-like ES3 strings
var IObject$1 = _iobject;
var defined = _defined;
var _toIobject = function (it) {
return IObject$1(defined(it));
};
// 7.1.4 ToInteger
var ceil = Math.ceil;
var floor = Math.floor;
var _toInteger = function (it) {
return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it);
};
// 7.1.15 ToLength
var toInteger = _toInteger;
var min = Math.min;
var _toLength = function (it) {
return it > 0 ? min(toInteger(it), 0x1fffffffffffff) : 0; // pow(2, 53) - 1 == 9007199254740991
};
var toInteger$1 = _toInteger;
var max = Math.max;
var min$1 = Math.min;
var _toAbsoluteIndex = function (index, length) {
index = toInteger$1(index);
return index < 0 ? max(index + length, 0) : min$1(index, length);
};
// false -> Array#indexOf
// true -> Array#includes
var toIObject$1 = _toIobject;
var toLength = _toLength;
var toAbsoluteIndex = _toAbsoluteIndex;
var _arrayIncludes = function (IS_INCLUDES) {
return function ($this, el, fromIndex) {
var O = toIObject$1($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;
};
};
var global$2 = _global;
var SHARED = '__core-js_shared__';
var store = global$2[SHARED] || (global$2[SHARED] = {});
var _shared = function (key) {
return store[key] || (store[key] = {});
};
var shared = _shared('keys');
var uid = _uid;
var _sharedKey = function (key) {
return shared[key] || (shared[key] = uid(key));
};
var has = _has;
var toIObject = _toIobject;
var arrayIndexOf = _arrayIncludes(false);
var IE_PROTO = _sharedKey('IE_PROTO');
var _objectKeysInternal = 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;
};
// IE 8- don't enum bug keys
var _enumBugKeys = (
'constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf'
).split(',');
// 19.1.2.14 / 15.2.3.14 Object.keys(O)
var $keys = _objectKeysInternal;
var enumBugKeys = _enumBugKeys;
var _objectKeys = Object.keys || function keys(O) {
return $keys(O, enumBugKeys);
};
var f$1 = Object.getOwnPropertySymbols;
var _objectGops = {
f: f$1
};
var f$2 = {}.propertyIsEnumerable;
var _objectPie = {
f: f$2
};
// 7.1.13 ToObject(argument)
var defined$1 = _defined;
var _toObject = function (it) {
return Object(defined$1(it));
};
// 19.1.2.1 Object.assign(target, source, ...)
var getKeys = _objectKeys;
var gOPS = _objectGops;
var pIE = _objectPie;
var toObject = _toObject;
var IObject = _iobject;
var $assign = Object.assign;
// should work with symbols and should have deterministic property order (V8 bug)
var _objectAssign = !$assign || _fails(function () {
var A = {};
var B = {};
// eslint-disable-next-line no-undef
var S = Symbol();
var K = 'abcdefghijklmnopqrst';
A[S] = 7;
K.split('').forEach(function (k) { B[k] = k; });
return $assign({}, A)[S] != 7 || Object.keys($assign({}, B)).join('') != K;
}) ? function assign(target, source) {
var arguments$1 = arguments;
// eslint-disable-line no-unused-vars
var T = toObject(target);
var aLen = arguments.length;
var index = 1;
var getSymbols = gOPS.f;
var isEnum = pIE.f;
while (aLen > index) {
var S = IObject(arguments$1[index++]);
var keys = getSymbols ? getKeys(S).concat(getSymbols(S)) : getKeys(S);
var length = keys.length;
var j = 0;
var key;
while (length > j) { if (isEnum.call(S, key = keys[j++])) { T[key] = S[key]; } }
} return T;
} : $assign;
// 19.1.3.1 Object.assign(target, source)
var $export = _export;
$export($export.S + $export.F, 'Object', { assign: _objectAssign });
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/* eslint-disable */
// https://gist.github.com/WebReflection/5593554
/* istanbul ignore if */
if (!Object.setPrototypeOf) {
Object.setPrototypeOf = (function(Object, magic) {
var set;
function setPrototypeOf(O, proto) {
set.call(O, proto);
return O;
}
try {
// this works already in Firefox and Safari
set = Object.getOwnPropertyDescriptor(Object.prototype, magic).set;
set.call({}, null);
} catch (e) {
if (
// IE < 11 cannot be shimmed
Object.prototype !== {}[magic] ||
// neither can any browser that actually
// implemented __proto__ correctly
// (all but old V8 will return here)
{__proto__: null}.__proto__ === void 0
// this case means null objects cannot be passed
// through setPrototypeOf in a reliable way
// which means here a **Sham** is needed instead
) {
return;
}
// nodejs 0.8 and 0.10 are (buggy and..) fine here
// probably Chrome or some old Mobile stock browser
set = function(proto) {
this[magic] = proto;
};
// please note that this will **not** work
// in those browsers that do not inherit
// __proto__ by mistake from Object.prototype
// in these cases we should probably throw an error
// or at least be informed about the issue
setPrototypeOf.polyfill = setPrototypeOf(
setPrototypeOf({}, null),
Object.prototype
) instanceof Object;
// setPrototypeOf.polyfill === true means it works as meant
// setPrototypeOf.polyfill === false means it's not 100% reliable
// setPrototypeOf.polyfill === undefined
// or
// setPrototypeOf.polyfill == null means it's not a polyfill
// which means it works as expected
// we can even delete Object.prototype.__proto__;
}
return setPrototypeOf;
}(Object, '__proto__'));
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// fix Promise Problem on JSContext of iOS7~8
// @see https://bugs.webkit.org/show_bug.cgi?id=135866
var ref = commonjsGlobal;
var WXEnvironment = ref.WXEnvironment;
/* istanbul ignore next */
if (WXEnvironment && WXEnvironment.platform === 'iOS') {
commonjsGlobal.Promise = undefined;
}
var _wks = createCommonjsModule(function (module) {
var store = _shared('wks');
var uid = _uid;
var Symbol = _global.Symbol;
var USE_SYMBOL = typeof Symbol == 'function';
var $exports = module.exports = function (name) {
return store[name] || (store[name] =
USE_SYMBOL && Symbol[name] || (USE_SYMBOL ? Symbol : uid)('Symbol.' + name));
};
$exports.store = store;
});
// getting tag from 19.1.3.6 Object.prototype.toString()
var cof$1 = _cof;
var TAG = _wks('toStringTag');
// ES3 wrong here
var ARG = cof$1(function () { return arguments; }()) == 'Arguments';
// fallback for IE11 Script Access Denied error
var tryGet = function (it, key) {
try {
return it[key];
} catch (e) { /* empty */ }
};
var _classof = function (it) {
var O, T, B;
return it === undefined ? 'Undefined' : it === null ? 'Null'
// @@toStringTag case
: typeof (T = tryGet(O = Object(it), TAG)) == 'string' ? T
// builtinTag case
: ARG ? cof$1(O)
// ES3 arguments fallback
: (B = cof$1(O)) == 'Object' && typeof O.callee == 'function' ? 'Arguments' : B;
};
// 19.1.3.6 Object.prototype.toString()
var classof = _classof;
var test = {};
test[_wks('toStringTag')] = 'z';
if (test + '' != '[object z]') {
_redefine(Object.prototype, 'toString', function toString() {
return '[object ' + classof(this) + ']';
}, true);
}
var toInteger$2 = _toInteger;
var defined$2 = _defined;
// true -> String#at
// false -> String#codePointAt
var _stringAt = function (TO_STRING) {
return function (that, pos) {
var s = String(defined$2(that));
var i = toInteger$2(pos);
var l = s.length;
var a, b;
if (i < 0 || i >= l) { return TO_STRING ? '' : undefined; }
a = s.charCodeAt(i);
return a < 0xd800 || a > 0xdbff || i + 1 === l || (b = s.charCodeAt(i + 1)) < 0xdc00 || b > 0xdfff
? TO_STRING ? s.charAt(i) : a
: TO_STRING ? s.slice(i, i + 2) : (a - 0xd800 << 10) + (b - 0xdc00) + 0x10000;
};
};
var _library = false;
var _iterators = {};
var dP$2 = _objectDp;
var anObject$2 = _anObject;
var getKeys$1 = _objectKeys;
var _objectDps = _descriptors ? Object.defineProperties : function defineProperties(O, Properties) {
anObject$2(O);
var keys = getKeys$1(Properties);
var length = keys.length;
var i = 0;
var P;
while (length > i) { dP$2.f(O, P = keys[i++], Properties[P]); }
return O;
};
var document$2 = _global.document;
var _html = document$2 && document$2.documentElement;
// 19.1.2.2 / 15.2.3.5 Object.create(O [, Properties])
var anObject$1 = _anObject;
var dPs = _objectDps;
var enumBugKeys$1 = _enumBugKeys;
var IE_PROTO$1 = _sharedKey('IE_PROTO');
var Empty = function () { /* empty */ };
var PROTOTYPE$1 = 'prototype';
// Create object with fake `null` prototype: use iframe Object with cleared prototype
var createDict = function () {
// Thrash, waste and sodomy: IE GC bug
var iframe = _domCreate('iframe');
var i = enumBugKeys$1.length;
var lt = '<';
var gt = '>';
var iframeDocument;
iframe.style.display = 'none';
_html.appendChild(iframe);
iframe.src = 'javascript:'; // eslint-disable-line no-script-url
// createDict = iframe.contentWindow.Object;
// html.removeChild(iframe);
iframeDocument = iframe.contentWindow.document;
iframeDocument.open();
iframeDocument.write(lt + 'script' + gt + 'document.F=Object' + lt + '/script' + gt);
iframeDocument.close();
createDict = iframeDocument.F;
while (i--) { delete createDict[PROTOTYPE$1][enumBugKeys$1[i]]; }
return createDict();
};
var _objectCreate = Object.create || function create(O, Properties) {
var result;
if (O !== null) {
Empty[PROTOTYPE$1] = anObject$1(O);
result = new Empty();
Empty[PROTOTYPE$1] = null;
// add "__proto__" for Object.getPrototypeOf polyfill
result[IE_PROTO$1] = O;
} else { result = createDict(); }
return Properties === undefined ? result : dPs(result, Properties);
};
var def = _objectDp.f;
var has$2 = _has;
var TAG$1 = _wks('toStringTag');
var _setToStringTag = function (it, tag, stat) {
if (it && !has$2(it = stat ? it : it.prototype, TAG$1)) { def(it, TAG$1, { configurable: true, value: tag }); }
};
var create$1 = _objectCreate;
var descriptor = _propertyDesc;
var setToStringTag$1 = _setToStringTag;
var IteratorPrototype = {};
// 25.1.2.1.1 %IteratorPrototype%[@@iterator]()
_hide(IteratorPrototype, _wks('iterator'), function () { return this; });
var _iterCreate = function (Constructor, NAME, next) {
Constructor.prototype = create$1(IteratorPrototype, { next: descriptor(1, next) });
setToStringTag$1(Constructor, NAME + ' Iterator');
};
// 19.1.2.9 / 15.2.3.2 Object.getPrototypeOf(O)
var has$3 = _has;
var toObject$1 = _toObject;
var IE_PROTO$2 = _sharedKey('IE_PROTO');
var ObjectProto = Object.prototype;
var _objectGpo = Object.getPrototypeOf || function (O) {
O = toObject$1(O);
if (has$3(O, IE_PROTO$2)) { return O[IE_PROTO$2]; }
if (typeof O.constructor == 'function' && O instanceof O.constructor) {
return O.constructor.prototype;
} return O instanceof Object ? ObjectProto : null;
};
var LIBRARY = _library;
var $export$2 = _export;
var redefine$1 = _redefine;
var hide$1 = _hide;
var has$1 = _has;
var Iterators = _iterators;
var $iterCreate = _iterCreate;
var setToStringTag = _setToStringTag;
var getPrototypeOf = _objectGpo;
var ITERATOR = _wks('iterator');
var BUGGY = !([].keys && 'next' in [].keys()); // Safari has buggy iterators w/o `next`
var FF_ITERATOR = '@@iterator';
var KEYS = 'keys';
var VALUES = 'values';
var returnThis = function () { return this; };
var _iterDefine = function (Base, NAME, Constructor, next, DEFAULT, IS_SET, FORCED) {
$iterCreate(Constructor, NAME, next);
var getMethod = function (kind) {
if (!BUGGY && kind in proto) { return proto[kind]; }
switch (kind) {
case KEYS: return function keys() { return new Constructor(this, kind); };
case VALUES: return function values() { return new Constructor(this, kind); };
} return function entries() { return new Constructor(this, kind); };
};
var TAG = NAME + ' Iterator';
var DEF_VALUES = DEFAULT == VALUES;
var VALUES_BUG = false;
var proto = Base.prototype;
var $native = proto[ITERATOR] || proto[FF_ITERATOR] || DEFAULT && proto[DEFAULT];
var $default = $native || getMethod(DEFAULT);
var $entries = DEFAULT ? !DEF_VALUES ? $default : getMethod('entries') : undefined;
var $anyNative = NAME == 'Array' ? proto.entries || $native : $native;
var methods, key, IteratorPrototype;
// Fix native
if ($anyNative) {
IteratorPrototype = getPrototypeOf($anyNative.call(new Base()));
if (IteratorPrototype !== Object.prototype && IteratorPrototype.next) {
// Set @@toStringTag to native iterators
setToStringTag(IteratorPrototype, TAG, true);
// fix for some old engines
if (!LIBRARY && !has$1(IteratorPrototype, ITERATOR)) { hide$1(IteratorPrototype, ITERATOR, returnThis); }
}
}
// fix Array#{values, @@iterator}.name in V8 / FF
if (DEF_VALUES && $native && $native.name !== VALUES) {
VALUES_BUG = true;
$default = function values() { return $native.call(this); };
}
// Define iterator
if ((!LIBRARY || FORCED) && (BUGGY || VALUES_BUG || !proto[ITERATOR])) {
hide$1(proto, ITERATOR, $default);
}
// Plug for library
Iterators[NAME] = $default;
Iterators[TAG] = returnThis;
if (DEFAULT) {
methods = {
values: DEF_VALUES ? $default : getMethod(VALUES),
keys: IS_SET ? $default : getMethod(KEYS),
entries: $entries
};
if (FORCED) { for (key in methods) {
if (!(key in proto)) { redefine$1(proto, key, methods[key]); }
} } else { $export$2($export$2.P + $export$2.F * (BUGGY || VALUES_BUG), NAME, methods); }
}
return methods;
};
var $at = _stringAt(true);
// 21.1.3.27 String.prototype[@@iterator]()
_iterDefine(String, 'String', function (iterated) {
this._t = String(iterated); // target
this._i = 0; // next index
// 21.1.5.2.1 %StringIteratorPrototype%.next()
}, function () {
var O = this._t;
var index = this._i;
var point;
if (index >= O.length) { return { value: undefined, done: true }; }
point = $at(O, index);
this._i += point.length;
return { value: point, done: false };
});
// 22.1.3.31 Array.prototype[@@unscopables]
var UNSCOPABLES = _wks('unscopables');
var ArrayProto = Array.prototype;
if (ArrayProto[UNSCOPABLES] == undefined) { _hide(ArrayProto, UNSCOPABLES, {}); }
var _addToUnscopables = function (key) {
ArrayProto[UNSCOPABLES][key] = true;
};
var _iterStep = function (done, value) {
return { value: value, done: !!done };
};
var addToUnscopables = _addToUnscopables;
var step = _iterStep;
var Iterators$2 = _iterators;
var toIObject$2 = _toIobject;
// 22.1.3.4 Array.prototype.entries()
// 22.1.3.13 Array.prototype.keys()
// 22.1.3.29 Array.prototype.values()
// 22.1.3.30 Array.prototype[@@iterator]()
var es6_array_iterator = _iterDefine(Array, 'Array', function (iterated, kind) {
this._t = toIObject$2(iterated); // target
this._i = 0; // next index
this._k = kind; // kind
// 22.1.5.2.1 %ArrayIteratorPrototype%.next()
}, function () {
var O = this._t;
var kind = this._k;
var index = this._i++;
if (!O || index >= O.length) {
this._t = undefined;
return step(1);
}
if (kind == 'keys') { return step(0, index); }
if (kind == 'values') { return step(0, O[index]); }
return step(0, [index, O[index]]);
}, 'values');
// argumentsList[@@iterator] is %ArrayProto_values% (9.4.4.6, 9.4.4.7)
Iterators$2.Arguments = Iterators$2.Array;
addToUnscopables('keys');
addToUnscopables('values');
addToUnscopables('entries');
var $iterators = es6_array_iterator;
var getKeys$2 = _objectKeys;
var redefine$2 = _redefine;
var global$3 = _global;
var hide$2 = _hide;
var Iterators$1 = _iterators;
var wks = _wks;
var ITERATOR$1 = wks('iterator');
var TO_STRING_TAG = wks('toStringTag');
var ArrayValues = Iterators$1.Array;
var DOMIterables = {
CSSRuleList: true, // TODO: Not spec compliant, should be false.
CSSStyleDeclaration: false,
CSSValueList: false,
ClientRectList: false,
DOMRectList: false,
DOMStringList: false,
DOMTokenList: true,
DataTransferItemList: false,
FileList: false,
HTMLAllCollection: false,
HTMLCollection: false,
HTMLFormElement: false,
HTMLSelectElement: false,
MediaList: true, // TODO: Not spec compliant, should be false.
MimeTypeArray: false,
NamedNodeMap: false,
NodeList: true,
PaintRequestList: false,
Plugin: false,
PluginArray: false,
SVGLengthList: false,
SVGNumberList: false,
SVGPathSegList: false,
SVGPointList: false,
SVGStringList: false,
SVGTransformList: false,
SourceBufferList: false,
StyleSheetList: true, // TODO: Not spec compliant, should be false.
TextTrackCueList: false,
TextTrackList: false,
TouchList: false
};
for (var collections = getKeys$2(DOMIterables), i = 0; i < collections.length; i++) {
var NAME = collections[i];
var explicit = DOMIterables[NAME];
var Collection = global$3[NAME];
var proto = Collection && Collection.prototype;
var key;
if (proto) {
if (!proto[ITERATOR$1]) { hide$2(proto, ITERATOR$1, ArrayValues); }
if (!proto[TO_STRING_TAG]) { hide$2(proto, TO_STRING_TAG, NAME); }
Iterators$1[NAME] = ArrayValues;
if (explicit) { for (key in $iterators) { if (!proto[key]) { redefine$2(proto, key, $iterators[key], true); } } }
}
}
var _anInstance = function (it, Constructor, name, forbiddenField) {
if (!(it instanceof Constructor) || (forbiddenField !== undefined && forbiddenField in it)) {
throw TypeError(name + ': incorrect invocation!');
} return it;
};
// call something on iterator step with safe closing on error
var anObject$3 = _anObject;
var _iterCall = function (iterator, fn, value, entries) {
try {
return entries ? fn(anObject$3(value)[0], value[1]) : fn(value);
// 7.4.6 IteratorClose(iterator, completion)
} catch (e) {
var ret = iterator['return'];
if (ret !== undefined) { anObject$3(ret.call(iterator)); }
throw e;
}
};
// check on default Array iterator
var Iterators$3 = _iterators;
var ITERATOR$2 = _wks('iterator');
var ArrayProto$1 = Array.prototype;
var _isArrayIter = function (it) {
return it !== undefined && (Iterators$3.Array === it || ArrayProto$1[ITERATOR$2] === it);
};
var classof$2 = _classof;
var ITERATOR$3 = _wks('iterator');
var Iterators$4 = _iterators;
var core_getIteratorMethod = _core.getIteratorMethod = function (it) {
if (it != undefined) { return it[ITERATOR$3]
|| it['@@iterator']
|| Iterators$4[classof$2(it)]; }
};
var _forOf = createCommonjsModule(function (module) {
var ctx = _ctx;
var call = _iterCall;
var isArrayIter = _isArrayIter;
var anObject = _anObject;
var toLength = _toLength;
var getIterFn = core_getIteratorMethod;
var BREAK = {};
var RETURN = {};
var exports = module.exports = function (iterable, entries, fn, that, ITERATOR) {
var iterFn = ITERATOR ? function () { return iterable; } : getIterFn(iterable);
var f = ctx(fn, that, entries ? 2 : 1);
var index = 0;
var length, step, iterator, result;
if (typeof iterFn != 'function') { throw TypeError(iterable + ' is not iterable!'); }
// fast case for arrays with default iterator
if (isArrayIter(iterFn)) { for (length = toLength(iterable.length); length > index; index++) {
result = entries ? f(anObject(step = iterable[index])[0], step[1]) : f(iterable[index]);
if (result === BREAK || result === RETURN) { return result; }
} } else { for (iterator = iterFn.call(iterable); !(step = iterator.next()).done;) {
result = call(iterator, f, step.value, entries);
if (result === BREAK || result === RETURN) { return result; }
} }
};
exports.BREAK = BREAK;
exports.RETURN = RETURN;
});
// 7.3.20 SpeciesConstructor(O, defaultConstructor)
var anObject$4 = _anObject;
var aFunction$2 = _aFunction;
var SPECIES = _wks('species');
var _speciesConstructor = function (O, D) {
var C = anObject$4(O).constructor;
var S;
return C === undefined || (S = anObject$4(C)[SPECIES]) == undefined ? D : aFunction$2(S);
};
// fast apply, http://jsperf.lnkit.com/fast-apply/5
var _invoke = function (fn, args, that) {
var un = that === undefined;
switch (args.length) {
case 0: return un ? fn()
: fn.call(that);
case 1: return un ? fn(args[0])
: fn.call(that, args[0]);
case 2: return un ? fn(args[0], args[1])
: fn.call(that, args[0], args[1]);
case 3: return un ? fn(args[0], args[1], args[2])
: fn.call(that, args[0], args[1], args[2]);
case 4: return un ? fn(args[0], args[1], args[2], args[3])
: fn.call(that, args[0], args[1], args[2], args[3]);
} return fn.apply(that, args);
};
var ctx$2 = _ctx;
var invoke = _invoke;
var html = _html;
var cel = _domCreate;
var global$5 = _global;
var process$1 = global$5.process;
var setTask = global$5.setImmediate;
var clearTask = global$5.clearImmediate;
var MessageChannel = global$5.MessageChannel;
var Dispatch = global$5.Dispatch;
var counter = 0;
var queue = {};
var ONREADYSTATECHANGE = 'onreadystatechange';
var defer;
var channel;
var port;
var run = function () {
var id = +this;
// eslint-disable-next-line no-prototype-builtins
if (queue.hasOwnProperty(id)) {
var fn = queue[id];
delete queue[id];
fn();
}
};
var listener = function (event) {
run.call(event.data);
};
// Node.js 0.9+ & IE10+ has setImmediate, otherwise:
if (!setTask || !clearTask) {
setTask = function setImmediate(fn) {
var arguments$1 = arguments;
var args = [];
var i = 1;
while (arguments.length > i) { args.push(arguments$1[i++]); }
queue[++counter] = function () {
// eslint-disable-next-line no-new-func
invoke(typeof fn == 'function' ? fn : Function(fn), args);
};
defer(counter);
return counter;
};
clearTask = function clearImmediate(id) {
delete queue[id];
};
// Node.js 0.8-
if (_cof(process$1) == 'process') {
defer = function (id) {
process$1.nextTick(ctx$2(run, id, 1));
};
// Sphere (JS game engine) Dispatch API
} else if (Dispatch && Dispatch.now) {
defer = function (id) {
Dispatch.now(ctx$2(run, id, 1));
};
// Browsers with MessageChannel, includes WebWorkers
} else if (MessageChannel) {
channel = new MessageChannel();
port = channel.port2;
channel.port1.onmessage = listener;
defer = ctx$2(port.postMessage, port, 1);
// Browsers with postMessage, skip WebWorkers
// IE8 has postMessage, but it's sync & typeof its postMessage is 'object'
} else if (global$5.addEventListener && typeof postMessage == 'function' && !global$5.importScripts) {
defer = function (id) {
global$5.postMessage(id + '', '*');
};
global$5.addEventListener('message', listener, false);
// IE8-
} else if (ONREADYSTATECHANGE in cel('script')) {
defer = function (id) {
html.appendChild(cel('script'))[ONREADYSTATECHANGE] = function () {
html.removeChild(this);
run.call(id);
};
};
// Rest old browsers
} else {
defer = function (id) {
setTimeout(ctx$2(run, id, 1), 0);
};
}
}
var _task = {
set: setTask,
clear: clearTask
};
var global$6 = _global;
var macrotask = _task.set;
var Observer = global$6.MutationObserver || global$6.WebKitMutationObserver;
var process$2 = global$6.process;
var Promise$1 = global$6.Promise;
var isNode$1 = _cof(process$2) == 'process';
var _microtask = function () {
var head, last, notify;
var flush = function () {
var parent, fn;
if (isNode$1 && (parent = process$2.domain)) { parent.exit(); }
while (head) {
fn = head.fn;
head = head.next;
try {
fn();
} catch (e) {
if (head) { notify(); }
else { last = undefined; }
throw e;
}
} last = undefined;
if (parent) { parent.enter(); }
};
// Node.js
if (isNode$1) {
notify = function () {
process$2.nextTick(flush);
};
// browsers with MutationObserver
} else if (Observer) {
var toggle = true;
var node = document.createTextNode('');
new Observer(flush).observe(node, { characterData: true }); // eslint-disable-line no-new
notify = function () {
node.data = toggle = !toggle;
};
// environments with maybe non-completely correct, but existent Promise
} else if (Promise$1 && Promise$1.resolve) {
var promise = Promise$1.resolve();
notify = function () {
promise.then(flush);
};
// for other environments - macrotask based on:
// - setImmediate
// - MessageChannel
// - window.postMessag
// - onreadystatechange
// - setTimeout
} else {
notify = function () {
// strange IE + webpack dev server bug - use .call(global)
macrotask.call(global$6, flush);
};
}
return function (fn) {
var task = { fn: fn, next: undefined };
if (last) { last.next = task; }
if (!head) {
head = task;
notify();
} last = task;
};
};
// 25.4.1.5 NewPromiseCapability(C)
var aFunction$3 = _aFunction;
function PromiseCapability(C) {
var resolve, reject;
this.promise = new C(function ($$resolve, $$reject) {
if (resolve !== undefined || reject !== undefined) { throw TypeError('Bad Promise constructor'); }
resolve = $$resolve;
reject = $$reject;
});
this.resolve = aFunction$3(resolve);
this.reject = aFunction$3(reject);
}
var f$3 = function (C) {
return new PromiseCapability(C);
};
var _newPromiseCapability = {
f: f$3
};
var _perform = function (exec) {
try {
return { e: false, v: exec() };
} catch (e) {
return { e: true, v: e };
}
};
var newPromiseCapability$1 = _newPromiseCapability;
var _promiseResolve = function (C, x) {
var promiseCapability = newPromiseCapability$1.f(C);
var resolve = promiseCapability.resolve;
resolve(x);
return promiseCapability.promise;
};
var redefine$3 = _redefine;
var _redefineAll = function (target, src, safe) {
for (var key in src) { redefine$3(target, key, src[key], safe); }
return target;
};
var global$7 = _global;
var dP$3 = _objectDp;
var DESCRIPTORS = _descriptors;
var SPECIES$1 = _wks('species');
var _setSpecies = function (KEY) {
var C = global$7[KEY];
if (DESCRIPTORS && C && !C[SPECIES$1]) { dP$3.f(C, SPECIES$1, {
configurable: true,
get: function () { return this; }
}); }
};
var ITERATOR$4 = _wks('iterator');
var SAFE_CLOSING = false;
try {
var riter = [7][ITERATOR$4]();
riter['return'] = function () { SAFE_CLOSING = true; };
// eslint-disable-next-line no-throw-literal
Array.from(riter, function () { throw 2; });
} catch (e) { /* empty */ }
var _iterDetect = function (exec, skipClosing) {
if (!skipClosing && !SAFE_CLOSING) { return false; }
var safe = false;
try {
var arr = [7];
var iter = arr[ITERATOR$4]();
iter.next = function () { return { done: safe = true }; };
arr[ITERATOR$4] = function () { return iter; };
exec(arr);
} catch (e) { /* empty */ }
return safe;
};
var LIBRARY$1 = _library;
var global$4 = _global;
var ctx$1 = _ctx;
var classof$1 = _classof;
var $export$3 = _export;
var isObject$3 = _isObject;
var aFunction$1 = _aFunction;
var anInstance = _anInstance;
var forOf = _forOf;
var speciesConstructor = _speciesConstructor;
var task = _task.set;
var microtask = _microtask();
var newPromiseCapabilityModule = _newPromiseCapability;
var perform = _perform;
var promiseResolve = _promiseResolve;
var PROMISE = 'Promise';
var TypeError$1 = global$4.TypeError;
var process = global$4.process;
var $Promise = global$4[PROMISE];
var isNode = classof$1(process) == 'process';
var empty = function () { /* empty */ };
var Internal;
var newGenericPromiseCapability;
var OwnPromiseCapability;
var Wrapper;
var newPromiseCapability = newGenericPromiseCapability = newPromiseCapabilityModule.f;
var USE_NATIVE = !!function () {
try {
// correct subclassing with @@species support
var promise = $Promise.resolve(1);
var FakePromise = (promise.constructor = {})[_wks('species')] = function (exec) {
exec(empty, empty);
};
// unhandled rejections tracking support, NodeJS Promise without it fails @@species test
return (isNode || typeof PromiseRejectionEvent == 'function') && promise.then(empty) instanceof FakePromise;
} catch (e) { /* empty */ }
}();
// helpers
var sameConstructor = LIBRARY$1 ? function (a, b) {
// with library wrapper special case
return a === b || a === $Promise && b === Wrapper;
} : function (a, b) {
return a === b;
};
var isThenable = function (it) {
var then;
return isObject$3(it) && typeof (then = it.then) == 'function' ? then : false;
};
var notify = function (promise, isReject) {
if (promise._n) { return; }
promise._n = true;
var chain = promise._c;
microtask(function () {
var value = promise._v;
var ok = promise._s == 1;
var i = 0;
var run = function (reaction) {
var handler = ok ? reaction.ok : reaction.fail;
var resolve = reaction.resolve;
var reject = reaction.reject;
var domain = reaction.domain;
var result, then;
try {
if (handler) {
if (!ok) {
if (promise._h == 2) { onHandleUnhandled(promise); }
promise._h = 1;
}
if (handler === true) { result = value; }
else {
if (domain) { domain.enter(); }
result = handler(value);
if (domain) { domain.exit(); }
}
if (result === reaction.promise) {
reject(TypeError$1('Promise-chain cycle'));
} else if (then = isThenable(result)) {
then.call(result, resolve, reject);
} else { resolve(result); }
} else { reject(value); }
} catch (e) {
reject(e);
}
};
while (chain.length > i) { run(chain[i++]); } // variable length - can't use forEach
promise._c = [];
promise._n = false;
if (isReject && !promise._h) { onUnhandled(promise); }
});
};
var onUnhandled = function (promise) {
task.call(global$4, function () {
var value = promise._v;
var unhandled = isUnhandled(promise);
var result, handler, console;
if (unhandled) {
result = perform(function () {
if (isNode) {
process.emit('unhandledRejection', value, promise);
} else if (handler = global$4.onunhandledrejection) {
handler({ promise: promise, reason: value });
} else if ((console = global$4.console) && console.error) {
console.error('Unhandled promise rejection', value);
}
});
// Browsers should not trigger `rejectionHandled` event if it was handled here, NodeJS - should
promise._h = isNode || isUnhandled(promise) ? 2 : 1;
} promise._a = undefined;
if (unhandled && result.e) { throw result.v; }
});
};
var isUnhandled = function (promise) {
if (promise._h == 1) { return false; }
var chain = promise._a || promise._c;
var i = 0;
var reaction;
while (chain.length > i) {
reaction = chain[i++];
if (reaction.fail || !isUnhandled(reaction.promise)) { return false; }
} return true;
};
var onHandleUnhandled = function (promise) {
task.call(global$4, function () {
var handler;
if (isNode) {
process.emit('rejectionHandled', promise);
} else if (handler = global$4.onrejectionhandled) {
handler({ promise: promise, reason: promise._v });
}
});
};
var $reject = function (value) {
var promise = this;
if (promise._d) { return; }
promise._d = true;
promise = promise._w || promise; // unwrap
promise._v = value;
promise._s = 2;
if (!promise._a) { promise._a = promise._c.slice(); }
notify(promise, true);
};
var $resolve = function (value) {
var promise = this;
var then;
if (promise._d) { return; }
promise._d = true;
promise = promise._w || promise; // unwrap
try {
if (promise === value) { throw TypeError$1("Promise can't be resolved itself"); }
if (then = isThenable(value)) {
microtask(function () {
var wrapper = { _w: promise, _d: false }; // wrap
try {
then.call(value, ctx$1($resolve, wrapper, 1), ctx$1($reject, wrapper, 1));
} catch (e) {
$reject.call(wrapper, e);
}
});
} else {
promise._v = value;
promise._s = 1;
notify(promise, false);
}
} catch (e) {
$reject.call({ _w: promise, _d: false }, e); // wrap
}
};
// constructor polyfill
if (!USE_NATIVE) {
// 25.4.3.1 Promise(executor)
$Promise = function Promise(executor) {
anInstance(this, $Promise, PROMISE, '_h');
aFunction$1(executor);
Internal.call(this);
try {
executor(ctx$1($resolve, this, 1), ctx$1($reject, this, 1));
} catch (err) {
$reject.call(this, err);
}
};
// eslint-disable-next-line no-unused-vars
Internal = function Promise(executor) {
this._c = []; // <- awaiting reactions
this._a = undefined; // <- checked in isUnhandled reactions
this._s = 0; // <- state
this._d = false; // <- done
this._v = undefined; // <- value
this._h = 0; // <- rejection state, 0 - default, 1 - handled, 2 - unhandled
this._n = false; // <- notify
};
Internal.prototype = _redefineAll($Promise.prototype, {
// 25.4.5.3 Promise.prototype.then(onFulfilled, onRejected)
then: function then(onFulfilled, onRejected) {
var reaction = newPromiseCapability(speciesConstructor(this, $Promise));
reaction.ok = typeof onFulfilled == 'function' ? onFulfilled : true;
reaction.fail = typeof onRejected == 'function' && onRejected;
reaction.domain = isNode ? process.domain : undefined;
this._c.push(reaction);
if (this._a) { this._a.push(reaction); }
if (this._s) { notify(this, false); }
return reaction.promise;
},
// 25.4.5.1 Promise.prototype.catch(onRejected)
'catch': function (onRejected) {
return this.then(undefined, onRejected);
}
});
OwnPromiseCapability = function () {
var promise = new Internal();
this.promise = promise;
this.resolve = ctx$1($resolve, promise, 1);
this.reject = ctx$1($reject, promise, 1);
};
newPromiseCapabilityModule.f = newPromiseCapability = function (C) {
return sameConstructor($Promise, C)
? new OwnPromiseCapability(C)
: newGenericPromiseCapability(C);
};
}
$export$3($export$3.G + $export$3.W + $export$3.F * !USE_NATIVE, { Promise: $Promise });
_setToStringTag($Promise, PROMISE);
_setSpecies(PROMISE);
Wrapper = _core[PROMISE];
// statics
$export$3($export$3.S + $export$3.F * !USE_NATIVE, PROMISE, {
// 25.4.4.5 Promise.reject(r)
reject: function reject(r) {
var capability = newPromiseCapability(this);
var $$reject = capability.reject;
$$reject(r);
return capability.promise;
}
});
$export$3($export$3.S + $export$3.F * (LIBRARY$1 || !USE_NATIVE), PROMISE, {
// 25.4.4.6 Promise.resolve(x)
resolve: function resolve(x) {
// instanceof instead of internal slot check because we should fix it without replacement native Promise core
if (x instanceof $Promise && sameConstructor(x.constructor, this)) { return x; }
return promiseResolve(this, x);
}
});
$export$3($export$3.S + $export$3.F * !(USE_NATIVE && _iterDetect(function (iter) {
$Promise.all(iter)['catch'](empty);
})), PROMISE, {
// 25.4.4.1 Promise.all(iterable)
all: function all(iterable) {
var C = this;
var capability = newPromiseCapability(C);
var resolve = capability.resolve;
var reject = capability.reject;
var result = perform(function () {
var values = [];
var index = 0;
var remaining = 1;
forOf(iterable, false, function (promise) {
var $index = index++;
var alreadyCalled = false;
values.push(undefined);
remaining++;
C.resolve(promise).then(function (value) {
if (alreadyCalled) { return; }
alreadyCalled = true;
values[$index] = value;
--remaining || resolve(values);
}, reject);
});
--remaining || resolve(values);
});
if (result.e) { reject(result.v); }
return capability.promise;
},
// 25.4.4.4 Promise.race(iterable)
race: function race(iterable) {
var C = this;
var capability = newPromiseCapability(C);
var reject = capability.reject;
var result = perform(function () {
forOf(iterable, false, function (promise) {
C.resolve(promise).then(capability.resolve, reject);
});
});
if (result.e) { reject(result.v); }
return capability.promise;
}
});
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* @fileOverview
* This file will hack `console` methods by `WXEnvironment.logLevel`.
* So we can control how many and which messages will be sent by change the log level.
* Additionally in native platform the message content must be primitive values and
* using `nativeLog(...args, logLevelMark)` so we create a new `console` object in
* global add a format process for its methods.
*/
var LEVELS = ['off', 'error', 'warn', 'info', 'log', 'debug'];
var levelMap = {};
var originalConsole = global.console;
/**
* Hack console for native environment.
*/
function setNativeConsole () {
generateLevelMap();
/* istanbul ignore next */
// mock console in native environment
if (global.WXEnvironment && global.WXEnvironment.platform !== 'Web') {
global.console = {
debug: function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
if (checkLevel('debug')) { global.nativeLog.apply(global, format(args).concat( ['__DEBUG'] )); }
},
log: function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
if (checkLevel('log')) { global.nativeLog.apply(global, format(args).concat( ['__LOG'] )); }
},
info: function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
if (checkLevel('info')) { global.nativeLog.apply(global, format(args).concat( ['__INFO'] )); }
},
warn: function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
if (checkLevel('warn')) { global.nativeLog.apply(global, format(args).concat( ['__WARN'] )); }
},
error: function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
if (checkLevel('error')) { global.nativeLog.apply(global, format(args).concat( ['__ERROR'] )); }
}
};
}
// Web or Node
else {
var debug = console.debug;
var log = console.log;
var info = console.info;
var warn = console.warn;
var error = console.error;
console.__ori__ = { debug: debug, log: log, info: info, warn: warn, error: error };
console.debug = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
if (checkLevel('debug')) { console.__ori__.debug.apply(console, args); }
};
console.log = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
if (checkLevel('log')) { console.__ori__.log.apply(console, args); }
};
console.info = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
if (checkLevel('info')) { console.__ori__.info.apply(console, args); }
};
console.warn = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
if (checkLevel('warn')) { console.__ori__.warn.apply(console, args); }
};
console.error = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
if (checkLevel('error')) { console.__ori__.error.apply(console, args); }
};
}
}
/**
* Reset hacked console to original.
*/
/* istanbul ignore next */
function resetNativeConsole () {
levelMap = {};
global.console = originalConsole;
}
/**
* Generate map for which types of message will be sent in a certain message level
* as the order of LEVELS.
*/
function generateLevelMap () {
LEVELS.forEach(function (level) {
var levelIndex = LEVELS.indexOf(level);
levelMap[level] = {};
LEVELS.forEach(function (type) {
var typeIndex = LEVELS.indexOf(type);
if (typeIndex <= levelIndex) {
levelMap[level][type] = true;
}
});
});
}
/**
* Check if a certain type of message will be sent in current log level of env.
* @param {string} type
* @return {boolean}
*/
function checkLevel (type) {
var logLevel = (global.WXEnvironment && global.WXEnvironment.logLevel) || 'log';
return levelMap[logLevel] && levelMap[logLevel][type]
}
/**
* Convert all log arguments into primitive values.
* @param {array} args
* @return {array}
*/
/* istanbul ignore next */
function format (args) {
return args.map(function (v) {
var type = Object.prototype.toString.call(v);
if (type.toLowerCase() === '[object object]') {
v = JSON.stringify(v);
}
else {
v = String(v);
}
return v
})
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* @fileOverview
* Polyfill `setTimeout` on Android V8 using native method
* `setTimeoutNative(callbackId, time)` and JS method
* `setTimeoutCallback(callbackId)`.
* This polyfill is only used in virtual-DOM diff & flush agorithm. Not
* accessed by JS Bundle code (The timer APIs polyfill for JS Bundle is in
* `html5/default/app/ctrl.js`).
*/
var originalSetTimeout = global.setTimeout;
var setTimeoutNative = global.setTimeoutNative;
/**
* Set up native timer
*/
/* istanbul ignore next */
function setNativeTimer () {
if (typeof setTimeout === 'undefined' &&
typeof setTimeoutNative === 'function') {
var timeoutMap = {};
var timeoutId = 0;
global.setTimeout = function (cb, time) {
timeoutMap[++timeoutId] = cb;
setTimeoutNative(timeoutId.toString(), time);
};
global.setTimeoutCallback = function (id) {
if (typeof timeoutMap[id] === 'function') {
timeoutMap[id]();
delete timeoutMap[id];
}
};
}
}
/* istanbul ignore next */
function resetNativeTimer () {
global.setTimeout = originalSetTimeout;
global.setTimeoutCallback = null;
}
setNativeTimer();
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* Freeze the prototype of javascript build-in objects.
*/
/* istanbul ignore next */
function freezePrototype$1 () {
Object.freeze(Object);
Object.freeze(Array);
// Object.freeze(Object.prototype)
freezeObjectProto();
Object.freeze(Array.prototype);
Object.freeze(String.prototype);
Object.freeze(Number.prototype);
Object.freeze(Boolean.prototype);
// Object.freeze(Error.prototype)
freezeErrorProto();
Object.freeze(Date.prototype);
Object.freeze(RegExp.prototype);
}
function freezeObjectProto () {
var proto = Object.prototype;
var protoName = 'Object.prototype';
freezeProtoProperty(proto, '__defineGetter__', protoName);
freezeProtoProperty(proto, '__defineSetter__', protoName);
freezeProtoProperty(proto, '__lookupGetter__', protoName);
freezeProtoProperty(proto, '__lookupSetter__', protoName);
freezeProtoProperty(proto, 'constructor', protoName);
freezeProtoProperty(proto, 'hasOwnProperty', protoName);
freezeProtoProperty(proto, 'isPrototypeOf', protoName);
freezeProtoProperty(proto, 'propertyIsEnumerable', protoName);
freezeProtoProperty(proto, 'toLocaleString', protoName);
freezeProtoProperty(proto, 'toString', protoName);
freezeProtoProperty(proto, 'valueOf', protoName);
Object.seal(proto);
}
function freezeErrorProto () {
var proto = Error.prototype;
var protoName = 'Error.prototype';
freezeProtoProperty(proto, 'name', protoName);
freezeProtoProperty(proto, 'message', protoName);
freezeProtoProperty(proto, 'toString', protoName);
freezeProtoProperty(proto, 'constructor', protoName);
Object.seal(proto);
}
function freezeProtoProperty (proto, propertyName, protoName) {
if (!proto.hasOwnProperty(propertyName)) {
return
}
var origin = proto[propertyName];
Object.defineProperty(proto, propertyName, {
get: function () {
return origin
},
set: function (value) {
if (this === proto) {
throw Error(("Cannot assign to read only property " + propertyName + " of " + protoName))
}
Object.defineProperty(this, propertyName, {
value: value,
writable: true
});
return value
}
});
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// import promise hack and polyfills
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* Get a unique id.
*/
var nextNodeRef = 1;
function uniqueId () {
return (nextNodeRef++).toString()
}
function typof (v) {
var s = Object.prototype.toString.call(v);
return s.substring(8, s.length - 1)
}
function bufferToBase64 (buffer) {
if (typeof btoa !== 'function') {
return ''
}
var string = Array.prototype.map.call(
new Uint8Array(buffer),
function (code) { return String.fromCharCode(code); }
).join('');
return btoa(string) // eslint-disable-line no-undef
}
function base64ToBuffer (base64) {
if (typeof atob !== 'function') {
return new ArrayBuffer(0)
}
var string = atob(base64); // eslint-disable-line no-undef
var array = new Uint8Array(string.length);
Array.prototype.forEach.call(string, function (ch, i) {
array[i] = ch.charCodeAt(0);
});
return array.buffer
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* Normalize a primitive value.
* @param {any} v
* @return {primitive}
*/
function normalizePrimitive (v) {
var type = typof(v);
switch (type) {
case 'Undefined':
case 'Null':
return ''
case 'RegExp':
return v.toString()
case 'Date':
return v.toISOString()
case 'Number':
case 'String':
case 'Boolean':
case 'Array':
case 'Object':
return v
case 'ArrayBuffer':
return {
'@type': 'binary',
dataType: type,
base64: bufferToBase64(v)
}
case 'Int8Array':
case 'Uint8Array':
case 'Uint8ClampedArray':
case 'Int16Array':
case 'Uint16Array':
case 'Int32Array':
case 'Uint32Array':
case 'Float32Array':
case 'Float64Array':
return {
'@type': 'binary',
dataType: type,
base64: bufferToBase64(v.buffer)
}
default:
return JSON.stringify(v)
}
}
function decodePrimitive (data) {
if (typof(data) === 'Object') {
// decode base64 into binary
if (data['@type'] && data['@type'] === 'binary') {
return base64ToBuffer(data.base64 || '')
}
var realData = {};
for (var key in data) {
realData[key] = decodePrimitive(data[key]);
}
return realData
}
if (typof(data) === 'Array') {
return data.map(decodePrimitive)
}
return data
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* For general callback management of a certain Weex instance.
* Because function can not passed into native, so we create callback
* callback id for each function and pass the callback id into native
* in fact. And when a callback called from native, we can find the real
* callback through the callback id we have passed before.
*/
var CallbackManager = function CallbackManager (instanceId) {
this.instanceId = instanceId;
this.lastCallbackId = 0;
this.callbacks = {};
};
CallbackManager.prototype.add = function add (callback) {
this.lastCallbackId++;
this.callbacks[this.lastCallbackId] = callback;
return this.lastCallbackId
};
CallbackManager.prototype.remove = function remove (callbackId) {
var callback = this.callbacks[callbackId];
delete this.callbacks[callbackId];
return callback
};
CallbackManager.prototype.consume = function consume (callbackId, data, ifKeepAlive) {
var callback = this.callbacks[callbackId];
if (typeof ifKeepAlive === 'undefined' || ifKeepAlive === false) {
delete this.callbacks[callbackId];
}
if (typeof callback === 'function') {
return callback(decodePrimitive(data))
}
return new Error(("invalid callback id \"" + callbackId + "\""))
};
CallbackManager.prototype.close = function close () {
this.callbacks = {};
};
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var docMap = {};
/**
* Add a document object into docMap.
* @param {string} id
* @param {object} document
*/
function addDoc (id, doc) {
if (id) {
docMap[id] = doc;
}
}
/**
* Get the document object by id.
* @param {string} id
*/
function getDoc (id) {
return docMap[id]
}
/**
* Remove the document from docMap by id.
* @param {string} id
*/
function removeDoc (id) {
delete docMap[id];
}
/**
* @deprecated
* Get listener by document id.
* @param {string} id
* @return {object} listener
*/
/**
* Get TaskCenter instance by id.
* @param {string} id
* @return {object} TaskCenter
*/
function getTaskCenter (id) {
var doc = docMap[id];
if (doc && doc.taskCenter) {
return doc.taskCenter
}
return null
}
/**
* Append body node to documentElement.
* @param {object} document
* @param {object} node
* @param {object} before
*/
function appendBody (doc, node, before) {
var documentElement = doc.documentElement;
if (documentElement.pureChildren.length > 0 || node.parentNode) {
return
}
var children = documentElement.children;
var beforeIndex = children.indexOf(before);
if (beforeIndex < 0) {
children.push(node);
}
else {
children.splice(beforeIndex, 0, node);
}
if (node.nodeType === 1) {
if (node.role === 'body') {
node.docId = doc.id;
node.ownerDocument = doc;
node.parentNode = documentElement;
linkParent(node, documentElement);
}
else {
node.children.forEach(function (child) {
child.parentNode = node;
});
setBody(doc, node);
node.docId = doc.id;
node.ownerDocument = doc;
linkParent(node, documentElement);
delete doc.nodeMap[node.nodeId];
}
documentElement.pureChildren.push(node);
sendBody(doc, node);
}
else {
node.parentNode = documentElement;
doc.nodeMap[node.ref] = node;
}
}
function sendBody (doc, node) {
var body = node.toJSON();
var children = body.children;
delete body.children;
var result = doc.taskCenter.send('dom', { action: 'createBody' }, [body]);
if (children) {
children.forEach(function (child) {
result = doc.taskCenter.send('dom', { action: 'addElement' }, [body.ref, child, -1]);
});
}
return result
}
/**
* Set up body node.
* @param {object} document
* @param {object} element
*/
function setBody (doc, el) {
el.role = 'body';
el.depth = 1;
delete doc.nodeMap[el.nodeId];
el.ref = '_root';
doc.nodeMap._root = el;
doc.body = el;
}
/**
* Establish the connection between parent and child node.
* @param {object} child node
* @param {object} parent node
*/
function linkParent (node, parent) {
node.parentNode = parent;
if (parent.docId) {
node.docId = parent.docId;
node.ownerDocument = parent.ownerDocument;
node.ownerDocument.nodeMap[node.nodeId] = node;
node.depth = parent.depth + 1;
}
node.children.forEach(function (child) {
linkParent(child, node);
});
}
/**
* Get the next sibling element.
* @param {object} node
*/
function nextElement (node) {
while (node) {
if (node.nodeType === 1) {
return node
}
node = node.nextSibling;
}
}
/**
* Get the previous sibling element.
* @param {object} node
*/
function previousElement (node) {
while (node) {
if (node.nodeType === 1) {
return node
}
node = node.previousSibling;
}
}
/**
* Insert a node into list at the specified index.
* @param {object} target node
* @param {array} list
* @param {number} newIndex
* @param {boolean} changeSibling
* @return {number} newIndex
*/
function insertIndex (target, list, newIndex, changeSibling) {
/* istanbul ignore next */
if (newIndex < 0) {
newIndex = 0;
}
var before = list[newIndex - 1];
var after = list[newIndex];
list.splice(newIndex, 0, target);
if (changeSibling) {
before && (before.nextSibling = target);
target.previousSibling = before;
target.nextSibling = after;
after && (after.previousSibling = target);
}
return newIndex
}
/**
* Move the node to a new index in list.
* @param {object} target node
* @param {array} list
* @param {number} newIndex
* @param {boolean} changeSibling
* @return {number} newIndex
*/
function moveIndex (target, list, newIndex, changeSibling) {
var index = list.indexOf(target);
/* istanbul ignore next */
if (index < 0) {
return -1
}
if (changeSibling) {
var before = list[index - 1];
var after = list[index + 1];
before && (before.nextSibling = after);
after && (after.previousSibling = before);
}
list.splice(index, 1);
var newIndexAfter = newIndex;
if (index <= newIndex) {
newIndexAfter = newIndex - 1;
}
var beforeNew = list[newIndexAfter - 1];
var afterNew = list[newIndexAfter];
list.splice(newIndexAfter, 0, target);
if (changeSibling) {
beforeNew && (beforeNew.nextSibling = target);
target.previousSibling = beforeNew;
target.nextSibling = afterNew;
afterNew && (afterNew.previousSibling = target);
}
if (index === newIndexAfter) {
return -1
}
return newIndex
}
/**
* Remove the node from list.
* @param {object} target node
* @param {array} list
* @param {boolean} changeSibling
*/
function removeIndex (target, list, changeSibling) {
var index = list.indexOf(target);
/* istanbul ignore next */
if (index < 0) {
return
}
if (changeSibling) {
var before = list[index - 1];
var after = list[index + 1];
before && (before.nextSibling = after);
after && (after.previousSibling = before);
}
list.splice(index, 1);
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var Node = function Node () {
this.nodeId = uniqueId();
this.ref = this.nodeId;
this.children = [];
this.pureChildren = [];
this.parentNode = null;
this.nextSibling = null;
this.previousSibling = null;
};
/**
* Destroy current node, and remove itself form nodeMap.
*/
Node.prototype.destroy = function destroy () {
var doc = getDoc(this.docId);
if (doc) {
delete this.docId;
delete doc.nodeMap[this.nodeId];
}
this.children.forEach(function (child) {
child.destroy();
});
};
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var Element$2;
function setElement (El) {
Element$2 = El;
}
/**
* A map which stores all type of elements.
* @type {Object}
*/
var registeredElements = {};
/**
* Register an extended element type with component methods.
* @param {string} type component type
* @param {array} methods a list of method names
*/
function registerElement (type, methods) {
// Skip when no special component methods.
if (!methods || !methods.length) {
return
}
// Init constructor.
var WeexElement = (function (Element) {
function WeexElement () {
Element.apply(this, arguments);
}if ( Element ) WeexElement.__proto__ = Element;
WeexElement.prototype = Object.create( Element && Element.prototype );
WeexElement.prototype.constructor = WeexElement;
return WeexElement;
}(Element$2));
// Add methods to prototype.
methods.forEach(function (methodName) {
WeexElement.prototype[methodName] = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var taskCenter = getTaskCenter(this.docId);
if (taskCenter) {
return taskCenter.send('component', {
ref: this.ref,
component: type,
method: methodName
}, args)
}
};
});
// Add to element type map.
registeredElements[type] = WeexElement;
}
function getWeexElement (type) {
return registeredElements[type]
}
/**
* Clear all element types. Only for testing.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// match the binding delimiter
var delimiterRE = /\[\[((?:.|\n)+?)\]\]/g;
function generateBinding (text) {
if (typof(text) === 'String') {
return { '@binding': text }
}
return text
}
function parseString (string) {
var tokens = [];
var lastIndex = delimiterRE.lastIndex = 0;
var match, index;
while ((match = delimiterRE.exec(string))) {
index = match.index;
if (index > lastIndex) {
tokens.push(string.slice(lastIndex, index));
}
var binding = generateBinding(match[1].trim());
tokens.push(binding);
lastIndex = index + match[0].length;
}
if (lastIndex < string.length) {
tokens.push(string.slice(lastIndex));
}
if (tokens.length === 1) {
return tokens[0]
}
return tokens
}
function filterDirective (value) {
if (typof(value) === 'String' && delimiterRE.test(value)) {
return parseString(value)
}
if (typof(value) === 'Object') {
var realData = {};
for (var key in value) {
realData[key] = filterDirective(value[key]);
}
return realData
}
if (typof(value) === 'Array') {
return value.map(filterDirective)
}
return value
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var DEFAULT_TAG_NAME = 'div';
var BUBBLE_EVENTS = [
'click', 'longpress', 'touchstart', 'touchmove', 'touchend',
'panstart', 'panmove', 'panend', 'horizontalpan', 'verticalpan', 'swipe'
];
function registerNode (docId, node) {
var doc = getDoc(docId);
doc.nodeMap[node.nodeId] = node;
}
var Element = (function (Node$$1) {
function Element (type, props, isExtended) {
if ( type === void 0 ) type = DEFAULT_TAG_NAME;
Node$$1.call(this);
var WeexElement = getWeexElement(type);
if (WeexElement && !isExtended) {
return new WeexElement(props)
}
props = props || {};
this.nodeType = 1;
this.nodeId = uniqueId();
this.ref = this.nodeId;
this.type = type;
this.attr = props.attr || {};
this.style = props.style || {};
this.classStyle = props.classStyle || {};
this.event = {};
this.children = [];
this.pureChildren = [];
}
if ( Node$$1 ) Element.__proto__ = Node$$1;
Element.prototype = Object.create( Node$$1 && Node$$1.prototype );
Element.prototype.constructor = Element;
/**
* Append a child node.
* @param {object} node
* @return {undefined | number} the signal sent by native
*/
Element.prototype.appendChild = function appendChild (node) {
if (node.parentNode && node.parentNode !== this) {
return
}
/* istanbul ignore else */
if (!node.parentNode) {
linkParent(node, this);
insertIndex(node, this.children, this.children.length, true);
if (this.docId) {
registerNode(this.docId, node);
}
if (node.nodeType === 1) {
insertIndex(node, this.pureChildren, this.pureChildren.length);
var taskCenter = getTaskCenter(this.docId);
if (taskCenter) {
return taskCenter.send(
'dom',
{ action: 'addElement' },
[this.ref, node.toJSON(), -1]
)
}
}
}
else {
moveIndex(node, this.children, this.children.length, true);
if (node.nodeType === 1) {
var index = moveIndex(node, this.pureChildren, this.pureChildren.length);
var taskCenter$1 = getTaskCenter(this.docId);
if (taskCenter$1 && index >= 0) {
return taskCenter$1.send(
'dom',
{ action: 'moveElement' },
[node.ref, this.ref, index]
)
}
}
}
};
/**
* Insert a node before specified node.
* @param {object} node
* @param {object} before
* @return {undefined | number} the signal sent by native
*/
Element.prototype.insertBefore = function insertBefore (node, before) {
if (node.parentNode && node.parentNode !== this) {
return
}
if (node === before || (node.nextSibling && node.nextSibling === before)) {
return
}
if (!node.parentNode) {
linkParent(node, this);
insertIndex(node, this.children, this.children.indexOf(before), true);
if (this.docId) {
registerNode(this.docId, node);
}
if (node.nodeType === 1) {
var pureBefore = nextElement(before);
var index = insertIndex(
node,
this.pureChildren,
pureBefore
? this.pureChildren.indexOf(pureBefore)
: this.pureChildren.length
);
var taskCenter = getTaskCenter(this.docId);
if (taskCenter) {
return taskCenter.send(
'dom',
{ action: 'addElement' },
[this.ref, node.toJSON(), index]
)
}
}
}
else {
moveIndex(node, this.children, this.children.indexOf(before), true);
if (node.nodeType === 1) {
var pureBefore$1 = nextElement(before);
/* istanbul ignore next */
var index$1 = moveIndex(
node,
this.pureChildren,
pureBefore$1
? this.pureChildren.indexOf(pureBefore$1)
: this.pureChildren.length
);
var taskCenter$1 = getTaskCenter(this.docId);
if (taskCenter$1 && index$1 >= 0) {
return taskCenter$1.send(
'dom',
{ action: 'moveElement' },
[node.ref, this.ref, index$1]
)
}
}
}
};
/**
* Insert a node after specified node.
* @param {object} node
* @param {object} after
* @return {undefined | number} the signal sent by native
*/
Element.prototype.insertAfter = function insertAfter (node, after) {
if (node.parentNode && node.parentNode !== this) {
return
}
if (node === after || (node.previousSibling && node.previousSibling === after)) {
return
}
if (!node.parentNode) {
linkParent(node, this);
insertIndex(node, this.children, this.children.indexOf(after) + 1, true);
/* istanbul ignore else */
if (this.docId) {
registerNode(this.docId, node);
}
if (node.nodeType === 1) {
var index = insertIndex(
node,
this.pureChildren,
this.pureChildren.indexOf(previousElement(after)) + 1
);
var taskCenter = getTaskCenter(this.docId);
/* istanbul ignore else */
if (taskCenter) {
return taskCenter.send(
'dom',
{ action: 'addElement' },
[this.ref, node.toJSON(), index]
)
}
}
}
else {
moveIndex(node, this.children, this.children.indexOf(after) + 1, true);
if (node.nodeType === 1) {
var index$1 = moveIndex(
node,
this.pureChildren,
this.pureChildren.indexOf(previousElement(after)) + 1
);
var taskCenter$1 = getTaskCenter(this.docId);
if (taskCenter$1 && index$1 >= 0) {
return taskCenter$1.send(
'dom',
{ action: 'moveElement' },
[node.ref, this.ref, index$1]
)
}
}
}
};
/**
* Remove a child node, and decide whether it should be destroyed.
* @param {object} node
* @param {boolean} preserved
*/
Element.prototype.removeChild = function removeChild (node, preserved) {
if (node.parentNode) {
removeIndex(node, this.children, true);
if (node.nodeType === 1) {
removeIndex(node, this.pureChildren);
var taskCenter = getTaskCenter(this.docId);
if (taskCenter) {
taskCenter.send(
'dom',
{ action: 'removeElement' },
[node.ref]
);
}
}
}
if (!preserved) {
node.destroy();
}
};
/**
* Clear all child nodes.
*/
Element.prototype.clear = function clear () {
var taskCenter = getTaskCenter(this.docId);
/* istanbul ignore else */
if (taskCenter) {
this.pureChildren.forEach(function (node) {
taskCenter.send(
'dom',
{ action: 'removeElement' },
[node.ref]
);
});
}
this.children.forEach(function (node) {
node.destroy();
});
this.children.length = 0;
this.pureChildren.length = 0;
};
/**
* Set an attribute, and decide whether the task should be send to native.
* @param {string} key
* @param {string | number} value
* @param {boolean} silent
*/
Element.prototype.setAttr = function setAttr (key, value, silent) {
if (this.attr[key] === value && silent !== false) {
return
}
this.attr[key] = value;
var taskCenter = getTaskCenter(this.docId);
if (!silent && taskCenter) {
var result = {};
result[key] = filterDirective(value);
taskCenter.send(
'dom',
{ action: 'updateAttrs' },
[this.ref, result]
);
}
};
/**
* Set a style property, and decide whether the task should be send to native.
* @param {string} key
* @param {string | number} value
* @param {boolean} silent
*/
Element.prototype.setStyle = function setStyle (key, value, silent) {
if (this.style[key] === value && silent !== false) {
return
}
this.style[key] = value;
var taskCenter = getTaskCenter(this.docId);
if (!silent && taskCenter) {
var result = {};
result[key] = value;
taskCenter.send(
'dom',
{ action: 'updateStyle' },
[this.ref, result]
);
}
};
/**
* Set style properties from class.
* @param {object} classStyle
*/
Element.prototype.setClassStyle = function setClassStyle (classStyle) {
var this$1 = this;
// reset previous class style to empty string
for (var key in this.classStyle) {
this$1.classStyle[key] = '';
}
Object.assign(this.classStyle, classStyle);
var taskCenter = getTaskCenter(this.docId);
if (taskCenter) {
taskCenter.send(
'dom',
{ action: 'updateStyle' },
[this.ref, this.toStyle()]
);
}
};
/**
* Add an event handler.
* @param {string} event type
* @param {function} event handler
*/
Element.prototype.addEvent = function addEvent (type, handler, params) {
if (!this.event) {
this.event = {};
}
if (!this.event[type]) {
this.event[type] = { handler: handler, params: params };
var taskCenter = getTaskCenter(this.docId);
if (taskCenter) {
taskCenter.send(
'dom',
{ action: 'addEvent' },
[this.ref, type]
);
}
}
};
/**
* Remove an event handler.
* @param {string} event type
*/
Element.prototype.removeEvent = function removeEvent (type) {
if (this.event && this.event[type]) {
delete this.event[type];
var taskCenter = getTaskCenter(this.docId);
if (taskCenter) {
taskCenter.send(
'dom',
{ action: 'removeEvent' },
[this.ref, type]
);
}
}
};
/**
* Fire an event manually.
* @param {string} type type
* @param {function} event handler
* @param {boolean} isBubble whether or not event bubble
* @param {boolean} options
* @return {} anything returned by handler function
*/
Element.prototype.fireEvent = function fireEvent (type, event, isBubble, options) {
var result = null;
var isStopPropagation = false;
var eventDesc = this.event[type];
if (eventDesc && event) {
var handler = eventDesc.handler;
event.stopPropagation = function () {
isStopPropagation = true;
};
if (options && options.params) {
result = handler.call.apply(handler, [ this ].concat( options.params, [event] ));
}
else {
result = handler.call(this, event);
}
}
if (!isStopPropagation
&& isBubble
&& BUBBLE_EVENTS.includes(type)
&& this.parentNode
&& this.parentNode.fireEvent) {
event.currentTarget = this.parentNode;
this.parentNode.fireEvent(type, event, isBubble); // no options
}
return result
};
/**
* Get all styles of current element.
* @return {object} style
*/
Element.prototype.toStyle = function toStyle () {
return Object.assign({}, this.classStyle, this.style)
};
/**
* Convert current element to JSON like object.
* @return {object} element
*/
Element.prototype.toJSON = function toJSON () {
var this$1 = this;
var result = {
ref: this.ref.toString(),
type: this.type,
attr: filterDirective(this.attr),
style: this.toStyle()
};
var event = [];
for (var type in this.event) {
var ref = this$1.event[type];
var params = ref.params;
if (!params) {
event.push(type);
}
else {
event.push({ type: type, params: params });
}
}
if (event.length) {
result.event = event;
}
if (this.pureChildren.length) {
result.children = this.pureChildren.map(function (child) { return child.toJSON(); });
}
return result
};
/**
* Convert to HTML element tag string.
* @return {stirng} html
*/
Element.prototype.toString = function toString () {
return '<' + this.type +
' attr=' + JSON.stringify(this.attr) +
' style=' + JSON.stringify(this.toStyle()) + '>' +
this.pureChildren.map(function (child) { return child.toString(); }).join('') +
'</' + this.type + '>'
};
return Element;
}(Node));
setElement(Element);
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var fallback = function () {};
// The API of TaskCenter would be re-design.
var TaskCenter = function TaskCenter (id, sendTasks) {
Object.defineProperty(this, 'instanceId', {
enumerable: true,
value: id
});
Object.defineProperty(this, 'callbackManager', {
enumerable: true,
value: new CallbackManager(id)
});
fallback = sendTasks || function () {};
};
TaskCenter.prototype.callback = function callback (callbackId, data, ifKeepAlive) {
return this.callbackManager.consume(callbackId, data, ifKeepAlive)
};
TaskCenter.prototype.destroyCallback = function destroyCallback () {
return this.callbackManager.close()
};
/**
* Normalize a value. Specially, if the value is a function, then generate a function id
* and save it to `CallbackManager`, at last return the function id.
* @param{any} v
* @return {primitive}
*/
TaskCenter.prototype.normalize = function normalize (v) {
var type = typof(v);
if (v && v instanceof Element) {
return v.ref
}
if (v && v._isVue && v.$el instanceof Element) {
return v.$el.ref
}
if (type === 'Function') {
return this.callbackManager.add(v).toString()
}
return normalizePrimitive(v)
};
TaskCenter.prototype.send = function send (type, params, args, options) {
var this$1 = this;
var action = params.action;
var component = params.component;
var ref = params.ref;
var module = params.module;
var method = params.method;
args = args.map(function (arg) { return this$1.normalize(arg); });
switch (type) {
case 'dom':
return this[action](this.instanceId, args)
case 'component':
return this.componentHandler(this.instanceId, ref, method, args, Object.assign({ component: component }, options))
default:
return this.moduleHandler(this.instanceId, module, method, args, options)
}
};
TaskCenter.prototype.callDOM = function callDOM (action, args) {
return this[action](this.instanceId, args)
};
TaskCenter.prototype.callComponent = function callComponent (ref, method, args, options) {
return this.componentHandler(this.instanceId, ref, method, args, options)
};
TaskCenter.prototype.callModule = function callModule (module, method, args, options) {
return this.moduleHandler(this.instanceId, module, method, args, options)
};
function init$1 () {
var DOM_METHODS = {
createFinish: global.callCreateFinish,
updateFinish: global.callUpdateFinish,
refreshFinish: global.callRefreshFinish,
createBody: global.callCreateBody,
addElement: global.callAddElement,
removeElement: global.callRemoveElement,
moveElement: global.callMoveElement,
updateAttrs: global.callUpdateAttrs,
updateStyle: global.callUpdateStyle,
addEvent: global.callAddEvent,
removeEvent: global.callRemoveEvent
};
var proto = TaskCenter.prototype;
var loop = function ( name ) {
var method = DOM_METHODS[name];
proto[name] = method ?
function (id, args) { return method.apply(void 0, [ id ].concat( args )); } :
function (id, args) { return fallback(id, [{ module: 'dom', method: name, args: args }], '-1'); };
};
for (var name in DOM_METHODS) loop( name );
proto.componentHandler = global.callNativeComponent ||
(function (id, ref, method, args, options) { return fallback(id, [{ component: options.component, ref: ref, method: method, args: args }]); });
proto.moduleHandler = global.callNativeModule ||
(function (id, module, method, args) { return fallback(id, [{ module: module, method: method, args: args }]); });
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// JS Services
var services = [];
/**
* Register a JavaScript service.
* A JavaScript service options could have a set of lifecycle methods
* for each Weex instance. For example: create, refresh, destroy.
* For the JS framework maintainer if you want to supply some features
* which need to work well in different Weex instances, even in different
* frameworks separately. You can make a JavaScript service to init
* its variables or classes for each Weex instance when it's created
* and recycle them when it's destroyed.
* @param {object} options Could have { create, refresh, destroy }
* lifecycle methods. In create method it should
* return an object of what variables or classes
* would be injected into the Weex instance.
*/
function register (name, options) {
if (has$4(name)) {
console.warn(("Service \"" + name + "\" has been registered already!"));
}
else {
options = Object.assign({}, options);
services.push({ name: name, options: options });
}
}
/**
* Unregister a JavaScript service by name
* @param {string} name
*/
function unregister (name) {
services.some(function (service, index) {
if (service.name === name) {
services.splice(index, 1);
return true
}
});
}
/**
* Check if a JavaScript service with a certain name existed.
* @param {string} name
* @return {Boolean}
*/
function has$4 (name) {
return indexOf(name) >= 0
}
/**
* Find the index of a JavaScript service by name
* @param {string} name
* @return {number}
*/
function indexOf (name) {
return services.map(function (service) { return service.name; }).indexOf(name)
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var frameworks;
var runtimeConfig;
var versionRegExp = /^\s*\/\/ *(\{[^}]*\}) *\r?\n/;
/**
* Detect a JS Bundle code and make sure which framework it's based to. Each JS
* Bundle should make sure that it starts with a line of JSON comment and is
* more that one line.
* @param {string} code
* @return {object}
*/
function getBundleType (code) {
var result = versionRegExp.exec(code);
if (result) {
try {
var info = JSON.parse(result[1]);
return info.framework
}
catch (e) {}
}
// default bundle type
return 'Weex'
}
function createServices (id, env, config) {
// Init JavaScript services for this instance.
var serviceMap = Object.create(null);
serviceMap.service = Object.create(null);
services.forEach(function (ref) {
var name = ref.name;
var options = ref.options;
{
console.debug(("[JS Runtime] create service " + name + "."));
}
var create = options.create;
if (create) {
var result = create(id, env, config);
Object.assign(serviceMap.service, result);
Object.assign(serviceMap, result.instance);
}
});
delete serviceMap.service.instance;
Object.freeze(serviceMap.service);
return serviceMap
}
var instanceMap = {};
function getFrameworkType (id) {
if (instanceMap[id]) {
return instanceMap[id].framework
}
}
/**
* Check which framework a certain JS Bundle code based to. And create instance
* by this framework.
* @param {string} id
* @param {string} code
* @param {object} config
* @param {object} data
*/
function createInstance (id, code, config, data) {
if (instanceMap[id]) {
return new Error(("invalid instance id \"" + id + "\""))
}
// Init instance info.
var bundleType = getBundleType(code);
// Init instance config.
config = JSON.parse(JSON.stringify(config || {}));
config.env = JSON.parse(JSON.stringify(global.WXEnvironment || {}));
var context = {
config: config,
created: Date.now(),
framework: bundleType
};
context.services = createServices(id, context, runtimeConfig);
instanceMap[id] = context;
{
console.debug(("[JS Framework] create an " + bundleType + " instance"));
}
var fm = frameworks[bundleType];
if (!fm) {
return new Error(("invalid bundle type \"" + bundleType + "\"."))
}
return fm.createInstance(id, code, config, data, context)
}
var methods = {
createInstance: createInstance,
registerService: register,
unregisterService: unregister
};
/**
* Register methods which init each frameworks.
* @param {string} methodName
*/
function genInit (methodName) {
methods[methodName] = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
if (methodName === 'registerComponents') {
checkComponentMethods(args[0]);
}
for (var name in frameworks) {
var framework = frameworks[name];
if (framework && framework[methodName]) {
framework[methodName].apply(framework, args);
}
}
};
}
function checkComponentMethods (components) {
if (Array.isArray(components)) {
components.forEach(function (name) {
if (name && name.type && name.methods) {
registerElement(name.type, name.methods);
}
});
}
}
/**
* Register methods which will be called for each instance.
* @param {string} methodName
*/
function genInstance (methodName) {
methods[methodName] = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var id = args[0];
var type = getFrameworkType(id);
if (type && frameworks[type]) {
var result = (ref = frameworks[type])[methodName].apply(ref, args);
var info = { framework: type };
// Lifecycle methods
if (methodName === 'refreshInstance') {
services.forEach(function (service) {
var refresh = service.options.refresh;
if (refresh) {
refresh(id, { info: info, runtime: runtimeConfig });
}
});
}
else if (methodName === 'destroyInstance') {
services.forEach(function (service) {
var destroy = service.options.destroy;
if (destroy) {
destroy(id, { info: info, runtime: runtimeConfig });
}
});
delete instanceMap[id];
}
return result
}
return new Error(("invalid instance id \"" + id + "\""))
var ref;
};
}
/**
* Adapt some legacy method(s) which will be called for each instance. These
* methods should be deprecated and removed later.
* @param {string} methodName
* @param {string} nativeMethodName
*/
function adaptInstance (methodName, nativeMethodName) {
methods[nativeMethodName] = function () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
var id = args[0];
var type = getFrameworkType(id);
if (type && frameworks[type]) {
return (ref = frameworks[type])[methodName].apply(ref, args)
}
return new Error(("invalid instance id \"" + id + "\""))
var ref;
};
}
function init$$1 (config) {
runtimeConfig = config || {};
frameworks = runtimeConfig.frameworks || {};
init$1();
// Init each framework by `init` method and `config` which contains three
// virtual-DOM Class: `Document`, `Element` & `Comment`, and a JS bridge method:
// `sendTasks(...args)`.
for (var name in frameworks) {
var framework = frameworks[name];
framework.init(config);
}
// @todo: The method `registerMethods` will be re-designed or removed later.
['registerComponents', 'registerModules', 'registerMethods'].forEach(genInit)
; ['destroyInstance', 'refreshInstance', 'receiveTasks', 'getRoot'].forEach(genInstance);
adaptInstance('receiveTasks', 'callJS');
return methods
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var Comment = (function (Node$$1) {
function Comment (value) {
Node$$1.call(this);
this.nodeType = 8;
this.nodeId = uniqueId();
this.ref = this.nodeId;
this.type = 'comment';
this.value = value;
this.children = [];
this.pureChildren = [];
}
if ( Node$$1 ) Comment.__proto__ = Node$$1;
Comment.prototype = Object.create( Node$$1 && Node$$1.prototype );
Comment.prototype.constructor = Comment;
/**
* Convert to HTML comment string.
* @return {stirng} html
*/
Comment.prototype.toString = function toString () {
return '<!-- ' + this.value + ' -->'
};
return Comment;
}(Node));
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* Create the action object.
* @param {string} name
* @param {array} arguments
* @return {object} action
*/
function createAction (name, args) {
if ( args === void 0 ) args = [];
return { module: 'dom', method: name, args: args }
}
var Listener = function Listener (id, handler) {
this.id = id;
this.batched = false;
this.updates = [];
if (typeof handler === 'function') {
Object.defineProperty(this, 'handler', {
configurable: true,
enumerable: true,
writable: true,
value: handler
});
}
else {
console.error('[JS Runtime] invalid parameter, handler must be a function');
}
};
/**
* Send the "createFinish" signal.
* @param {function} callback
* @return {undefined | number} the signal sent by native
*/
Listener.prototype.createFinish = function createFinish (callback) {
var handler = this.handler;
return handler([createAction('createFinish')], callback)
};
/**
* Send the "updateFinish" signal.
* @param {function} callback
* @return {undefined | number} the signal sent by native
*/
Listener.prototype.updateFinish = function updateFinish (callback) {
var handler = this.handler;
return handler([createAction('updateFinish')], callback)
};
/**
* Send the "refreshFinish" signal.
* @param {function} callback
* @return {undefined | number} the signal sent by native
*/
Listener.prototype.refreshFinish = function refreshFinish (callback) {
var handler = this.handler;
return handler([createAction('refreshFinish')], callback)
};
/**
* Send the "createBody" signal.
* @param {object} element
* @return {undefined | number} the signal sent by native
*/
Listener.prototype.createBody = function createBody (element) {
var body = element.toJSON();
var children = body.children;
delete body.children;
var actions = [createAction('createBody', [body])];
if (children) {
actions.push.apply(actions, children.map(function (child) {
return createAction('addElement', [body.ref, child, -1])
}));
}
return this.addActions(actions)
};
/**
* Send the "addElement" signal.
* @param {object} element
* @param {stirng} reference id
* @param {number} index
* @return {undefined | number} the signal sent by native
*/
Listener.prototype.addElement = function addElement (element, ref, index) {
if (!(index >= 0)) {
index = -1;
}
return this.addActions(createAction('addElement', [ref, element.toJSON(), index]))
};
/**
* Send the "removeElement" signal.
* @param {stirng} reference id
* @return {undefined | number} the signal sent by native
*/
Listener.prototype.removeElement = function removeElement (ref) {
if (Array.isArray(ref)) {
var actions = ref.map(function (r) { return createAction('removeElement', [r]); });
return this.addActions(actions)
}
return this.addActions(createAction('removeElement', [ref]))
};
/**
* Send the "moveElement" signal.
* @param {stirng} target reference id
* @param {stirng} parent reference id
* @param {number} index
* @return {undefined | number} the signal sent by native
*/
Listener.prototype.moveElement = function moveElement (targetRef, parentRef, index) {
return this.addActions(createAction('moveElement', [targetRef, parentRef, index]))
};
/**
* Send the "updateAttrs" signal.
* @param {stirng} reference id
* @param {stirng} key
* @param {stirng} value
* @return {undefined | number} the signal sent by native
*/
Listener.prototype.setAttr = function setAttr (ref, key, value) {
var result = {};
result[key] = value;
return this.addActions(createAction('updateAttrs', [ref, result]))
};
/**
* Send the "updateStyle" signal, update a sole style.
* @param {stirng} reference id
* @param {stirng} key
* @param {stirng} value
* @return {undefined | number} the signal sent by native
*/
Listener.prototype.setStyle = function setStyle (ref, key, value) {
var result = {};
result[key] = value;
return this.addActions(createAction('updateStyle', [ref, result]))
};
/**
* Send the "updateStyle" signal.
* @param {stirng} reference id
* @param {object} style
* @return {undefined | number} the signal sent by native
*/
Listener.prototype.setStyles = function setStyles (ref, style) {
return this.addActions(createAction('updateStyle', [ref, style]))
};
/**
* Send the "addEvent" signal.
* @param {stirng} reference id
* @param {string} event type
* @return {undefined | number} the signal sent by native
*/
Listener.prototype.addEvent = function addEvent (ref, type) {
return this.addActions(createAction('addEvent', [ref, type]))
};
/**
* Send the "removeEvent" signal.
* @param {stirng} reference id
* @param {string} event type
* @return {undefined | number} the signal sent by native
*/
Listener.prototype.removeEvent = function removeEvent (ref, type) {
return this.addActions(createAction('removeEvent', [ref, type]))
};
/**
* Default handler.
* @param {object | array} actions
* @param {function} callback
* @return {} anything returned by callback function
*/
Listener.prototype.handler = function handler (actions, cb) {
return cb && cb()
};
/**
* Add actions into updates.
* @param {object | array} actions
* @return {undefined | number} the signal sent by native
*/
Listener.prototype.addActions = function addActions (actions) {
var updates = this.updates;
var handler = this.handler;
if (!Array.isArray(actions)) {
actions = [actions];
}
if (this.batched) {
updates.push.apply(updates, actions);
}
else {
return handler(actions)
}
};
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* @fileOverview
* Task handler for communication between javascript and native.
*/
var handlerMap = {
createBody: 'callCreateBody',
addElement: 'callAddElement',
removeElement: 'callRemoveElement',
moveElement: 'callMoveElement',
updateAttrs: 'callUpdateAttrs',
updateStyle: 'callUpdateStyle',
addEvent: 'callAddEvent',
removeEvent: 'callRemoveEvent'
};
/**
* Create a task handler.
* @param {string} id
* @param {function} handler
* @return {function} taskHandler
*/
function createHandler (id, handler) {
var defaultHandler = handler || global.callNative;
/* istanbul ignore if */
if (typeof defaultHandler !== 'function') {
console.error('[JS Runtime] no default handler');
}
return function taskHandler (tasks) {
/* istanbul ignore if */
if (!Array.isArray(tasks)) {
tasks = [tasks];
}
for (var i = 0; i < tasks.length; i++) {
var returnValue = dispatchTask(id, tasks[i], defaultHandler);
if (returnValue === -1) {
return returnValue
}
}
}
}
/**
* Check if there is a corresponding available handler in the environment.
* @param {string} module
* @param {string} method
* @return {boolean}
*/
function hasAvailableHandler (module, method) {
return module === 'dom'
&& handlerMap[method]
&& typeof global[handlerMap[method]] === 'function'
}
/**
* Dispatch the task to the specified handler.
* @param {string} id
* @param {object} task
* @param {function} defaultHandler
* @return {number} signal returned from native
*/
function dispatchTask (id, task, defaultHandler) {
var module = task.module;
var method = task.method;
var args = task.args;
if (hasAvailableHandler(module, method)) {
return global[handlerMap[method]].apply(global, [ id ].concat( args, ['-1'] ))
}
return defaultHandler(id, [task], '-1')
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* Update all changes for an element.
* @param {object} element
* @param {object} changes
*/
function updateElement (el, changes) {
var attrs = changes.attrs || {};
for (var name in attrs) {
el.setAttr(name, attrs[name], true);
}
var style = changes.style || {};
for (var name$1 in style) {
el.setStyle(name$1, style[name$1], true);
}
}
var Document = function Document (id, url, handler) {
id = id ? id.toString() : '';
this.id = id;
this.URL = url;
addDoc(id, this);
this.nodeMap = {};
var L = Document.Listener || Listener;
this.listener = new L(id, handler || createHandler(id, Document.handler)); // deprecated
this.taskCenter = new TaskCenter(id, handler ? function (id) {
var args = [], len = arguments.length - 1;
while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ];
return handler.apply(void 0, args);
} : Document.handler);
this.createDocumentElement();
};
/**
* Get the node from nodeMap.
* @param {string} reference id
* @return {object} node
*/
Document.prototype.getRef = function getRef (ref) {
return this.nodeMap[ref]
};
/**
* Turn on batched updates.
*/
Document.prototype.open = function open () {
this.listener.batched = false;
};
/**
* Turn off batched updates.
*/
Document.prototype.close = function close () {
this.listener.batched = true;
};
/**
* Create the document element.
* @return {object} documentElement
*/
Document.prototype.createDocumentElement = function createDocumentElement () {
var this$1 = this;
if (!this.documentElement) {
var el = new Element('document');
el.docId = this.id;
el.ownerDocument = this;
el.role = 'documentElement';
el.depth = 0;
el.ref = '_documentElement';
this.nodeMap._documentElement = el;
this.documentElement = el;
Object.defineProperty(el, 'appendChild', {
configurable: true,
enumerable: true,
writable: true,
value: function (node) {
appendBody(this$1, node);
}
});
Object.defineProperty(el, 'insertBefore', {
configurable: true,
enumerable: true,
writable: true,
value: function (node, before) {
appendBody(this$1, node, before);
}
});
}
return this.documentElement
};
/**
* Create the body element.
* @param {string} type
* @param {objct} props
* @return {object} body element
*/
Document.prototype.createBody = function createBody (type, props) {
if (!this.body) {
var el = new Element(type, props);
setBody(this, el);
}
return this.body
};
/**
* Create an element.
* @param {string} tagName
* @param {objct} props
* @return {object} element
*/
Document.prototype.createElement = function createElement (tagName, props) {
return new Element(tagName, props)
};
/**
* Create an comment.
* @param {string} text
* @return {object} comment
*/
Document.prototype.createComment = function createComment (text) {
return new Comment(text)
};
/**
* Fire an event on specified element manually.
* @param {object} element
* @param {string} event type
* @param {object} event object
* @param {object} dom changes
* @param {object} options
* @return {} anything returned by handler function
*/
Document.prototype.fireEvent = function fireEvent (el, type, event, domChanges, options) {
if (!el) {
return
}
event = event || {};
event.type = type;
event.target = el;
event.currentTarget = el;
event.timestamp = Date.now();
if (domChanges) {
updateElement(el, domChanges);
}
var isBubble = this.getRef('_root').attr['bubble'] === 'true';
return el.fireEvent(type, event, isBubble, options)
};
/**
* Destroy current document, and remove itself form docMap.
*/
Document.prototype.destroy = function destroy () {
this.taskCenter.destroyCallback();
delete this.listener;
delete this.nodeMap;
delete this.taskCenter;
removeDoc(this.id);
};
// default task handler
Document.handler = null;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var config = {
Document: Document, Element: Element, Comment: Comment, Listener: Listener,
TaskCenter: TaskCenter,
sendTasks: function sendTasks () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
if (typeof callNative === 'function') {
return callNative.apply(void 0, args)
}
return (global.callNative || (function () {})).apply(void 0, args)
}
};
Document.handler = config.sendTasks;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* @fileOverview
* Register framework(s) in JS runtime. Weex supply two layers for 3rd-party
* framework(s): one is the instance management layer, another is the
* virtual-DOM layer.
*/
/* istanbul ignore next */
function freezePrototype$$1 () {
freezePrototype$1();
Object.freeze(config.Element);
Object.freeze(config.Comment);
Object.freeze(config.Listener);
Object.freeze(config.Document.prototype);
Object.freeze(config.Element.prototype);
Object.freeze(config.Comment.prototype);
Object.freeze(config.Listener.prototype);
}
var index = {
setNativeConsole: setNativeConsole,
resetNativeConsole: resetNativeConsole,
setNativeTimer: setNativeTimer,
resetNativeTimer: resetNativeTimer,
service: { register: register, unregister: unregister, has: has$4 },
freezePrototype: freezePrototype$$1,
init: init$$1,
config: config
};
return index;
})));