utils-lib-js 2.0.5 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle/animate.d.ts +25 -0
- package/dist/bundle/array.d.ts +10 -0
- package/dist/bundle/base.d.ts +15 -0
- package/dist/bundle/element.d.ts +6 -0
- package/dist/bundle/event.d.ts +14 -0
- package/dist/bundle/function.d.ts +12 -0
- package/dist/bundle/index.d.ts +67 -0
- package/dist/bundle/index.js +7 -0
- package/dist/bundle/log.d.ts +8 -0
- package/dist/bundle/object.d.ts +32 -0
- package/dist/bundle/static.d.ts +16 -0
- package/dist/bundle/storage.d.ts +9 -0
- package/dist/bundle/types.d.ts +68 -0
- package/dist/cjs/animate.d.ts +25 -0
- package/dist/cjs/array.d.ts +10 -0
- package/dist/cjs/base.d.ts +15 -0
- package/dist/cjs/element.d.ts +6 -0
- package/dist/cjs/event.d.ts +14 -0
- package/dist/cjs/function.d.ts +12 -0
- package/dist/cjs/index.d.ts +67 -0
- package/dist/cjs/index.js +3021 -0
- package/dist/cjs/log.d.ts +8 -0
- package/dist/cjs/object.d.ts +32 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/static.d.ts +16 -0
- package/dist/cjs/storage.d.ts +9 -0
- package/dist/cjs/types.d.ts +68 -0
- package/dist/esm/animate.d.ts +25 -0
- package/dist/esm/array.d.ts +10 -0
- package/dist/esm/base.d.ts +15 -0
- package/dist/esm/element.d.ts +6 -0
- package/dist/esm/event.d.ts +14 -0
- package/dist/esm/function.d.ts +12 -0
- package/dist/esm/index.d.ts +67 -0
- package/dist/esm/index.js +2968 -0
- package/dist/esm/log.d.ts +8 -0
- package/dist/esm/object.d.ts +32 -0
- package/dist/esm/static.d.ts +16 -0
- package/dist/esm/storage.d.ts +9 -0
- package/dist/esm/types.d.ts +68 -0
- package/dist/umd/animate.d.ts +25 -0
- package/dist/umd/array.d.ts +10 -0
- package/dist/umd/base.d.ts +15 -0
- package/dist/umd/element.d.ts +6 -0
- package/dist/umd/event.d.ts +14 -0
- package/dist/umd/function.d.ts +12 -0
- package/dist/umd/index.d.ts +67 -0
- package/dist/umd/index.js +3023 -0
- package/dist/umd/log.d.ts +8 -0
- package/dist/umd/object.d.ts +32 -0
- package/dist/umd/static.d.ts +16 -0
- package/dist/umd/storage.d.ts +9 -0
- package/dist/umd/types.d.ts +68 -0
- package/package.json +1 -1
|
@@ -0,0 +1,3023 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('http'), require('https'), require('url')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'http', 'https', 'url'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.UtilsLib = {}, global.http, global.https, global.url));
|
|
5
|
+
})(this, (function (exports, http, https, url) { 'use strict';
|
|
6
|
+
|
|
7
|
+
/******************************************************************************
|
|
8
|
+
Copyright (c) Microsoft Corporation.
|
|
9
|
+
|
|
10
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
+
purpose with or without fee is hereby granted.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
20
|
+
***************************************************************************** */
|
|
21
|
+
|
|
22
|
+
var __assign$4 = function() {
|
|
23
|
+
__assign$4 = Object.assign || function __assign(t) {
|
|
24
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
25
|
+
s = arguments[i];
|
|
26
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
27
|
+
}
|
|
28
|
+
return t;
|
|
29
|
+
};
|
|
30
|
+
return __assign$4.apply(this, arguments);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
function __spreadArray$1(to, from, pack) {
|
|
34
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
35
|
+
if (ar || !(i in from)) {
|
|
36
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
37
|
+
ar[i] = from[i];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
exports.types = void 0;
|
|
44
|
+
(function (types) {
|
|
45
|
+
types["[object Array]"] = "array";
|
|
46
|
+
types["[object Object]"] = "object";
|
|
47
|
+
types["[object Function]"] = "function";
|
|
48
|
+
types["[object Set]"] = "set";
|
|
49
|
+
types["[object Map]"] = "map";
|
|
50
|
+
types["[object WeakMap]"] = "weakMap";
|
|
51
|
+
types["[object WeakSet]"] = "weakSet";
|
|
52
|
+
types["[object Date]"] = "date";
|
|
53
|
+
types["[object RegExp]"] = "regExp";
|
|
54
|
+
types["[object Math]"] = "math";
|
|
55
|
+
})(exports.types || (exports.types = {}));
|
|
56
|
+
var __static$1 = { types: exports.types };
|
|
57
|
+
|
|
58
|
+
var randomNum$1 = function (min, max, bool) {
|
|
59
|
+
if (bool === void 0) { bool = false; }
|
|
60
|
+
return Math.floor(Math.random() * (max - min + (bool ? 1 : 0)) + min);
|
|
61
|
+
};
|
|
62
|
+
var urlSplit$1 = function (url) {
|
|
63
|
+
var result = {};
|
|
64
|
+
if (!url.includes("?")) {
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
var params = url.split("?")[1].split("&");
|
|
68
|
+
params.forEach(function (i) {
|
|
69
|
+
var key = i.split("=")[0];
|
|
70
|
+
result[key] = i.split("=")[1];
|
|
71
|
+
});
|
|
72
|
+
return result;
|
|
73
|
+
};
|
|
74
|
+
var urlJoin$1 = function (url, query) {
|
|
75
|
+
if (query === void 0) { query = {}; }
|
|
76
|
+
var queryObject = Object.keys(query);
|
|
77
|
+
if (queryObject.length === 0)
|
|
78
|
+
return url;
|
|
79
|
+
var params = queryObject.map(function (i) { return "".concat(i, "=").concat(query[i]); });
|
|
80
|
+
return "".concat(url).concat(url.includes("?") ? "&" : '?').concat(params.join("&"));
|
|
81
|
+
};
|
|
82
|
+
var getType$1 = function (data) {
|
|
83
|
+
var type = typeof data;
|
|
84
|
+
if (data === null) {
|
|
85
|
+
return "null";
|
|
86
|
+
}
|
|
87
|
+
else if (type === "object") {
|
|
88
|
+
var key = Object.prototype.toString.call(data);
|
|
89
|
+
return exports.types[key];
|
|
90
|
+
}
|
|
91
|
+
return type;
|
|
92
|
+
};
|
|
93
|
+
var getTypeByList$1 = function (data, whiteList) {
|
|
94
|
+
if (whiteList === void 0) { whiteList = []; }
|
|
95
|
+
var __type = getType$1(data);
|
|
96
|
+
return whiteList.indexOf(__type) > 0;
|
|
97
|
+
};
|
|
98
|
+
var base$1 = {
|
|
99
|
+
randomNum: randomNum$1,
|
|
100
|
+
urlSplit: urlSplit$1,
|
|
101
|
+
urlJoin: urlJoin$1,
|
|
102
|
+
getType: getType$1,
|
|
103
|
+
getTypeByList: getTypeByList$1,
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
var getValue$1 = function (object, key, defaultValue) {
|
|
107
|
+
if (defaultValue === void 0) { defaultValue = ''; }
|
|
108
|
+
var paths = key.split('.');
|
|
109
|
+
for (var _i = 0, paths_1 = paths; _i < paths_1.length; _i++) {
|
|
110
|
+
var i = paths_1[_i];
|
|
111
|
+
object = object[i];
|
|
112
|
+
if (object === undefined) {
|
|
113
|
+
return defaultValue;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return object;
|
|
117
|
+
};
|
|
118
|
+
var setValue$1 = function (object, key, value) {
|
|
119
|
+
if (value === void 0) { value = {}; }
|
|
120
|
+
var paths = key.split('.');
|
|
121
|
+
var last = paths[paths.length - 1];
|
|
122
|
+
var _object = object;
|
|
123
|
+
for (var _i = 0, paths_2 = paths; _i < paths_2.length; _i++) {
|
|
124
|
+
var i = paths_2[_i];
|
|
125
|
+
if (typeof _object !== "object" && _object !== undefined) {
|
|
126
|
+
return object;
|
|
127
|
+
}
|
|
128
|
+
!_object && (_object = {});
|
|
129
|
+
!_object[i] && (_object[i] = {});
|
|
130
|
+
last === i && (_object[last] = value);
|
|
131
|
+
_object = _object[i];
|
|
132
|
+
}
|
|
133
|
+
return object;
|
|
134
|
+
};
|
|
135
|
+
var mixIn$1 = function (target, source, overwrite) {
|
|
136
|
+
var _a;
|
|
137
|
+
if (source === void 0) { source = {}; }
|
|
138
|
+
if (overwrite === void 0) { overwrite = false; }
|
|
139
|
+
for (var k in source) {
|
|
140
|
+
for (var key in source[k]) {
|
|
141
|
+
var proto = (_a = target.prototype) !== null && _a !== void 0 ? _a : target;
|
|
142
|
+
if (target[key] === undefined || overwrite) {
|
|
143
|
+
proto[key] = source[k][key];
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return target;
|
|
148
|
+
};
|
|
149
|
+
var enumInversion$1 = function (target) {
|
|
150
|
+
for (var key in target) {
|
|
151
|
+
var _key = target[key];
|
|
152
|
+
if (typeof _key === "string" && !!!target[_key]) {
|
|
153
|
+
target[_key] = key;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return target;
|
|
157
|
+
};
|
|
158
|
+
var isNotObject$1 = function (source, type) { return (typeof source !== "object" || type === 'null'); };
|
|
159
|
+
var cloneDeep$1 = function (target) {
|
|
160
|
+
var __type = getType$1(target);
|
|
161
|
+
if (isNotObject$1(target, __type))
|
|
162
|
+
return target;
|
|
163
|
+
var __init = createObjectVariable$1(__type, target);
|
|
164
|
+
if (__type === "map") {
|
|
165
|
+
target.forEach(function (value, key) {
|
|
166
|
+
__init.set(key, cloneDeep$1(value));
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
else if (__type === "set") {
|
|
170
|
+
target.forEach(function (value) {
|
|
171
|
+
__init.add(cloneDeep$1(value));
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
Reflect.ownKeys(target).forEach(function (keys) {
|
|
176
|
+
var desc = target[keys];
|
|
177
|
+
__init[keys] = cloneDeep$1(desc);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
return __init;
|
|
181
|
+
};
|
|
182
|
+
var createObjectVariable$1 = function (type, source) {
|
|
183
|
+
if (source === void 0) { source = {}; }
|
|
184
|
+
switch (type) {
|
|
185
|
+
case "array":
|
|
186
|
+
return [];
|
|
187
|
+
case "function":
|
|
188
|
+
return source;
|
|
189
|
+
case "set":
|
|
190
|
+
return new Set();
|
|
191
|
+
case "map":
|
|
192
|
+
return new Map();
|
|
193
|
+
case "date":
|
|
194
|
+
return new Date(source);
|
|
195
|
+
case "regExp":
|
|
196
|
+
return new RegExp(source);
|
|
197
|
+
case "math":
|
|
198
|
+
return Math;
|
|
199
|
+
default:
|
|
200
|
+
return {};
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
var createObject$1 = function (source) {
|
|
204
|
+
function F() { }
|
|
205
|
+
F.prototype = source;
|
|
206
|
+
return new F();
|
|
207
|
+
};
|
|
208
|
+
var inherit$1 = function (source, target) {
|
|
209
|
+
if (target === void 0) { target = function () { }; }
|
|
210
|
+
target.prototype = createObject$1(source.prototype);
|
|
211
|
+
target.prototype.super = source;
|
|
212
|
+
target.prototype.constructor = target;
|
|
213
|
+
return target;
|
|
214
|
+
};
|
|
215
|
+
var getInstance$1 = function (classProto, overwrite) {
|
|
216
|
+
if (overwrite === void 0) { overwrite = false; }
|
|
217
|
+
var params = [];
|
|
218
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
219
|
+
params[_i - 2] = arguments[_i];
|
|
220
|
+
}
|
|
221
|
+
if (!classProto._instance || overwrite) {
|
|
222
|
+
classProto._instance = new (classProto.bind.apply(classProto, __spreadArray$1([void 0], params, false)))();
|
|
223
|
+
}
|
|
224
|
+
return classProto._instance;
|
|
225
|
+
};
|
|
226
|
+
var classDecorator$1 = function (params) {
|
|
227
|
+
return function (target) {
|
|
228
|
+
for (var key in params) {
|
|
229
|
+
if (!!!Reflect.has(target.prototype, key)) {
|
|
230
|
+
target.prototype[key] = params[key];
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
};
|
|
235
|
+
var stringToJson$1 = function (target) {
|
|
236
|
+
if (getType$1(target) !== "string")
|
|
237
|
+
return null;
|
|
238
|
+
try {
|
|
239
|
+
return JSON.parse(target);
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
var jsonToString$1 = function (target) {
|
|
246
|
+
if (!getTypeByList$1(target, ["array", "object", "set", "map"]))
|
|
247
|
+
return "";
|
|
248
|
+
try {
|
|
249
|
+
return JSON.stringify(target);
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
return "";
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
var isWindow$1 = function (win) {
|
|
256
|
+
return win && win === win.window;
|
|
257
|
+
};
|
|
258
|
+
var object$1 = {
|
|
259
|
+
getValue: getValue$1,
|
|
260
|
+
setValue: setValue$1,
|
|
261
|
+
mixIn: mixIn$1,
|
|
262
|
+
enumInversion: enumInversion$1,
|
|
263
|
+
isNotObject: isNotObject$1,
|
|
264
|
+
cloneDeep: cloneDeep$1,
|
|
265
|
+
createObjectVariable: createObjectVariable$1,
|
|
266
|
+
createObject: createObject$1,
|
|
267
|
+
inherit: inherit$1,
|
|
268
|
+
getInstance: getInstance$1,
|
|
269
|
+
classDecorator: classDecorator$1,
|
|
270
|
+
stringToJson: stringToJson$1,
|
|
271
|
+
jsonToString: jsonToString$1,
|
|
272
|
+
isWindow: isWindow$1,
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
var arrayRandom$1 = function (arr) { return arr.sort(function () { return Math.random() - 0.5; }); };
|
|
276
|
+
var arrayUniq$1 = function (arr) { return Array.from(new Set(arr)); };
|
|
277
|
+
var arrayDemote$1 = function (arr, result) {
|
|
278
|
+
if (result === void 0) { result = []; }
|
|
279
|
+
arr.forEach(function (i) { return getType$1(i) === "array" ? arrayDemote$1(i, result) : result.push(i); });
|
|
280
|
+
return result;
|
|
281
|
+
};
|
|
282
|
+
var array$1 = {
|
|
283
|
+
arrayRandom: arrayRandom$1,
|
|
284
|
+
arrayUniq: arrayUniq$1,
|
|
285
|
+
arrayDemote: arrayDemote$1
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
var _this$1 = undefined;
|
|
289
|
+
var throttle$1 = function (fn, time) {
|
|
290
|
+
var _timer = null;
|
|
291
|
+
return function () {
|
|
292
|
+
var args = [];
|
|
293
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
294
|
+
args[_i] = arguments[_i];
|
|
295
|
+
}
|
|
296
|
+
if (_timer)
|
|
297
|
+
return;
|
|
298
|
+
_timer = setTimeout(function () {
|
|
299
|
+
fn.call.apply(fn, __spreadArray$1([_this$1], args, false));
|
|
300
|
+
_timer = null;
|
|
301
|
+
}, time);
|
|
302
|
+
};
|
|
303
|
+
};
|
|
304
|
+
var debounce$1 = function (fn, time) {
|
|
305
|
+
var _timer = null;
|
|
306
|
+
return function () {
|
|
307
|
+
var args = [];
|
|
308
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
309
|
+
args[_i] = arguments[_i];
|
|
310
|
+
}
|
|
311
|
+
if (_timer) {
|
|
312
|
+
clearTimeout(_timer);
|
|
313
|
+
_timer = null;
|
|
314
|
+
}
|
|
315
|
+
_timer = setTimeout(function () {
|
|
316
|
+
fn.call.apply(fn, __spreadArray$1([_this$1], args, false));
|
|
317
|
+
}, time);
|
|
318
|
+
};
|
|
319
|
+
};
|
|
320
|
+
var defer$1 = function (timer) {
|
|
321
|
+
if (timer === void 0) { timer = 0; }
|
|
322
|
+
var resolve, reject;
|
|
323
|
+
if (timer > 0)
|
|
324
|
+
setTimeout(reject, timer);
|
|
325
|
+
return {
|
|
326
|
+
promise: new Promise(function (_resolve, _reject) {
|
|
327
|
+
resolve = _resolve;
|
|
328
|
+
reject = _reject;
|
|
329
|
+
}),
|
|
330
|
+
resolve: resolve,
|
|
331
|
+
reject: reject
|
|
332
|
+
};
|
|
333
|
+
};
|
|
334
|
+
var catchAwait$1 = function (defer) { return defer.then(function (res) { return [null, res]; }).catch(function (err) { return [err]; }); };
|
|
335
|
+
var __function$1 = {
|
|
336
|
+
throttle: throttle$1,
|
|
337
|
+
debounce: debounce$1,
|
|
338
|
+
defer: defer$1,
|
|
339
|
+
catchAwait: catchAwait$1,
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
var createElement$1 = function (_a) {
|
|
343
|
+
var _b, _c;
|
|
344
|
+
var ele = _a.ele, style = _a.style, attr = _a.attr, parent = _a.parent;
|
|
345
|
+
var element = ele instanceof HTMLElement ? ele : document.createElement(ele !== null && ele !== void 0 ? ele : 'div');
|
|
346
|
+
style && ((_b = Object.keys(style)) === null || _b === void 0 ? void 0 : _b.forEach(function (key) { return element.style[key] = style[key]; }));
|
|
347
|
+
attr && ((_c = Object.keys(attr)) === null || _c === void 0 ? void 0 : _c.forEach(function (key) { return element[key] = attr[key]; }));
|
|
348
|
+
parent && parent.appendChild(element);
|
|
349
|
+
return element;
|
|
350
|
+
};
|
|
351
|
+
var element$1 = {
|
|
352
|
+
createElement: createElement$1
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
var addHandler$1 = function (ele, type, handler) {
|
|
356
|
+
if (ele.addEventListener) {
|
|
357
|
+
ele.addEventListener(type, handler, false);
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
ele["on" + type] = handler;
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
var stopBubble$1 = function (event) {
|
|
364
|
+
event = event || window.event;
|
|
365
|
+
if (event.stopPropagation) {
|
|
366
|
+
event.stopPropagation();
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
event.cancelBubble = false;
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
var stopDefault$1 = function (event) {
|
|
373
|
+
event = event || window.event;
|
|
374
|
+
if (event.preventDefault) {
|
|
375
|
+
event.preventDefault();
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
event.returnValue = false;
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
var removeHandler$1 = function (ele, type, handler) {
|
|
382
|
+
if (ele.removeEventListener) {
|
|
383
|
+
ele.removeEventListener(type, handler, false);
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
ele["on" + type] = null;
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
var dispatchEvent$1 = function (ele, data) {
|
|
390
|
+
var evts = new Event(data);
|
|
391
|
+
ele.dispatchEvent(evts);
|
|
392
|
+
};
|
|
393
|
+
var event$1 = {
|
|
394
|
+
addHandler: addHandler$1,
|
|
395
|
+
stopBubble: stopBubble$1,
|
|
396
|
+
stopDefault: stopDefault$1,
|
|
397
|
+
removeHandler: removeHandler$1,
|
|
398
|
+
dispatchEvent: dispatchEvent$1,
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
var setStorage$1 = function (key, val) {
|
|
402
|
+
try {
|
|
403
|
+
localStorage.setItem(key, JSON.stringify(val));
|
|
404
|
+
}
|
|
405
|
+
catch (error) {
|
|
406
|
+
console.error(error);
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
var getStorage$1 = function (key) {
|
|
410
|
+
try {
|
|
411
|
+
var str = localStorage.getItem(key);
|
|
412
|
+
if (str === null || str === undefined) {
|
|
413
|
+
return null;
|
|
414
|
+
}
|
|
415
|
+
return JSON.parse(str);
|
|
416
|
+
}
|
|
417
|
+
catch (error) {
|
|
418
|
+
console.error(error);
|
|
419
|
+
return null;
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
var clearStorage$1 = function (key) {
|
|
423
|
+
try {
|
|
424
|
+
key && localStorage.removeItem(key);
|
|
425
|
+
!key && localStorage.clear();
|
|
426
|
+
}
|
|
427
|
+
catch (error) {
|
|
428
|
+
console.error(error);
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
var storage$1 = {
|
|
432
|
+
setStorage: setStorage$1,
|
|
433
|
+
getStorage: getStorage$1,
|
|
434
|
+
clearStorage: clearStorage$1
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
var logOneLine$1 = function (str, overwrite, warp) {
|
|
438
|
+
if (overwrite === void 0) { overwrite = false; }
|
|
439
|
+
if (warp === void 0) { warp = true; }
|
|
440
|
+
if (overwrite) {
|
|
441
|
+
process.stdout.clearLine(0);
|
|
442
|
+
process.stdout.cursorTo(0);
|
|
443
|
+
}
|
|
444
|
+
process.stdout.write(str);
|
|
445
|
+
warp && process.stdout.write("\n");
|
|
446
|
+
};
|
|
447
|
+
var renderLoop$1 = function (str) { return logOneLine$1(str, true, false); };
|
|
448
|
+
var defaultLoopList$1 = ["\\", "|", "/", "\u2014", "\u2014"];
|
|
449
|
+
var logLoop$1 = function (opts) {
|
|
450
|
+
var _a;
|
|
451
|
+
if (opts === void 0) { opts = {}; }
|
|
452
|
+
var _b = opts.loopList, loopList = _b === void 0 ? defaultLoopList$1 : _b, _c = opts.isStop, isStop = _c === void 0 ? false : _c, _d = opts.timer, timer = _d === void 0 ? 100 : _d;
|
|
453
|
+
var _e = opts.index, index = _e === void 0 ? 0 : _e;
|
|
454
|
+
var len = (_a = loopList === null || loopList === void 0 ? void 0 : loopList.length) !== null && _a !== void 0 ? _a : 0;
|
|
455
|
+
if (!!!len)
|
|
456
|
+
return opts;
|
|
457
|
+
if (isStop)
|
|
458
|
+
return renderLoop$1("\n");
|
|
459
|
+
if (index >= len - 1)
|
|
460
|
+
index = 0;
|
|
461
|
+
var str = loopList[index++];
|
|
462
|
+
renderLoop$1(str);
|
|
463
|
+
setTimeout(function () {
|
|
464
|
+
opts.index = index;
|
|
465
|
+
logLoop$1(opts);
|
|
466
|
+
}, timer);
|
|
467
|
+
return opts;
|
|
468
|
+
};
|
|
469
|
+
var log$1 = {
|
|
470
|
+
logOneLine: logOneLine$1,
|
|
471
|
+
logLoop: logLoop$1
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
var AnimateFrame$1 = (function () {
|
|
475
|
+
function AnimateFrame(fn) {
|
|
476
|
+
this.fn = fn;
|
|
477
|
+
this.id = null;
|
|
478
|
+
this.duration = Infinity;
|
|
479
|
+
this.isActive = false;
|
|
480
|
+
}
|
|
481
|
+
AnimateFrame.prototype.start = function (duration) {
|
|
482
|
+
if (this.isActive)
|
|
483
|
+
return;
|
|
484
|
+
this.duration = duration !== null && duration !== void 0 ? duration : Infinity;
|
|
485
|
+
this.isActive = true;
|
|
486
|
+
this.animate();
|
|
487
|
+
};
|
|
488
|
+
AnimateFrame.prototype.stop = function () {
|
|
489
|
+
this.isActive = false;
|
|
490
|
+
cancelAnimationFrame(this.id);
|
|
491
|
+
};
|
|
492
|
+
AnimateFrame.prototype.animate = function (timer) {
|
|
493
|
+
if (timer === void 0) { timer = 0; }
|
|
494
|
+
if (this.isActive && this.duration-- > 0) {
|
|
495
|
+
this.fn(timer);
|
|
496
|
+
this.id = requestAnimationFrame(this.animate.bind(this));
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
return AnimateFrame;
|
|
500
|
+
}());
|
|
501
|
+
function quadraticBezier$1(_x, _y, t) {
|
|
502
|
+
var mt = 1 - t;
|
|
503
|
+
var t2 = t * t;
|
|
504
|
+
var x = 2 * mt * t * _x + t2;
|
|
505
|
+
var y = 2 * mt * t * _y + t2;
|
|
506
|
+
return [x, y];
|
|
507
|
+
}
|
|
508
|
+
function cubicBezier$1(_x1, _y1, _x2, _y2, t) {
|
|
509
|
+
var cx = 3 * _x1;
|
|
510
|
+
var cy = 3 * _y1;
|
|
511
|
+
var bx = 3 * (_x2 - _x1) - cx;
|
|
512
|
+
var by = 3 * (_y2 - _y1) - cy;
|
|
513
|
+
var ax = 1 - cx - bx;
|
|
514
|
+
var ay = 1 - cy - by;
|
|
515
|
+
var x = ax * Math.pow(t, 3) + bx * Math.pow(t, 2) + cx * t;
|
|
516
|
+
var y = ay * Math.pow(t, 3) + by * Math.pow(t, 2) + cy * t;
|
|
517
|
+
return [x, y];
|
|
518
|
+
}
|
|
519
|
+
function factorial$1(n) {
|
|
520
|
+
if (n === 0 || n === 1) {
|
|
521
|
+
return 1;
|
|
522
|
+
}
|
|
523
|
+
return n * factorial$1(n - 1);
|
|
524
|
+
}
|
|
525
|
+
function combination$1(n, k) {
|
|
526
|
+
return factorial$1(n) / (factorial$1(k) * factorial$1(n - k));
|
|
527
|
+
}
|
|
528
|
+
function NBezier$1(points, t) {
|
|
529
|
+
var n = points.length - 1;
|
|
530
|
+
var result = [0, 0];
|
|
531
|
+
for (var i = 0; i <= n; i++) {
|
|
532
|
+
var coefficient = combination$1(n, i) * Math.pow(1 - t, n - i) * Math.pow(t, i);
|
|
533
|
+
result[0] += coefficient * points[i][0];
|
|
534
|
+
result[1] += coefficient * points[i][1];
|
|
535
|
+
}
|
|
536
|
+
return result;
|
|
537
|
+
}
|
|
538
|
+
var animate$1 = {
|
|
539
|
+
AnimateFrame: AnimateFrame$1,
|
|
540
|
+
quadraticBezier: quadraticBezier$1,
|
|
541
|
+
cubicBezier: cubicBezier$1,
|
|
542
|
+
factorial: factorial$1,
|
|
543
|
+
combination: combination$1,
|
|
544
|
+
NBezier: NBezier$1,
|
|
545
|
+
};
|
|
546
|
+
|
|
547
|
+
var MessageCenter$1 = (function () {
|
|
548
|
+
function MessageCenter(options) {
|
|
549
|
+
if (options === void 0) { options = {}; }
|
|
550
|
+
this.options = options;
|
|
551
|
+
this.events = {};
|
|
552
|
+
}
|
|
553
|
+
MessageCenter.prototype.on = function (type, handler) {
|
|
554
|
+
this.checkHandler(type, handler);
|
|
555
|
+
var fns = this.getHandler(type, []);
|
|
556
|
+
fns.push(handler);
|
|
557
|
+
return this;
|
|
558
|
+
};
|
|
559
|
+
MessageCenter.prototype.emit = function (type, data) {
|
|
560
|
+
if (this.has(type)) {
|
|
561
|
+
this.runHandler(type, data);
|
|
562
|
+
}
|
|
563
|
+
return this;
|
|
564
|
+
};
|
|
565
|
+
MessageCenter.prototype.un = function (type, handler) {
|
|
566
|
+
this.unHandler(type, handler);
|
|
567
|
+
return this;
|
|
568
|
+
};
|
|
569
|
+
MessageCenter.prototype.once = function (type, handler) {
|
|
570
|
+
var _this = this;
|
|
571
|
+
this.checkHandler(type, handler);
|
|
572
|
+
var fn = function () {
|
|
573
|
+
var args = [];
|
|
574
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
575
|
+
args[_i] = arguments[_i];
|
|
576
|
+
}
|
|
577
|
+
_this.un(type, fn);
|
|
578
|
+
return handler.apply(void 0, args);
|
|
579
|
+
};
|
|
580
|
+
this.on(type, fn);
|
|
581
|
+
return this;
|
|
582
|
+
};
|
|
583
|
+
MessageCenter.prototype.clear = function () {
|
|
584
|
+
this.events = {};
|
|
585
|
+
return this;
|
|
586
|
+
};
|
|
587
|
+
MessageCenter.prototype.has = function (type) {
|
|
588
|
+
return !!this.getHandler(type);
|
|
589
|
+
};
|
|
590
|
+
MessageCenter.prototype.getHandler = function (type, defaultVal) {
|
|
591
|
+
var _a;
|
|
592
|
+
typeof defaultVal === "object" && (this.events[type] = (_a = this.events[type]) !== null && _a !== void 0 ? _a : defaultVal);
|
|
593
|
+
return this.events[type];
|
|
594
|
+
};
|
|
595
|
+
MessageCenter.prototype.handlerLength = function (type) {
|
|
596
|
+
var _a, _b;
|
|
597
|
+
return (_b = (_a = this.getHandler(type)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
598
|
+
};
|
|
599
|
+
MessageCenter.prototype.watch = function (type, handler) {
|
|
600
|
+
var _this = this;
|
|
601
|
+
this.checkHandler(type, handler);
|
|
602
|
+
var fn = function () {
|
|
603
|
+
var args = [];
|
|
604
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
605
|
+
args[_i] = arguments[_i];
|
|
606
|
+
}
|
|
607
|
+
_this.emit(_this.prefixStr(type), handler.apply(void 0, args));
|
|
608
|
+
};
|
|
609
|
+
this.on(type, fn);
|
|
610
|
+
return this;
|
|
611
|
+
};
|
|
612
|
+
MessageCenter.prototype.invoke = function (type, data) {
|
|
613
|
+
var _this = this;
|
|
614
|
+
return new Promise(function (resolve) {
|
|
615
|
+
_this.once(_this.prefixStr(type), resolve);
|
|
616
|
+
_this.emit(type, data);
|
|
617
|
+
});
|
|
618
|
+
};
|
|
619
|
+
MessageCenter.prototype.runHandler = function (type, data) {
|
|
620
|
+
var _fns = this.getHandler(type);
|
|
621
|
+
for (var _i = 0, _fns_1 = _fns; _i < _fns_1.length; _i++) {
|
|
622
|
+
var fn = _fns_1[_i];
|
|
623
|
+
fn && fn(data);
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
MessageCenter.prototype.unHandler = function (type, handler) {
|
|
627
|
+
var _fns = this.getHandler(type);
|
|
628
|
+
!handler && (this.events[type] = []);
|
|
629
|
+
handler && this.checkHandler(type, handler);
|
|
630
|
+
for (var i = 0; i < _fns.length; i++) {
|
|
631
|
+
if (_fns && _fns[i] === handler) {
|
|
632
|
+
_fns[i] = null;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
};
|
|
636
|
+
MessageCenter.prototype.prefixStr = function (str) {
|
|
637
|
+
return "@".concat(str);
|
|
638
|
+
};
|
|
639
|
+
MessageCenter.prototype.checkHandler = function (type, handler) {
|
|
640
|
+
var _a = this.options, _b = _a.blackList, blackList = _b === void 0 ? [] : _b, _c = _a.maxLen, maxLen = _c === void 0 ? Infinity : _c;
|
|
641
|
+
var len = this.handlerLength(type);
|
|
642
|
+
if ((type === null || type === void 0 ? void 0 : type.length) === 0) {
|
|
643
|
+
throw new Error('type.length can not be 0');
|
|
644
|
+
}
|
|
645
|
+
if (!handler || !type) {
|
|
646
|
+
throw new ReferenceError('type or handler is not defined');
|
|
647
|
+
}
|
|
648
|
+
if (typeof handler !== 'function' || typeof type !== 'string') {
|
|
649
|
+
throw new TypeError("".concat(handler, " is not a function or ").concat(type, " is not a string"));
|
|
650
|
+
}
|
|
651
|
+
if (blackList.includes(type)) {
|
|
652
|
+
throw new Error("".concat(type, " is not allow"));
|
|
653
|
+
}
|
|
654
|
+
if (maxLen <= len) {
|
|
655
|
+
throw new Error("the number of ".concat(type, " must be less than ").concat(maxLen));
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
MessageCenter.Instance = function (Fn) {
|
|
659
|
+
if (!Fn._instance) {
|
|
660
|
+
Object.defineProperty(Fn, "_instance", {
|
|
661
|
+
value: new Fn()
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
return Fn._instance;
|
|
665
|
+
};
|
|
666
|
+
return MessageCenter;
|
|
667
|
+
}());
|
|
668
|
+
var messageCenter = MessageCenter$1.Instance(MessageCenter$1);
|
|
669
|
+
var decoratorMessageCenter$1 = function (target) {
|
|
670
|
+
if (!target.prototype.messageCenter) {
|
|
671
|
+
target.prototype.messageCenter = new MessageCenter$1();
|
|
672
|
+
}
|
|
673
|
+
return target;
|
|
674
|
+
};
|
|
675
|
+
|
|
676
|
+
var __assign$3 = (undefined && undefined.__assign) || function () {
|
|
677
|
+
__assign$3 = Object.assign || function(t) {
|
|
678
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
679
|
+
s = arguments[i];
|
|
680
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
681
|
+
t[p] = s[p];
|
|
682
|
+
}
|
|
683
|
+
return t;
|
|
684
|
+
};
|
|
685
|
+
return __assign$3.apply(this, arguments);
|
|
686
|
+
};
|
|
687
|
+
var __decorate$1 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
688
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
689
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
690
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
691
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
692
|
+
};
|
|
693
|
+
var __metadata$1 = (undefined && undefined.__metadata) || function (k, v) {
|
|
694
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
695
|
+
};
|
|
696
|
+
var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
697
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
698
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
699
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
700
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
701
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
702
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
703
|
+
});
|
|
704
|
+
};
|
|
705
|
+
var __generator$1 = (undefined && undefined.__generator) || function (thisArg, body) {
|
|
706
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
707
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
708
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
709
|
+
function step(op) {
|
|
710
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
711
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
712
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
713
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
714
|
+
switch (op[0]) {
|
|
715
|
+
case 0: case 1: t = op; break;
|
|
716
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
717
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
718
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
719
|
+
default:
|
|
720
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
721
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
722
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
723
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
724
|
+
if (t[2]) _.ops.pop();
|
|
725
|
+
_.trys.pop(); continue;
|
|
726
|
+
}
|
|
727
|
+
op = body.call(thisArg, _);
|
|
728
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
729
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
var TaskQueue$1 = (function () {
|
|
733
|
+
function TaskQueue(props) {
|
|
734
|
+
var _this = this;
|
|
735
|
+
this.fix = "@~&$";
|
|
736
|
+
this.init = function () {
|
|
737
|
+
_this.messageCenter.on("push:handler", _this.run);
|
|
738
|
+
_this.messageCenter.on("run:success:handler", _this.run);
|
|
739
|
+
_this.messageCenter.on("run:success:handler", _this.finish);
|
|
740
|
+
_this.messageCenter.on("run:error:handler", _this.run);
|
|
741
|
+
_this.messageCenter.on("run:error:handler", _this.finish);
|
|
742
|
+
};
|
|
743
|
+
this.defineProps = function (props, key) {
|
|
744
|
+
Object.defineProperty(_this, key, { value: props });
|
|
745
|
+
};
|
|
746
|
+
this.push = function (queue) {
|
|
747
|
+
var _a;
|
|
748
|
+
_this.checkHandler(queue);
|
|
749
|
+
var resolve = (_a = _this.defer(), _a.resolve), reject = _a.reject, promise = _a.promise;
|
|
750
|
+
var queueName = _this.fixStr(queue.name);
|
|
751
|
+
_this.queues = _this.queues.concat(queue.children.map(function (defer) { return ({ defer: defer, name: queueName }); }));
|
|
752
|
+
_this.queueTemp[queueName] = __assign$3(__assign$3({}, queue), { result: [] });
|
|
753
|
+
_this.messageCenter.emit("push:handler", reject);
|
|
754
|
+
_this.messageCenter.on(queueName, resolve);
|
|
755
|
+
return promise;
|
|
756
|
+
};
|
|
757
|
+
this.unshift = function (length) {
|
|
758
|
+
return _this.queues.splice(0, length);
|
|
759
|
+
};
|
|
760
|
+
this.run = function (_a) {
|
|
761
|
+
var reject = _a.reject;
|
|
762
|
+
return __awaiter$1(_this, void 0, void 0, function () {
|
|
763
|
+
var queues, res, error_1;
|
|
764
|
+
var _b, _c;
|
|
765
|
+
return __generator$1(this, function (_d) {
|
|
766
|
+
switch (_d.label) {
|
|
767
|
+
case 0:
|
|
768
|
+
if (this.stateProxy() === 'pending')
|
|
769
|
+
return [2, void 0];
|
|
770
|
+
if (this.queues.length === 0)
|
|
771
|
+
return [2, this.stateProxy("idle")];
|
|
772
|
+
this.stateProxy("pending");
|
|
773
|
+
queues = this.unshift((_c = (_b = this.props) === null || _b === void 0 ? void 0 : _b.maxLen) !== null && _c !== void 0 ? _c : 10);
|
|
774
|
+
_d.label = 1;
|
|
775
|
+
case 1:
|
|
776
|
+
_d.trys.push([1, 3, , 4]);
|
|
777
|
+
return [4, Promise.all(queues.map(function (item, i) { return item.defer().catch(function (error) { return error; }); }))];
|
|
778
|
+
case 2:
|
|
779
|
+
res = _d.sent();
|
|
780
|
+
return [2, this.handlerSuccess({ res: res, queues: queues })];
|
|
781
|
+
case 3:
|
|
782
|
+
error_1 = _d.sent();
|
|
783
|
+
return [2, this.handlerError({ reject: reject, error: error_1, queues: queues })];
|
|
784
|
+
case 4: return [2];
|
|
785
|
+
}
|
|
786
|
+
});
|
|
787
|
+
});
|
|
788
|
+
};
|
|
789
|
+
this.clear = function () {
|
|
790
|
+
_this.queues = [];
|
|
791
|
+
_this.queueTemp = {};
|
|
792
|
+
_this.props = null;
|
|
793
|
+
_this.stateProxy("idle");
|
|
794
|
+
_this.messageCenter.clear();
|
|
795
|
+
};
|
|
796
|
+
this.finish = function (_a) {
|
|
797
|
+
var _b = _a.res, res = _b === void 0 ? [] : _b, queues = _a.queues, _c = _a.error, error = _c === void 0 ? 'err' : _c;
|
|
798
|
+
var queueTemp = _this.queueTemp;
|
|
799
|
+
queues.forEach(function (it, i) {
|
|
800
|
+
var _a, _b, _c;
|
|
801
|
+
var item = queueTemp[it.name];
|
|
802
|
+
item === null || item === void 0 ? void 0 : item.result.push((_a = res[i]) !== null && _a !== void 0 ? _a : error);
|
|
803
|
+
if (((_b = item === null || item === void 0 ? void 0 : item.result) === null || _b === void 0 ? void 0 : _b.length) === ((_c = item === null || item === void 0 ? void 0 : item.children) === null || _c === void 0 ? void 0 : _c.length)) {
|
|
804
|
+
_this.messageCenter.emit(it.name, item === null || item === void 0 ? void 0 : item.result);
|
|
805
|
+
queueTemp[it.name] = null;
|
|
806
|
+
}
|
|
807
|
+
});
|
|
808
|
+
};
|
|
809
|
+
this.handlerSuccess = function (data) {
|
|
810
|
+
_this.stateProxy("fulfilled");
|
|
811
|
+
return _this.messageCenter.emit("run:success:handler", data);
|
|
812
|
+
};
|
|
813
|
+
this.handlerError = function (data) {
|
|
814
|
+
var reject = data.reject, error = data.error;
|
|
815
|
+
_this.stateProxy("rejected");
|
|
816
|
+
reject && typeof reject === "function" && reject(error);
|
|
817
|
+
return _this.messageCenter.emit("run:error:handler", data);
|
|
818
|
+
};
|
|
819
|
+
this.stateProxy = function (state) {
|
|
820
|
+
state && (_this.state = state);
|
|
821
|
+
return _this.state;
|
|
822
|
+
};
|
|
823
|
+
this.defer = function () {
|
|
824
|
+
var resolve, reject;
|
|
825
|
+
return {
|
|
826
|
+
promise: new Promise(function (_resolve, _reject) {
|
|
827
|
+
resolve = _resolve;
|
|
828
|
+
reject = _reject;
|
|
829
|
+
}),
|
|
830
|
+
resolve: resolve,
|
|
831
|
+
reject: reject
|
|
832
|
+
};
|
|
833
|
+
};
|
|
834
|
+
this.clear();
|
|
835
|
+
props && this.defineProps(props, "props");
|
|
836
|
+
this.init();
|
|
837
|
+
}
|
|
838
|
+
TaskQueue.prototype.checkHandler = function (queue) {
|
|
839
|
+
var _a, _b;
|
|
840
|
+
if (!queue) {
|
|
841
|
+
throw new ReferenceError('queue is not defined');
|
|
842
|
+
}
|
|
843
|
+
if (!(queue.children instanceof Array) || typeof queue !== "object") {
|
|
844
|
+
throw new TypeError("queue should be an object and queue.children should be an array");
|
|
845
|
+
}
|
|
846
|
+
var noFn = function (i) { return !i || typeof i !== "function"; };
|
|
847
|
+
if (((_a = queue.children) === null || _a === void 0 ? void 0 : _a.length) === 0)
|
|
848
|
+
throw new Error('queue.children.length can not be 0');
|
|
849
|
+
if ((_b = queue.children) === null || _b === void 0 ? void 0 : _b.find(function (i) { return noFn(i); }))
|
|
850
|
+
throw new Error('queueList should have defer');
|
|
851
|
+
};
|
|
852
|
+
TaskQueue.prototype.fixStr = function (str) {
|
|
853
|
+
return "".concat(this.fix).concat(str);
|
|
854
|
+
};
|
|
855
|
+
TaskQueue = __decorate$1([
|
|
856
|
+
decoratorMessageCenter$1,
|
|
857
|
+
__metadata$1("design:paramtypes", [Object])
|
|
858
|
+
], TaskQueue);
|
|
859
|
+
return TaskQueue;
|
|
860
|
+
}());
|
|
861
|
+
var decoratorTaskQueue = function (opts) {
|
|
862
|
+
return function (target) {
|
|
863
|
+
if (!target.prototype.taskQueue) {
|
|
864
|
+
target.prototype.taskQueue = new TaskQueue$1(opts);
|
|
865
|
+
}
|
|
866
|
+
};
|
|
867
|
+
};
|
|
868
|
+
|
|
869
|
+
/******************************************************************************
|
|
870
|
+
Copyright (c) Microsoft Corporation.
|
|
871
|
+
|
|
872
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
873
|
+
purpose with or without fee is hereby granted.
|
|
874
|
+
|
|
875
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
876
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
877
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
878
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
879
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
880
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
881
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
882
|
+
***************************************************************************** */
|
|
883
|
+
|
|
884
|
+
var __assign$1 = function() {
|
|
885
|
+
__assign$1 = Object.assign || function __assign(t) {
|
|
886
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
887
|
+
s = arguments[i];
|
|
888
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
889
|
+
}
|
|
890
|
+
return t;
|
|
891
|
+
};
|
|
892
|
+
return __assign$1.apply(this, arguments);
|
|
893
|
+
};
|
|
894
|
+
|
|
895
|
+
function __spreadArray(to, from, pack) {
|
|
896
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
897
|
+
if (ar || !(i in from)) {
|
|
898
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
899
|
+
ar[i] = from[i];
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
var types;
|
|
906
|
+
(function (types) {
|
|
907
|
+
types["[object Array]"] = "array";
|
|
908
|
+
types["[object Object]"] = "object";
|
|
909
|
+
types["[object Function]"] = "function";
|
|
910
|
+
types["[object Set]"] = "set";
|
|
911
|
+
types["[object Map]"] = "map";
|
|
912
|
+
types["[object WeakMap]"] = "weakMap";
|
|
913
|
+
types["[object WeakSet]"] = "weakSet";
|
|
914
|
+
types["[object Date]"] = "date";
|
|
915
|
+
types["[object RegExp]"] = "regExp";
|
|
916
|
+
types["[object Math]"] = "math";
|
|
917
|
+
})(types || (types = {}));
|
|
918
|
+
var __static = { types: types };
|
|
919
|
+
|
|
920
|
+
var randomNum = function (min, max, bool) {
|
|
921
|
+
if (bool === void 0) { bool = false; }
|
|
922
|
+
return Math.floor(Math.random() * (max - min + (bool ? 1 : 0)) + min);
|
|
923
|
+
};
|
|
924
|
+
var urlSplit = function (url) {
|
|
925
|
+
var result = {};
|
|
926
|
+
if (!url.includes("?")) {
|
|
927
|
+
return result;
|
|
928
|
+
}
|
|
929
|
+
var params = url.split("?")[1].split("&");
|
|
930
|
+
params.forEach(function (i) {
|
|
931
|
+
var key = i.split("=")[0];
|
|
932
|
+
result[key] = i.split("=")[1];
|
|
933
|
+
});
|
|
934
|
+
return result;
|
|
935
|
+
};
|
|
936
|
+
var urlJoin = function (url, query) {
|
|
937
|
+
if (query === void 0) { query = {}; }
|
|
938
|
+
var queryObject = Object.keys(query);
|
|
939
|
+
if (queryObject.length === 0)
|
|
940
|
+
return url;
|
|
941
|
+
var params = queryObject.map(function (i) { return "".concat(i, "=").concat(query[i]); });
|
|
942
|
+
return "".concat(url).concat(url.includes("?") ? "&" : '?').concat(params.join("&"));
|
|
943
|
+
};
|
|
944
|
+
var getType = function (data) {
|
|
945
|
+
var type = typeof data;
|
|
946
|
+
if (data === null) {
|
|
947
|
+
return "null";
|
|
948
|
+
}
|
|
949
|
+
else if (type === "object") {
|
|
950
|
+
var key = Object.prototype.toString.call(data);
|
|
951
|
+
return types[key];
|
|
952
|
+
}
|
|
953
|
+
return type;
|
|
954
|
+
};
|
|
955
|
+
var getTypeByList = function (data, whiteList) {
|
|
956
|
+
if (whiteList === void 0) { whiteList = []; }
|
|
957
|
+
var __type = getType(data);
|
|
958
|
+
return whiteList.indexOf(__type) > 0;
|
|
959
|
+
};
|
|
960
|
+
var base = {
|
|
961
|
+
randomNum: randomNum,
|
|
962
|
+
urlSplit: urlSplit,
|
|
963
|
+
urlJoin: urlJoin,
|
|
964
|
+
getType: getType,
|
|
965
|
+
getTypeByList: getTypeByList,
|
|
966
|
+
};
|
|
967
|
+
|
|
968
|
+
var getValue = function (object, key, defaultValue) {
|
|
969
|
+
if (defaultValue === void 0) { defaultValue = ''; }
|
|
970
|
+
var paths = key.split('.');
|
|
971
|
+
for (var _i = 0, paths_1 = paths; _i < paths_1.length; _i++) {
|
|
972
|
+
var i = paths_1[_i];
|
|
973
|
+
object = object[i];
|
|
974
|
+
if (object === undefined) {
|
|
975
|
+
return defaultValue;
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
return object;
|
|
979
|
+
};
|
|
980
|
+
var setValue = function (object, key, value) {
|
|
981
|
+
if (value === void 0) { value = {}; }
|
|
982
|
+
var paths = key.split('.');
|
|
983
|
+
var last = paths[paths.length - 1];
|
|
984
|
+
var _object = object;
|
|
985
|
+
for (var _i = 0, paths_2 = paths; _i < paths_2.length; _i++) {
|
|
986
|
+
var i = paths_2[_i];
|
|
987
|
+
if (typeof _object !== "object" && _object !== undefined) {
|
|
988
|
+
return object;
|
|
989
|
+
}
|
|
990
|
+
!_object && (_object = {});
|
|
991
|
+
!_object[i] && (_object[i] = {});
|
|
992
|
+
last === i && (_object[last] = value);
|
|
993
|
+
_object = _object[i];
|
|
994
|
+
}
|
|
995
|
+
return object;
|
|
996
|
+
};
|
|
997
|
+
var mixIn = function (target, source, overwrite) {
|
|
998
|
+
var _a;
|
|
999
|
+
if (source === void 0) { source = {}; }
|
|
1000
|
+
if (overwrite === void 0) { overwrite = false; }
|
|
1001
|
+
for (var k in source) {
|
|
1002
|
+
for (var key in source[k]) {
|
|
1003
|
+
var proto = (_a = target.prototype) !== null && _a !== void 0 ? _a : target;
|
|
1004
|
+
if (target[key] === undefined || overwrite) {
|
|
1005
|
+
proto[key] = source[k][key];
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
return target;
|
|
1010
|
+
};
|
|
1011
|
+
var enumInversion = function (target) {
|
|
1012
|
+
for (var key in target) {
|
|
1013
|
+
var _key = target[key];
|
|
1014
|
+
if (typeof _key === "string" && !!!target[_key]) {
|
|
1015
|
+
target[_key] = key;
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
return target;
|
|
1019
|
+
};
|
|
1020
|
+
var isNotObject = function (source, type) { return (typeof source !== "object" || type === 'null'); };
|
|
1021
|
+
var cloneDeep = function (target) {
|
|
1022
|
+
var __type = getType(target);
|
|
1023
|
+
if (isNotObject(target, __type))
|
|
1024
|
+
return target;
|
|
1025
|
+
var __init = createObjectVariable(__type, target);
|
|
1026
|
+
if (__type === "map") {
|
|
1027
|
+
target.forEach(function (value, key) {
|
|
1028
|
+
__init.set(key, cloneDeep(value));
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
else if (__type === "set") {
|
|
1032
|
+
target.forEach(function (value) {
|
|
1033
|
+
__init.add(cloneDeep(value));
|
|
1034
|
+
});
|
|
1035
|
+
}
|
|
1036
|
+
else {
|
|
1037
|
+
Reflect.ownKeys(target).forEach(function (keys) {
|
|
1038
|
+
var desc = target[keys];
|
|
1039
|
+
__init[keys] = cloneDeep(desc);
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
return __init;
|
|
1043
|
+
};
|
|
1044
|
+
var createObjectVariable = function (type, source) {
|
|
1045
|
+
if (source === void 0) { source = {}; }
|
|
1046
|
+
switch (type) {
|
|
1047
|
+
case "array":
|
|
1048
|
+
return [];
|
|
1049
|
+
case "function":
|
|
1050
|
+
return source;
|
|
1051
|
+
case "set":
|
|
1052
|
+
return new Set();
|
|
1053
|
+
case "map":
|
|
1054
|
+
return new Map();
|
|
1055
|
+
case "date":
|
|
1056
|
+
return new Date(source);
|
|
1057
|
+
case "regExp":
|
|
1058
|
+
return new RegExp(source);
|
|
1059
|
+
case "math":
|
|
1060
|
+
return Math;
|
|
1061
|
+
default:
|
|
1062
|
+
return {};
|
|
1063
|
+
}
|
|
1064
|
+
};
|
|
1065
|
+
var createObject = function (source) {
|
|
1066
|
+
function F() { }
|
|
1067
|
+
F.prototype = source;
|
|
1068
|
+
return new F();
|
|
1069
|
+
};
|
|
1070
|
+
var inherit = function (source, target) {
|
|
1071
|
+
if (target === void 0) { target = function () { }; }
|
|
1072
|
+
target.prototype = createObject(source.prototype);
|
|
1073
|
+
target.prototype.super = source;
|
|
1074
|
+
target.prototype.constructor = target;
|
|
1075
|
+
return target;
|
|
1076
|
+
};
|
|
1077
|
+
var getInstance = function (classProto, overwrite) {
|
|
1078
|
+
if (overwrite === void 0) { overwrite = false; }
|
|
1079
|
+
var params = [];
|
|
1080
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
1081
|
+
params[_i - 2] = arguments[_i];
|
|
1082
|
+
}
|
|
1083
|
+
if (!classProto._instance || overwrite) {
|
|
1084
|
+
classProto._instance = new (classProto.bind.apply(classProto, __spreadArray([void 0], params, false)))();
|
|
1085
|
+
}
|
|
1086
|
+
return classProto._instance;
|
|
1087
|
+
};
|
|
1088
|
+
var classDecorator = function (params) {
|
|
1089
|
+
return function (target) {
|
|
1090
|
+
for (var key in params) {
|
|
1091
|
+
if (!!!Reflect.has(target.prototype, key)) {
|
|
1092
|
+
target.prototype[key] = params[key];
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
};
|
|
1096
|
+
};
|
|
1097
|
+
var stringToJson = function (target) {
|
|
1098
|
+
if (getType(target) !== "string")
|
|
1099
|
+
return null;
|
|
1100
|
+
try {
|
|
1101
|
+
return JSON.parse(target);
|
|
1102
|
+
}
|
|
1103
|
+
catch (error) {
|
|
1104
|
+
return null;
|
|
1105
|
+
}
|
|
1106
|
+
};
|
|
1107
|
+
var jsonToString = function (target) {
|
|
1108
|
+
if (!getTypeByList(target, ["array", "object", "set", "map"]))
|
|
1109
|
+
return "";
|
|
1110
|
+
try {
|
|
1111
|
+
return JSON.stringify(target);
|
|
1112
|
+
}
|
|
1113
|
+
catch (error) {
|
|
1114
|
+
return "";
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1117
|
+
var isWindow = function (win) {
|
|
1118
|
+
return win && win === win.window;
|
|
1119
|
+
};
|
|
1120
|
+
var object = {
|
|
1121
|
+
getValue: getValue,
|
|
1122
|
+
setValue: setValue,
|
|
1123
|
+
mixIn: mixIn,
|
|
1124
|
+
enumInversion: enumInversion,
|
|
1125
|
+
isNotObject: isNotObject,
|
|
1126
|
+
cloneDeep: cloneDeep,
|
|
1127
|
+
createObjectVariable: createObjectVariable,
|
|
1128
|
+
createObject: createObject,
|
|
1129
|
+
inherit: inherit,
|
|
1130
|
+
getInstance: getInstance,
|
|
1131
|
+
classDecorator: classDecorator,
|
|
1132
|
+
stringToJson: stringToJson,
|
|
1133
|
+
jsonToString: jsonToString,
|
|
1134
|
+
isWindow: isWindow,
|
|
1135
|
+
};
|
|
1136
|
+
|
|
1137
|
+
var arrayRandom = function (arr) { return arr.sort(function () { return Math.random() - 0.5; }); };
|
|
1138
|
+
var arrayUniq = function (arr) { return Array.from(new Set(arr)); };
|
|
1139
|
+
var arrayDemote = function (arr, result) {
|
|
1140
|
+
if (result === void 0) { result = []; }
|
|
1141
|
+
arr.forEach(function (i) { return getType(i) === "array" ? arrayDemote(i, result) : result.push(i); });
|
|
1142
|
+
return result;
|
|
1143
|
+
};
|
|
1144
|
+
var array = {
|
|
1145
|
+
arrayRandom: arrayRandom,
|
|
1146
|
+
arrayUniq: arrayUniq,
|
|
1147
|
+
arrayDemote: arrayDemote
|
|
1148
|
+
};
|
|
1149
|
+
|
|
1150
|
+
var _this = undefined;
|
|
1151
|
+
var throttle = function (fn, time) {
|
|
1152
|
+
var _timer = null;
|
|
1153
|
+
return function () {
|
|
1154
|
+
var args = [];
|
|
1155
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1156
|
+
args[_i] = arguments[_i];
|
|
1157
|
+
}
|
|
1158
|
+
if (_timer)
|
|
1159
|
+
return;
|
|
1160
|
+
_timer = setTimeout(function () {
|
|
1161
|
+
fn.call.apply(fn, __spreadArray([_this], args, false));
|
|
1162
|
+
_timer = null;
|
|
1163
|
+
}, time);
|
|
1164
|
+
};
|
|
1165
|
+
};
|
|
1166
|
+
var debounce = function (fn, time) {
|
|
1167
|
+
var _timer = null;
|
|
1168
|
+
return function () {
|
|
1169
|
+
var args = [];
|
|
1170
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1171
|
+
args[_i] = arguments[_i];
|
|
1172
|
+
}
|
|
1173
|
+
if (_timer) {
|
|
1174
|
+
clearTimeout(_timer);
|
|
1175
|
+
_timer = null;
|
|
1176
|
+
}
|
|
1177
|
+
_timer = setTimeout(function () {
|
|
1178
|
+
fn.call.apply(fn, __spreadArray([_this], args, false));
|
|
1179
|
+
}, time);
|
|
1180
|
+
};
|
|
1181
|
+
};
|
|
1182
|
+
var defer = function (timer) {
|
|
1183
|
+
if (timer === void 0) { timer = 0; }
|
|
1184
|
+
var resolve, reject;
|
|
1185
|
+
if (timer > 0)
|
|
1186
|
+
setTimeout(reject, timer);
|
|
1187
|
+
return {
|
|
1188
|
+
promise: new Promise(function (_resolve, _reject) {
|
|
1189
|
+
resolve = _resolve;
|
|
1190
|
+
reject = _reject;
|
|
1191
|
+
}),
|
|
1192
|
+
resolve: resolve,
|
|
1193
|
+
reject: reject
|
|
1194
|
+
};
|
|
1195
|
+
};
|
|
1196
|
+
var catchAwait = function (defer) { return defer.then(function (res) { return [null, res]; }).catch(function (err) { return [err]; }); };
|
|
1197
|
+
var __function = {
|
|
1198
|
+
throttle: throttle,
|
|
1199
|
+
debounce: debounce,
|
|
1200
|
+
defer: defer,
|
|
1201
|
+
catchAwait: catchAwait,
|
|
1202
|
+
};
|
|
1203
|
+
|
|
1204
|
+
var createElement = function (_a) {
|
|
1205
|
+
var _b, _c;
|
|
1206
|
+
var ele = _a.ele, style = _a.style, attr = _a.attr, parent = _a.parent;
|
|
1207
|
+
var element = ele instanceof HTMLElement ? ele : document.createElement(ele !== null && ele !== void 0 ? ele : 'div');
|
|
1208
|
+
style && ((_b = Object.keys(style)) === null || _b === void 0 ? void 0 : _b.forEach(function (key) { return element.style[key] = style[key]; }));
|
|
1209
|
+
attr && ((_c = Object.keys(attr)) === null || _c === void 0 ? void 0 : _c.forEach(function (key) { return element[key] = attr[key]; }));
|
|
1210
|
+
parent && parent.appendChild(element);
|
|
1211
|
+
return element;
|
|
1212
|
+
};
|
|
1213
|
+
var element = {
|
|
1214
|
+
createElement: createElement
|
|
1215
|
+
};
|
|
1216
|
+
|
|
1217
|
+
var addHandler = function (ele, type, handler) {
|
|
1218
|
+
if (ele.addEventListener) {
|
|
1219
|
+
ele.addEventListener(type, handler, false);
|
|
1220
|
+
}
|
|
1221
|
+
else {
|
|
1222
|
+
ele["on" + type] = handler;
|
|
1223
|
+
}
|
|
1224
|
+
};
|
|
1225
|
+
var stopBubble = function (event) {
|
|
1226
|
+
event = event || window.event;
|
|
1227
|
+
if (event.stopPropagation) {
|
|
1228
|
+
event.stopPropagation();
|
|
1229
|
+
}
|
|
1230
|
+
else {
|
|
1231
|
+
event.cancelBubble = false;
|
|
1232
|
+
}
|
|
1233
|
+
};
|
|
1234
|
+
var stopDefault = function (event) {
|
|
1235
|
+
event = event || window.event;
|
|
1236
|
+
if (event.preventDefault) {
|
|
1237
|
+
event.preventDefault();
|
|
1238
|
+
}
|
|
1239
|
+
else {
|
|
1240
|
+
event.returnValue = false;
|
|
1241
|
+
}
|
|
1242
|
+
};
|
|
1243
|
+
var removeHandler = function (ele, type, handler) {
|
|
1244
|
+
if (ele.removeEventListener) {
|
|
1245
|
+
ele.removeEventListener(type, handler, false);
|
|
1246
|
+
}
|
|
1247
|
+
else {
|
|
1248
|
+
ele["on" + type] = null;
|
|
1249
|
+
}
|
|
1250
|
+
};
|
|
1251
|
+
var dispatchEvent = function (ele, data) {
|
|
1252
|
+
var evts = new Event(data);
|
|
1253
|
+
ele.dispatchEvent(evts);
|
|
1254
|
+
};
|
|
1255
|
+
var event = {
|
|
1256
|
+
addHandler: addHandler,
|
|
1257
|
+
stopBubble: stopBubble,
|
|
1258
|
+
stopDefault: stopDefault,
|
|
1259
|
+
removeHandler: removeHandler,
|
|
1260
|
+
dispatchEvent: dispatchEvent,
|
|
1261
|
+
};
|
|
1262
|
+
|
|
1263
|
+
var setStorage = function (key, val) {
|
|
1264
|
+
try {
|
|
1265
|
+
localStorage.setItem(key, JSON.stringify(val));
|
|
1266
|
+
}
|
|
1267
|
+
catch (error) {
|
|
1268
|
+
console.error(error);
|
|
1269
|
+
}
|
|
1270
|
+
};
|
|
1271
|
+
var getStorage = function (key) {
|
|
1272
|
+
try {
|
|
1273
|
+
var str = localStorage.getItem(key);
|
|
1274
|
+
if (str === null || str === undefined) {
|
|
1275
|
+
return null;
|
|
1276
|
+
}
|
|
1277
|
+
return JSON.parse(str);
|
|
1278
|
+
}
|
|
1279
|
+
catch (error) {
|
|
1280
|
+
console.error(error);
|
|
1281
|
+
return null;
|
|
1282
|
+
}
|
|
1283
|
+
};
|
|
1284
|
+
var clearStorage = function (key) {
|
|
1285
|
+
try {
|
|
1286
|
+
key && localStorage.removeItem(key);
|
|
1287
|
+
!key && localStorage.clear();
|
|
1288
|
+
}
|
|
1289
|
+
catch (error) {
|
|
1290
|
+
console.error(error);
|
|
1291
|
+
}
|
|
1292
|
+
};
|
|
1293
|
+
var storage = {
|
|
1294
|
+
setStorage: setStorage,
|
|
1295
|
+
getStorage: getStorage,
|
|
1296
|
+
clearStorage: clearStorage
|
|
1297
|
+
};
|
|
1298
|
+
|
|
1299
|
+
var logOneLine = function (str, overwrite, warp) {
|
|
1300
|
+
if (overwrite === void 0) { overwrite = false; }
|
|
1301
|
+
if (warp === void 0) { warp = true; }
|
|
1302
|
+
if (overwrite) {
|
|
1303
|
+
process.stdout.clearLine(0);
|
|
1304
|
+
process.stdout.cursorTo(0);
|
|
1305
|
+
}
|
|
1306
|
+
process.stdout.write(str);
|
|
1307
|
+
warp && process.stdout.write("\n");
|
|
1308
|
+
};
|
|
1309
|
+
var renderLoop = function (str) { return logOneLine(str, true, false); };
|
|
1310
|
+
var defaultLoopList = ["\\", "|", "/", "\u2014", "\u2014"];
|
|
1311
|
+
var logLoop = function (opts) {
|
|
1312
|
+
var _a;
|
|
1313
|
+
if (opts === void 0) { opts = {}; }
|
|
1314
|
+
var _b = opts.loopList, loopList = _b === void 0 ? defaultLoopList : _b, _c = opts.isStop, isStop = _c === void 0 ? false : _c, _d = opts.timer, timer = _d === void 0 ? 100 : _d;
|
|
1315
|
+
var _e = opts.index, index = _e === void 0 ? 0 : _e;
|
|
1316
|
+
var len = (_a = loopList === null || loopList === void 0 ? void 0 : loopList.length) !== null && _a !== void 0 ? _a : 0;
|
|
1317
|
+
if (!!!len)
|
|
1318
|
+
return opts;
|
|
1319
|
+
if (isStop)
|
|
1320
|
+
return renderLoop("\n");
|
|
1321
|
+
if (index >= len - 1)
|
|
1322
|
+
index = 0;
|
|
1323
|
+
var str = loopList[index++];
|
|
1324
|
+
renderLoop(str);
|
|
1325
|
+
setTimeout(function () {
|
|
1326
|
+
opts.index = index;
|
|
1327
|
+
logLoop(opts);
|
|
1328
|
+
}, timer);
|
|
1329
|
+
return opts;
|
|
1330
|
+
};
|
|
1331
|
+
var log = {
|
|
1332
|
+
logOneLine: logOneLine,
|
|
1333
|
+
logLoop: logLoop
|
|
1334
|
+
};
|
|
1335
|
+
|
|
1336
|
+
var AnimateFrame = (function () {
|
|
1337
|
+
function AnimateFrame(fn) {
|
|
1338
|
+
this.fn = fn;
|
|
1339
|
+
this.id = null;
|
|
1340
|
+
this.duration = Infinity;
|
|
1341
|
+
this.isActive = false;
|
|
1342
|
+
}
|
|
1343
|
+
AnimateFrame.prototype.start = function (duration) {
|
|
1344
|
+
if (this.isActive)
|
|
1345
|
+
return;
|
|
1346
|
+
this.duration = duration !== null && duration !== void 0 ? duration : Infinity;
|
|
1347
|
+
this.isActive = true;
|
|
1348
|
+
this.animate();
|
|
1349
|
+
};
|
|
1350
|
+
AnimateFrame.prototype.stop = function () {
|
|
1351
|
+
this.isActive = false;
|
|
1352
|
+
cancelAnimationFrame(this.id);
|
|
1353
|
+
};
|
|
1354
|
+
AnimateFrame.prototype.animate = function (timer) {
|
|
1355
|
+
if (timer === void 0) { timer = 0; }
|
|
1356
|
+
if (this.isActive && this.duration-- > 0) {
|
|
1357
|
+
this.fn(timer);
|
|
1358
|
+
this.id = requestAnimationFrame(this.animate.bind(this));
|
|
1359
|
+
}
|
|
1360
|
+
};
|
|
1361
|
+
return AnimateFrame;
|
|
1362
|
+
}());
|
|
1363
|
+
function quadraticBezier(_x, _y, t) {
|
|
1364
|
+
var mt = 1 - t;
|
|
1365
|
+
var t2 = t * t;
|
|
1366
|
+
var x = 2 * mt * t * _x + t2;
|
|
1367
|
+
var y = 2 * mt * t * _y + t2;
|
|
1368
|
+
return [x, y];
|
|
1369
|
+
}
|
|
1370
|
+
function cubicBezier(_x1, _y1, _x2, _y2, t) {
|
|
1371
|
+
var cx = 3 * _x1;
|
|
1372
|
+
var cy = 3 * _y1;
|
|
1373
|
+
var bx = 3 * (_x2 - _x1) - cx;
|
|
1374
|
+
var by = 3 * (_y2 - _y1) - cy;
|
|
1375
|
+
var ax = 1 - cx - bx;
|
|
1376
|
+
var ay = 1 - cy - by;
|
|
1377
|
+
var x = ax * Math.pow(t, 3) + bx * Math.pow(t, 2) + cx * t;
|
|
1378
|
+
var y = ay * Math.pow(t, 3) + by * Math.pow(t, 2) + cy * t;
|
|
1379
|
+
return [x, y];
|
|
1380
|
+
}
|
|
1381
|
+
function factorial(n) {
|
|
1382
|
+
if (n === 0 || n === 1) {
|
|
1383
|
+
return 1;
|
|
1384
|
+
}
|
|
1385
|
+
return n * factorial(n - 1);
|
|
1386
|
+
}
|
|
1387
|
+
function combination(n, k) {
|
|
1388
|
+
return factorial(n) / (factorial(k) * factorial(n - k));
|
|
1389
|
+
}
|
|
1390
|
+
function NBezier(points, t) {
|
|
1391
|
+
var n = points.length - 1;
|
|
1392
|
+
var result = [0, 0];
|
|
1393
|
+
for (var i = 0; i <= n; i++) {
|
|
1394
|
+
var coefficient = combination(n, i) * Math.pow(1 - t, n - i) * Math.pow(t, i);
|
|
1395
|
+
result[0] += coefficient * points[i][0];
|
|
1396
|
+
result[1] += coefficient * points[i][1];
|
|
1397
|
+
}
|
|
1398
|
+
return result;
|
|
1399
|
+
}
|
|
1400
|
+
var animate = {
|
|
1401
|
+
AnimateFrame: AnimateFrame,
|
|
1402
|
+
quadraticBezier: quadraticBezier,
|
|
1403
|
+
cubicBezier: cubicBezier,
|
|
1404
|
+
factorial: factorial,
|
|
1405
|
+
combination: combination,
|
|
1406
|
+
NBezier: NBezier,
|
|
1407
|
+
};
|
|
1408
|
+
|
|
1409
|
+
var MessageCenter = (function () {
|
|
1410
|
+
function MessageCenter(options) {
|
|
1411
|
+
if (options === void 0) { options = {}; }
|
|
1412
|
+
this.options = options;
|
|
1413
|
+
this.events = {};
|
|
1414
|
+
}
|
|
1415
|
+
MessageCenter.prototype.on = function (type, handler) {
|
|
1416
|
+
this.checkHandler(type, handler);
|
|
1417
|
+
var fns = this.getHandler(type, []);
|
|
1418
|
+
fns.push(handler);
|
|
1419
|
+
return this;
|
|
1420
|
+
};
|
|
1421
|
+
MessageCenter.prototype.emit = function (type, data) {
|
|
1422
|
+
if (this.has(type)) {
|
|
1423
|
+
this.runHandler(type, data);
|
|
1424
|
+
}
|
|
1425
|
+
return this;
|
|
1426
|
+
};
|
|
1427
|
+
MessageCenter.prototype.un = function (type, handler) {
|
|
1428
|
+
this.unHandler(type, handler);
|
|
1429
|
+
return this;
|
|
1430
|
+
};
|
|
1431
|
+
MessageCenter.prototype.once = function (type, handler) {
|
|
1432
|
+
var _this = this;
|
|
1433
|
+
this.checkHandler(type, handler);
|
|
1434
|
+
var fn = function () {
|
|
1435
|
+
var args = [];
|
|
1436
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1437
|
+
args[_i] = arguments[_i];
|
|
1438
|
+
}
|
|
1439
|
+
_this.un(type, fn);
|
|
1440
|
+
return handler.apply(void 0, args);
|
|
1441
|
+
};
|
|
1442
|
+
this.on(type, fn);
|
|
1443
|
+
return this;
|
|
1444
|
+
};
|
|
1445
|
+
MessageCenter.prototype.clear = function () {
|
|
1446
|
+
this.events = {};
|
|
1447
|
+
return this;
|
|
1448
|
+
};
|
|
1449
|
+
MessageCenter.prototype.has = function (type) {
|
|
1450
|
+
return !!this.getHandler(type);
|
|
1451
|
+
};
|
|
1452
|
+
MessageCenter.prototype.getHandler = function (type, defaultVal) {
|
|
1453
|
+
var _a;
|
|
1454
|
+
typeof defaultVal === "object" && (this.events[type] = (_a = this.events[type]) !== null && _a !== void 0 ? _a : defaultVal);
|
|
1455
|
+
return this.events[type];
|
|
1456
|
+
};
|
|
1457
|
+
MessageCenter.prototype.handlerLength = function (type) {
|
|
1458
|
+
var _a, _b;
|
|
1459
|
+
return (_b = (_a = this.getHandler(type)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
1460
|
+
};
|
|
1461
|
+
MessageCenter.prototype.watch = function (type, handler) {
|
|
1462
|
+
var _this = this;
|
|
1463
|
+
this.checkHandler(type, handler);
|
|
1464
|
+
var fn = function () {
|
|
1465
|
+
var args = [];
|
|
1466
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1467
|
+
args[_i] = arguments[_i];
|
|
1468
|
+
}
|
|
1469
|
+
_this.emit(_this.prefixStr(type), handler.apply(void 0, args));
|
|
1470
|
+
};
|
|
1471
|
+
this.on(type, fn);
|
|
1472
|
+
return this;
|
|
1473
|
+
};
|
|
1474
|
+
MessageCenter.prototype.invoke = function (type, data) {
|
|
1475
|
+
var _this = this;
|
|
1476
|
+
return new Promise(function (resolve) {
|
|
1477
|
+
_this.once(_this.prefixStr(type), resolve);
|
|
1478
|
+
_this.emit(type, data);
|
|
1479
|
+
});
|
|
1480
|
+
};
|
|
1481
|
+
MessageCenter.prototype.runHandler = function (type, data) {
|
|
1482
|
+
var _fns = this.getHandler(type);
|
|
1483
|
+
for (var _i = 0, _fns_1 = _fns; _i < _fns_1.length; _i++) {
|
|
1484
|
+
var fn = _fns_1[_i];
|
|
1485
|
+
fn && fn(data);
|
|
1486
|
+
}
|
|
1487
|
+
};
|
|
1488
|
+
MessageCenter.prototype.unHandler = function (type, handler) {
|
|
1489
|
+
var _fns = this.getHandler(type);
|
|
1490
|
+
!handler && (this.events[type] = []);
|
|
1491
|
+
handler && this.checkHandler(type, handler);
|
|
1492
|
+
for (var i = 0; i < _fns.length; i++) {
|
|
1493
|
+
if (_fns && _fns[i] === handler) {
|
|
1494
|
+
_fns[i] = null;
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
};
|
|
1498
|
+
MessageCenter.prototype.prefixStr = function (str) {
|
|
1499
|
+
return "@".concat(str);
|
|
1500
|
+
};
|
|
1501
|
+
MessageCenter.prototype.checkHandler = function (type, handler) {
|
|
1502
|
+
var _a = this.options, _b = _a.blackList, blackList = _b === void 0 ? [] : _b, _c = _a.maxLen, maxLen = _c === void 0 ? Infinity : _c;
|
|
1503
|
+
var len = this.handlerLength(type);
|
|
1504
|
+
if ((type === null || type === void 0 ? void 0 : type.length) === 0) {
|
|
1505
|
+
throw new Error('type.length can not be 0');
|
|
1506
|
+
}
|
|
1507
|
+
if (!handler || !type) {
|
|
1508
|
+
throw new ReferenceError('type or handler is not defined');
|
|
1509
|
+
}
|
|
1510
|
+
if (typeof handler !== 'function' || typeof type !== 'string') {
|
|
1511
|
+
throw new TypeError("".concat(handler, " is not a function or ").concat(type, " is not a string"));
|
|
1512
|
+
}
|
|
1513
|
+
if (blackList.includes(type)) {
|
|
1514
|
+
throw new Error("".concat(type, " is not allow"));
|
|
1515
|
+
}
|
|
1516
|
+
if (maxLen <= len) {
|
|
1517
|
+
throw new Error("the number of ".concat(type, " must be less than ").concat(maxLen));
|
|
1518
|
+
}
|
|
1519
|
+
};
|
|
1520
|
+
MessageCenter.Instance = function (Fn) {
|
|
1521
|
+
if (!Fn._instance) {
|
|
1522
|
+
Object.defineProperty(Fn, "_instance", {
|
|
1523
|
+
value: new Fn()
|
|
1524
|
+
});
|
|
1525
|
+
}
|
|
1526
|
+
return Fn._instance;
|
|
1527
|
+
};
|
|
1528
|
+
return MessageCenter;
|
|
1529
|
+
}());
|
|
1530
|
+
MessageCenter.Instance(MessageCenter);
|
|
1531
|
+
var decoratorMessageCenter = function (target) {
|
|
1532
|
+
if (!target.prototype.messageCenter) {
|
|
1533
|
+
target.prototype.messageCenter = new MessageCenter();
|
|
1534
|
+
}
|
|
1535
|
+
return target;
|
|
1536
|
+
};
|
|
1537
|
+
|
|
1538
|
+
var __assign$2 = function () {
|
|
1539
|
+
__assign$2 = Object.assign || function(t) {
|
|
1540
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
1541
|
+
s = arguments[i];
|
|
1542
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
1543
|
+
t[p] = s[p];
|
|
1544
|
+
}
|
|
1545
|
+
return t;
|
|
1546
|
+
};
|
|
1547
|
+
return __assign$2.apply(this, arguments);
|
|
1548
|
+
};
|
|
1549
|
+
var __decorate = function (decorators, target, key, desc) {
|
|
1550
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1551
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1552
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1553
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1554
|
+
};
|
|
1555
|
+
var __metadata = function (k, v) {
|
|
1556
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1557
|
+
};
|
|
1558
|
+
var __awaiter = function (thisArg, _arguments, P, generator) {
|
|
1559
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1560
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1561
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
1562
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
1563
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
1564
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1565
|
+
});
|
|
1566
|
+
};
|
|
1567
|
+
var __generator = function (thisArg, body) {
|
|
1568
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
1569
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
1570
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
1571
|
+
function step(op) {
|
|
1572
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
1573
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
1574
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
1575
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
1576
|
+
switch (op[0]) {
|
|
1577
|
+
case 0: case 1: t = op; break;
|
|
1578
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
1579
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
1580
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
1581
|
+
default:
|
|
1582
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
1583
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
1584
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
1585
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
1586
|
+
if (t[2]) _.ops.pop();
|
|
1587
|
+
_.trys.pop(); continue;
|
|
1588
|
+
}
|
|
1589
|
+
op = body.call(thisArg, _);
|
|
1590
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
1591
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
1592
|
+
}
|
|
1593
|
+
};
|
|
1594
|
+
var TaskQueue = (function () {
|
|
1595
|
+
function TaskQueue(props) {
|
|
1596
|
+
var _this = this;
|
|
1597
|
+
this.fix = "@~&$";
|
|
1598
|
+
this.init = function () {
|
|
1599
|
+
_this.messageCenter.on("push:handler", _this.run);
|
|
1600
|
+
_this.messageCenter.on("run:success:handler", _this.run);
|
|
1601
|
+
_this.messageCenter.on("run:success:handler", _this.finish);
|
|
1602
|
+
_this.messageCenter.on("run:error:handler", _this.run);
|
|
1603
|
+
_this.messageCenter.on("run:error:handler", _this.finish);
|
|
1604
|
+
};
|
|
1605
|
+
this.defineProps = function (props, key) {
|
|
1606
|
+
Object.defineProperty(_this, key, { value: props });
|
|
1607
|
+
};
|
|
1608
|
+
this.push = function (queue) {
|
|
1609
|
+
var _a;
|
|
1610
|
+
_this.checkHandler(queue);
|
|
1611
|
+
var resolve = (_a = _this.defer(), _a.resolve), reject = _a.reject, promise = _a.promise;
|
|
1612
|
+
var queueName = _this.fixStr(queue.name);
|
|
1613
|
+
_this.queues = _this.queues.concat(queue.children.map(function (defer) { return ({ defer: defer, name: queueName }); }));
|
|
1614
|
+
_this.queueTemp[queueName] = __assign$2(__assign$2({}, queue), { result: [] });
|
|
1615
|
+
_this.messageCenter.emit("push:handler", reject);
|
|
1616
|
+
_this.messageCenter.on(queueName, resolve);
|
|
1617
|
+
return promise;
|
|
1618
|
+
};
|
|
1619
|
+
this.unshift = function (length) {
|
|
1620
|
+
return _this.queues.splice(0, length);
|
|
1621
|
+
};
|
|
1622
|
+
this.run = function (_a) {
|
|
1623
|
+
var reject = _a.reject;
|
|
1624
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
1625
|
+
var queues, res, error_1;
|
|
1626
|
+
var _b, _c;
|
|
1627
|
+
return __generator(this, function (_d) {
|
|
1628
|
+
switch (_d.label) {
|
|
1629
|
+
case 0:
|
|
1630
|
+
if (this.stateProxy() === 'pending')
|
|
1631
|
+
return [2, void 0];
|
|
1632
|
+
if (this.queues.length === 0)
|
|
1633
|
+
return [2, this.stateProxy("idle")];
|
|
1634
|
+
this.stateProxy("pending");
|
|
1635
|
+
queues = this.unshift((_c = (_b = this.props) === null || _b === void 0 ? void 0 : _b.maxLen) !== null && _c !== void 0 ? _c : 10);
|
|
1636
|
+
_d.label = 1;
|
|
1637
|
+
case 1:
|
|
1638
|
+
_d.trys.push([1, 3, , 4]);
|
|
1639
|
+
return [4, Promise.all(queues.map(function (item, i) { return item.defer().catch(function (error) { return error; }); }))];
|
|
1640
|
+
case 2:
|
|
1641
|
+
res = _d.sent();
|
|
1642
|
+
return [2, this.handlerSuccess({ res: res, queues: queues })];
|
|
1643
|
+
case 3:
|
|
1644
|
+
error_1 = _d.sent();
|
|
1645
|
+
return [2, this.handlerError({ reject: reject, error: error_1, queues: queues })];
|
|
1646
|
+
case 4: return [2];
|
|
1647
|
+
}
|
|
1648
|
+
});
|
|
1649
|
+
});
|
|
1650
|
+
};
|
|
1651
|
+
this.clear = function () {
|
|
1652
|
+
_this.queues = [];
|
|
1653
|
+
_this.queueTemp = {};
|
|
1654
|
+
_this.props = null;
|
|
1655
|
+
_this.stateProxy("idle");
|
|
1656
|
+
_this.messageCenter.clear();
|
|
1657
|
+
};
|
|
1658
|
+
this.finish = function (_a) {
|
|
1659
|
+
var _b = _a.res, res = _b === void 0 ? [] : _b, queues = _a.queues, _c = _a.error, error = _c === void 0 ? 'err' : _c;
|
|
1660
|
+
var queueTemp = _this.queueTemp;
|
|
1661
|
+
queues.forEach(function (it, i) {
|
|
1662
|
+
var _a, _b, _c;
|
|
1663
|
+
var item = queueTemp[it.name];
|
|
1664
|
+
item === null || item === void 0 ? void 0 : item.result.push((_a = res[i]) !== null && _a !== void 0 ? _a : error);
|
|
1665
|
+
if (((_b = item === null || item === void 0 ? void 0 : item.result) === null || _b === void 0 ? void 0 : _b.length) === ((_c = item === null || item === void 0 ? void 0 : item.children) === null || _c === void 0 ? void 0 : _c.length)) {
|
|
1666
|
+
_this.messageCenter.emit(it.name, item === null || item === void 0 ? void 0 : item.result);
|
|
1667
|
+
queueTemp[it.name] = null;
|
|
1668
|
+
}
|
|
1669
|
+
});
|
|
1670
|
+
};
|
|
1671
|
+
this.handlerSuccess = function (data) {
|
|
1672
|
+
_this.stateProxy("fulfilled");
|
|
1673
|
+
return _this.messageCenter.emit("run:success:handler", data);
|
|
1674
|
+
};
|
|
1675
|
+
this.handlerError = function (data) {
|
|
1676
|
+
var reject = data.reject, error = data.error;
|
|
1677
|
+
_this.stateProxy("rejected");
|
|
1678
|
+
reject && typeof reject === "function" && reject(error);
|
|
1679
|
+
return _this.messageCenter.emit("run:error:handler", data);
|
|
1680
|
+
};
|
|
1681
|
+
this.stateProxy = function (state) {
|
|
1682
|
+
state && (_this.state = state);
|
|
1683
|
+
return _this.state;
|
|
1684
|
+
};
|
|
1685
|
+
this.defer = function () {
|
|
1686
|
+
var resolve, reject;
|
|
1687
|
+
return {
|
|
1688
|
+
promise: new Promise(function (_resolve, _reject) {
|
|
1689
|
+
resolve = _resolve;
|
|
1690
|
+
reject = _reject;
|
|
1691
|
+
}),
|
|
1692
|
+
resolve: resolve,
|
|
1693
|
+
reject: reject
|
|
1694
|
+
};
|
|
1695
|
+
};
|
|
1696
|
+
this.clear();
|
|
1697
|
+
props && this.defineProps(props, "props");
|
|
1698
|
+
this.init();
|
|
1699
|
+
}
|
|
1700
|
+
TaskQueue.prototype.checkHandler = function (queue) {
|
|
1701
|
+
var _a, _b;
|
|
1702
|
+
if (!queue) {
|
|
1703
|
+
throw new ReferenceError('queue is not defined');
|
|
1704
|
+
}
|
|
1705
|
+
if (!(queue.children instanceof Array) || typeof queue !== "object") {
|
|
1706
|
+
throw new TypeError("queue should be an object and queue.children should be an array");
|
|
1707
|
+
}
|
|
1708
|
+
var noFn = function (i) { return !i || typeof i !== "function"; };
|
|
1709
|
+
if (((_a = queue.children) === null || _a === void 0 ? void 0 : _a.length) === 0)
|
|
1710
|
+
throw new Error('queue.children.length can not be 0');
|
|
1711
|
+
if ((_b = queue.children) === null || _b === void 0 ? void 0 : _b.find(function (i) { return noFn(i); }))
|
|
1712
|
+
throw new Error('queueList should have defer');
|
|
1713
|
+
};
|
|
1714
|
+
TaskQueue.prototype.fixStr = function (str) {
|
|
1715
|
+
return "".concat(this.fix).concat(str);
|
|
1716
|
+
};
|
|
1717
|
+
TaskQueue = __decorate([
|
|
1718
|
+
decoratorMessageCenter,
|
|
1719
|
+
__metadata("design:paramtypes", [Object])
|
|
1720
|
+
], TaskQueue);
|
|
1721
|
+
return TaskQueue;
|
|
1722
|
+
}());
|
|
1723
|
+
|
|
1724
|
+
__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1({}, object), base), array), __function), element), __static), event), storage), log), animate), { eventMessageCenter: MessageCenter, taskQueueLib: TaskQueue });
|
|
1725
|
+
|
|
1726
|
+
/**
|
|
1727
|
+
* @author Toru Nagashima <https://github.com/mysticatea>
|
|
1728
|
+
* @copyright 2015 Toru Nagashima. All rights reserved.
|
|
1729
|
+
* See LICENSE file in root directory for full license.
|
|
1730
|
+
*/
|
|
1731
|
+
/**
|
|
1732
|
+
* @typedef {object} PrivateData
|
|
1733
|
+
* @property {EventTarget} eventTarget The event target.
|
|
1734
|
+
* @property {{type:string}} event The original event object.
|
|
1735
|
+
* @property {number} eventPhase The current event phase.
|
|
1736
|
+
* @property {EventTarget|null} currentTarget The current event target.
|
|
1737
|
+
* @property {boolean} canceled The flag to prevent default.
|
|
1738
|
+
* @property {boolean} stopped The flag to stop propagation.
|
|
1739
|
+
* @property {boolean} immediateStopped The flag to stop propagation immediately.
|
|
1740
|
+
* @property {Function|null} passiveListener The listener if the current listener is passive. Otherwise this is null.
|
|
1741
|
+
* @property {number} timeStamp The unix time.
|
|
1742
|
+
* @private
|
|
1743
|
+
*/
|
|
1744
|
+
|
|
1745
|
+
/**
|
|
1746
|
+
* Private data for event wrappers.
|
|
1747
|
+
* @type {WeakMap<Event, PrivateData>}
|
|
1748
|
+
* @private
|
|
1749
|
+
*/
|
|
1750
|
+
const privateData = new WeakMap();
|
|
1751
|
+
|
|
1752
|
+
/**
|
|
1753
|
+
* Cache for wrapper classes.
|
|
1754
|
+
* @type {WeakMap<Object, Function>}
|
|
1755
|
+
* @private
|
|
1756
|
+
*/
|
|
1757
|
+
const wrappers = new WeakMap();
|
|
1758
|
+
|
|
1759
|
+
/**
|
|
1760
|
+
* Get private data.
|
|
1761
|
+
* @param {Event} event The event object to get private data.
|
|
1762
|
+
* @returns {PrivateData} The private data of the event.
|
|
1763
|
+
* @private
|
|
1764
|
+
*/
|
|
1765
|
+
function pd(event) {
|
|
1766
|
+
const retv = privateData.get(event);
|
|
1767
|
+
console.assert(
|
|
1768
|
+
retv != null,
|
|
1769
|
+
"'this' is expected an Event object, but got",
|
|
1770
|
+
event
|
|
1771
|
+
);
|
|
1772
|
+
return retv
|
|
1773
|
+
}
|
|
1774
|
+
|
|
1775
|
+
/**
|
|
1776
|
+
* https://dom.spec.whatwg.org/#set-the-canceled-flag
|
|
1777
|
+
* @param data {PrivateData} private data.
|
|
1778
|
+
*/
|
|
1779
|
+
function setCancelFlag(data) {
|
|
1780
|
+
if (data.passiveListener != null) {
|
|
1781
|
+
if (
|
|
1782
|
+
typeof console !== "undefined" &&
|
|
1783
|
+
typeof console.error === "function"
|
|
1784
|
+
) {
|
|
1785
|
+
console.error(
|
|
1786
|
+
"Unable to preventDefault inside passive event listener invocation.",
|
|
1787
|
+
data.passiveListener
|
|
1788
|
+
);
|
|
1789
|
+
}
|
|
1790
|
+
return
|
|
1791
|
+
}
|
|
1792
|
+
if (!data.event.cancelable) {
|
|
1793
|
+
return
|
|
1794
|
+
}
|
|
1795
|
+
|
|
1796
|
+
data.canceled = true;
|
|
1797
|
+
if (typeof data.event.preventDefault === "function") {
|
|
1798
|
+
data.event.preventDefault();
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
|
|
1802
|
+
/**
|
|
1803
|
+
* @see https://dom.spec.whatwg.org/#interface-event
|
|
1804
|
+
* @private
|
|
1805
|
+
*/
|
|
1806
|
+
/**
|
|
1807
|
+
* The event wrapper.
|
|
1808
|
+
* @constructor
|
|
1809
|
+
* @param {EventTarget} eventTarget The event target of this dispatching.
|
|
1810
|
+
* @param {Event|{type:string}} event The original event to wrap.
|
|
1811
|
+
*/
|
|
1812
|
+
function Event$1(eventTarget, event) {
|
|
1813
|
+
privateData.set(this, {
|
|
1814
|
+
eventTarget,
|
|
1815
|
+
event,
|
|
1816
|
+
eventPhase: 2,
|
|
1817
|
+
currentTarget: eventTarget,
|
|
1818
|
+
canceled: false,
|
|
1819
|
+
stopped: false,
|
|
1820
|
+
immediateStopped: false,
|
|
1821
|
+
passiveListener: null,
|
|
1822
|
+
timeStamp: event.timeStamp || Date.now(),
|
|
1823
|
+
});
|
|
1824
|
+
|
|
1825
|
+
// https://heycam.github.io/webidl/#Unforgeable
|
|
1826
|
+
Object.defineProperty(this, "isTrusted", { value: false, enumerable: true });
|
|
1827
|
+
|
|
1828
|
+
// Define accessors
|
|
1829
|
+
const keys = Object.keys(event);
|
|
1830
|
+
for (let i = 0; i < keys.length; ++i) {
|
|
1831
|
+
const key = keys[i];
|
|
1832
|
+
if (!(key in this)) {
|
|
1833
|
+
Object.defineProperty(this, key, defineRedirectDescriptor(key));
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
|
|
1838
|
+
// Should be enumerable, but class methods are not enumerable.
|
|
1839
|
+
Event$1.prototype = {
|
|
1840
|
+
/**
|
|
1841
|
+
* The type of this event.
|
|
1842
|
+
* @type {string}
|
|
1843
|
+
*/
|
|
1844
|
+
get type() {
|
|
1845
|
+
return pd(this).event.type
|
|
1846
|
+
},
|
|
1847
|
+
|
|
1848
|
+
/**
|
|
1849
|
+
* The target of this event.
|
|
1850
|
+
* @type {EventTarget}
|
|
1851
|
+
*/
|
|
1852
|
+
get target() {
|
|
1853
|
+
return pd(this).eventTarget
|
|
1854
|
+
},
|
|
1855
|
+
|
|
1856
|
+
/**
|
|
1857
|
+
* The target of this event.
|
|
1858
|
+
* @type {EventTarget}
|
|
1859
|
+
*/
|
|
1860
|
+
get currentTarget() {
|
|
1861
|
+
return pd(this).currentTarget
|
|
1862
|
+
},
|
|
1863
|
+
|
|
1864
|
+
/**
|
|
1865
|
+
* @returns {EventTarget[]} The composed path of this event.
|
|
1866
|
+
*/
|
|
1867
|
+
composedPath() {
|
|
1868
|
+
const currentTarget = pd(this).currentTarget;
|
|
1869
|
+
if (currentTarget == null) {
|
|
1870
|
+
return []
|
|
1871
|
+
}
|
|
1872
|
+
return [currentTarget]
|
|
1873
|
+
},
|
|
1874
|
+
|
|
1875
|
+
/**
|
|
1876
|
+
* Constant of NONE.
|
|
1877
|
+
* @type {number}
|
|
1878
|
+
*/
|
|
1879
|
+
get NONE() {
|
|
1880
|
+
return 0
|
|
1881
|
+
},
|
|
1882
|
+
|
|
1883
|
+
/**
|
|
1884
|
+
* Constant of CAPTURING_PHASE.
|
|
1885
|
+
* @type {number}
|
|
1886
|
+
*/
|
|
1887
|
+
get CAPTURING_PHASE() {
|
|
1888
|
+
return 1
|
|
1889
|
+
},
|
|
1890
|
+
|
|
1891
|
+
/**
|
|
1892
|
+
* Constant of AT_TARGET.
|
|
1893
|
+
* @type {number}
|
|
1894
|
+
*/
|
|
1895
|
+
get AT_TARGET() {
|
|
1896
|
+
return 2
|
|
1897
|
+
},
|
|
1898
|
+
|
|
1899
|
+
/**
|
|
1900
|
+
* Constant of BUBBLING_PHASE.
|
|
1901
|
+
* @type {number}
|
|
1902
|
+
*/
|
|
1903
|
+
get BUBBLING_PHASE() {
|
|
1904
|
+
return 3
|
|
1905
|
+
},
|
|
1906
|
+
|
|
1907
|
+
/**
|
|
1908
|
+
* The target of this event.
|
|
1909
|
+
* @type {number}
|
|
1910
|
+
*/
|
|
1911
|
+
get eventPhase() {
|
|
1912
|
+
return pd(this).eventPhase
|
|
1913
|
+
},
|
|
1914
|
+
|
|
1915
|
+
/**
|
|
1916
|
+
* Stop event bubbling.
|
|
1917
|
+
* @returns {void}
|
|
1918
|
+
*/
|
|
1919
|
+
stopPropagation() {
|
|
1920
|
+
const data = pd(this);
|
|
1921
|
+
|
|
1922
|
+
data.stopped = true;
|
|
1923
|
+
if (typeof data.event.stopPropagation === "function") {
|
|
1924
|
+
data.event.stopPropagation();
|
|
1925
|
+
}
|
|
1926
|
+
},
|
|
1927
|
+
|
|
1928
|
+
/**
|
|
1929
|
+
* Stop event bubbling.
|
|
1930
|
+
* @returns {void}
|
|
1931
|
+
*/
|
|
1932
|
+
stopImmediatePropagation() {
|
|
1933
|
+
const data = pd(this);
|
|
1934
|
+
|
|
1935
|
+
data.stopped = true;
|
|
1936
|
+
data.immediateStopped = true;
|
|
1937
|
+
if (typeof data.event.stopImmediatePropagation === "function") {
|
|
1938
|
+
data.event.stopImmediatePropagation();
|
|
1939
|
+
}
|
|
1940
|
+
},
|
|
1941
|
+
|
|
1942
|
+
/**
|
|
1943
|
+
* The flag to be bubbling.
|
|
1944
|
+
* @type {boolean}
|
|
1945
|
+
*/
|
|
1946
|
+
get bubbles() {
|
|
1947
|
+
return Boolean(pd(this).event.bubbles)
|
|
1948
|
+
},
|
|
1949
|
+
|
|
1950
|
+
/**
|
|
1951
|
+
* The flag to be cancelable.
|
|
1952
|
+
* @type {boolean}
|
|
1953
|
+
*/
|
|
1954
|
+
get cancelable() {
|
|
1955
|
+
return Boolean(pd(this).event.cancelable)
|
|
1956
|
+
},
|
|
1957
|
+
|
|
1958
|
+
/**
|
|
1959
|
+
* Cancel this event.
|
|
1960
|
+
* @returns {void}
|
|
1961
|
+
*/
|
|
1962
|
+
preventDefault() {
|
|
1963
|
+
setCancelFlag(pd(this));
|
|
1964
|
+
},
|
|
1965
|
+
|
|
1966
|
+
/**
|
|
1967
|
+
* The flag to indicate cancellation state.
|
|
1968
|
+
* @type {boolean}
|
|
1969
|
+
*/
|
|
1970
|
+
get defaultPrevented() {
|
|
1971
|
+
return pd(this).canceled
|
|
1972
|
+
},
|
|
1973
|
+
|
|
1974
|
+
/**
|
|
1975
|
+
* The flag to be composed.
|
|
1976
|
+
* @type {boolean}
|
|
1977
|
+
*/
|
|
1978
|
+
get composed() {
|
|
1979
|
+
return Boolean(pd(this).event.composed)
|
|
1980
|
+
},
|
|
1981
|
+
|
|
1982
|
+
/**
|
|
1983
|
+
* The unix time of this event.
|
|
1984
|
+
* @type {number}
|
|
1985
|
+
*/
|
|
1986
|
+
get timeStamp() {
|
|
1987
|
+
return pd(this).timeStamp
|
|
1988
|
+
},
|
|
1989
|
+
|
|
1990
|
+
/**
|
|
1991
|
+
* The target of this event.
|
|
1992
|
+
* @type {EventTarget}
|
|
1993
|
+
* @deprecated
|
|
1994
|
+
*/
|
|
1995
|
+
get srcElement() {
|
|
1996
|
+
return pd(this).eventTarget
|
|
1997
|
+
},
|
|
1998
|
+
|
|
1999
|
+
/**
|
|
2000
|
+
* The flag to stop event bubbling.
|
|
2001
|
+
* @type {boolean}
|
|
2002
|
+
* @deprecated
|
|
2003
|
+
*/
|
|
2004
|
+
get cancelBubble() {
|
|
2005
|
+
return pd(this).stopped
|
|
2006
|
+
},
|
|
2007
|
+
set cancelBubble(value) {
|
|
2008
|
+
if (!value) {
|
|
2009
|
+
return
|
|
2010
|
+
}
|
|
2011
|
+
const data = pd(this);
|
|
2012
|
+
|
|
2013
|
+
data.stopped = true;
|
|
2014
|
+
if (typeof data.event.cancelBubble === "boolean") {
|
|
2015
|
+
data.event.cancelBubble = true;
|
|
2016
|
+
}
|
|
2017
|
+
},
|
|
2018
|
+
|
|
2019
|
+
/**
|
|
2020
|
+
* The flag to indicate cancellation state.
|
|
2021
|
+
* @type {boolean}
|
|
2022
|
+
* @deprecated
|
|
2023
|
+
*/
|
|
2024
|
+
get returnValue() {
|
|
2025
|
+
return !pd(this).canceled
|
|
2026
|
+
},
|
|
2027
|
+
set returnValue(value) {
|
|
2028
|
+
if (!value) {
|
|
2029
|
+
setCancelFlag(pd(this));
|
|
2030
|
+
}
|
|
2031
|
+
},
|
|
2032
|
+
|
|
2033
|
+
/**
|
|
2034
|
+
* Initialize this event object. But do nothing under event dispatching.
|
|
2035
|
+
* @param {string} type The event type.
|
|
2036
|
+
* @param {boolean} [bubbles=false] The flag to be possible to bubble up.
|
|
2037
|
+
* @param {boolean} [cancelable=false] The flag to be possible to cancel.
|
|
2038
|
+
* @deprecated
|
|
2039
|
+
*/
|
|
2040
|
+
initEvent() {
|
|
2041
|
+
// Do nothing.
|
|
2042
|
+
},
|
|
2043
|
+
};
|
|
2044
|
+
|
|
2045
|
+
// `constructor` is not enumerable.
|
|
2046
|
+
Object.defineProperty(Event$1.prototype, "constructor", {
|
|
2047
|
+
value: Event$1,
|
|
2048
|
+
configurable: true,
|
|
2049
|
+
writable: true,
|
|
2050
|
+
});
|
|
2051
|
+
|
|
2052
|
+
// Ensure `event instanceof window.Event` is `true`.
|
|
2053
|
+
if (typeof window !== "undefined" && typeof window.Event !== "undefined") {
|
|
2054
|
+
Object.setPrototypeOf(Event$1.prototype, window.Event.prototype);
|
|
2055
|
+
|
|
2056
|
+
// Make association for wrappers.
|
|
2057
|
+
wrappers.set(window.Event.prototype, Event$1);
|
|
2058
|
+
}
|
|
2059
|
+
|
|
2060
|
+
/**
|
|
2061
|
+
* Get the property descriptor to redirect a given property.
|
|
2062
|
+
* @param {string} key Property name to define property descriptor.
|
|
2063
|
+
* @returns {PropertyDescriptor} The property descriptor to redirect the property.
|
|
2064
|
+
* @private
|
|
2065
|
+
*/
|
|
2066
|
+
function defineRedirectDescriptor(key) {
|
|
2067
|
+
return {
|
|
2068
|
+
get() {
|
|
2069
|
+
return pd(this).event[key]
|
|
2070
|
+
},
|
|
2071
|
+
set(value) {
|
|
2072
|
+
pd(this).event[key] = value;
|
|
2073
|
+
},
|
|
2074
|
+
configurable: true,
|
|
2075
|
+
enumerable: true,
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
|
|
2079
|
+
/**
|
|
2080
|
+
* Get the property descriptor to call a given method property.
|
|
2081
|
+
* @param {string} key Property name to define property descriptor.
|
|
2082
|
+
* @returns {PropertyDescriptor} The property descriptor to call the method property.
|
|
2083
|
+
* @private
|
|
2084
|
+
*/
|
|
2085
|
+
function defineCallDescriptor(key) {
|
|
2086
|
+
return {
|
|
2087
|
+
value() {
|
|
2088
|
+
const event = pd(this).event;
|
|
2089
|
+
return event[key].apply(event, arguments)
|
|
2090
|
+
},
|
|
2091
|
+
configurable: true,
|
|
2092
|
+
enumerable: true,
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
|
|
2096
|
+
/**
|
|
2097
|
+
* Define new wrapper class.
|
|
2098
|
+
* @param {Function} BaseEvent The base wrapper class.
|
|
2099
|
+
* @param {Object} proto The prototype of the original event.
|
|
2100
|
+
* @returns {Function} The defined wrapper class.
|
|
2101
|
+
* @private
|
|
2102
|
+
*/
|
|
2103
|
+
function defineWrapper(BaseEvent, proto) {
|
|
2104
|
+
const keys = Object.keys(proto);
|
|
2105
|
+
if (keys.length === 0) {
|
|
2106
|
+
return BaseEvent
|
|
2107
|
+
}
|
|
2108
|
+
|
|
2109
|
+
/** CustomEvent */
|
|
2110
|
+
function CustomEvent(eventTarget, event) {
|
|
2111
|
+
BaseEvent.call(this, eventTarget, event);
|
|
2112
|
+
}
|
|
2113
|
+
|
|
2114
|
+
CustomEvent.prototype = Object.create(BaseEvent.prototype, {
|
|
2115
|
+
constructor: { value: CustomEvent, configurable: true, writable: true },
|
|
2116
|
+
});
|
|
2117
|
+
|
|
2118
|
+
// Define accessors.
|
|
2119
|
+
for (let i = 0; i < keys.length; ++i) {
|
|
2120
|
+
const key = keys[i];
|
|
2121
|
+
if (!(key in BaseEvent.prototype)) {
|
|
2122
|
+
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
2123
|
+
const isFunc = typeof descriptor.value === "function";
|
|
2124
|
+
Object.defineProperty(
|
|
2125
|
+
CustomEvent.prototype,
|
|
2126
|
+
key,
|
|
2127
|
+
isFunc
|
|
2128
|
+
? defineCallDescriptor(key)
|
|
2129
|
+
: defineRedirectDescriptor(key)
|
|
2130
|
+
);
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
|
|
2134
|
+
return CustomEvent
|
|
2135
|
+
}
|
|
2136
|
+
|
|
2137
|
+
/**
|
|
2138
|
+
* Get the wrapper class of a given prototype.
|
|
2139
|
+
* @param {Object} proto The prototype of the original event to get its wrapper.
|
|
2140
|
+
* @returns {Function} The wrapper class.
|
|
2141
|
+
* @private
|
|
2142
|
+
*/
|
|
2143
|
+
function getWrapper(proto) {
|
|
2144
|
+
if (proto == null || proto === Object.prototype) {
|
|
2145
|
+
return Event$1
|
|
2146
|
+
}
|
|
2147
|
+
|
|
2148
|
+
let wrapper = wrappers.get(proto);
|
|
2149
|
+
if (wrapper == null) {
|
|
2150
|
+
wrapper = defineWrapper(getWrapper(Object.getPrototypeOf(proto)), proto);
|
|
2151
|
+
wrappers.set(proto, wrapper);
|
|
2152
|
+
}
|
|
2153
|
+
return wrapper
|
|
2154
|
+
}
|
|
2155
|
+
|
|
2156
|
+
/**
|
|
2157
|
+
* Wrap a given event to management a dispatching.
|
|
2158
|
+
* @param {EventTarget} eventTarget The event target of this dispatching.
|
|
2159
|
+
* @param {Object} event The event to wrap.
|
|
2160
|
+
* @returns {Event} The wrapper instance.
|
|
2161
|
+
* @private
|
|
2162
|
+
*/
|
|
2163
|
+
function wrapEvent(eventTarget, event) {
|
|
2164
|
+
const Wrapper = getWrapper(Object.getPrototypeOf(event));
|
|
2165
|
+
return new Wrapper(eventTarget, event)
|
|
2166
|
+
}
|
|
2167
|
+
|
|
2168
|
+
/**
|
|
2169
|
+
* Get the immediateStopped flag of a given event.
|
|
2170
|
+
* @param {Event} event The event to get.
|
|
2171
|
+
* @returns {boolean} The flag to stop propagation immediately.
|
|
2172
|
+
* @private
|
|
2173
|
+
*/
|
|
2174
|
+
function isStopped(event) {
|
|
2175
|
+
return pd(event).immediateStopped
|
|
2176
|
+
}
|
|
2177
|
+
|
|
2178
|
+
/**
|
|
2179
|
+
* Set the current event phase of a given event.
|
|
2180
|
+
* @param {Event} event The event to set current target.
|
|
2181
|
+
* @param {number} eventPhase New event phase.
|
|
2182
|
+
* @returns {void}
|
|
2183
|
+
* @private
|
|
2184
|
+
*/
|
|
2185
|
+
function setEventPhase(event, eventPhase) {
|
|
2186
|
+
pd(event).eventPhase = eventPhase;
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2189
|
+
/**
|
|
2190
|
+
* Set the current target of a given event.
|
|
2191
|
+
* @param {Event} event The event to set current target.
|
|
2192
|
+
* @param {EventTarget|null} currentTarget New current target.
|
|
2193
|
+
* @returns {void}
|
|
2194
|
+
* @private
|
|
2195
|
+
*/
|
|
2196
|
+
function setCurrentTarget(event, currentTarget) {
|
|
2197
|
+
pd(event).currentTarget = currentTarget;
|
|
2198
|
+
}
|
|
2199
|
+
|
|
2200
|
+
/**
|
|
2201
|
+
* Set a passive listener of a given event.
|
|
2202
|
+
* @param {Event} event The event to set current target.
|
|
2203
|
+
* @param {Function|null} passiveListener New passive listener.
|
|
2204
|
+
* @returns {void}
|
|
2205
|
+
* @private
|
|
2206
|
+
*/
|
|
2207
|
+
function setPassiveListener(event, passiveListener) {
|
|
2208
|
+
pd(event).passiveListener = passiveListener;
|
|
2209
|
+
}
|
|
2210
|
+
|
|
2211
|
+
/**
|
|
2212
|
+
* @typedef {object} ListenerNode
|
|
2213
|
+
* @property {Function} listener
|
|
2214
|
+
* @property {1|2|3} listenerType
|
|
2215
|
+
* @property {boolean} passive
|
|
2216
|
+
* @property {boolean} once
|
|
2217
|
+
* @property {ListenerNode|null} next
|
|
2218
|
+
* @private
|
|
2219
|
+
*/
|
|
2220
|
+
|
|
2221
|
+
/**
|
|
2222
|
+
* @type {WeakMap<object, Map<string, ListenerNode>>}
|
|
2223
|
+
* @private
|
|
2224
|
+
*/
|
|
2225
|
+
const listenersMap = new WeakMap();
|
|
2226
|
+
|
|
2227
|
+
// Listener types
|
|
2228
|
+
const CAPTURE = 1;
|
|
2229
|
+
const BUBBLE = 2;
|
|
2230
|
+
const ATTRIBUTE = 3;
|
|
2231
|
+
|
|
2232
|
+
/**
|
|
2233
|
+
* Check whether a given value is an object or not.
|
|
2234
|
+
* @param {any} x The value to check.
|
|
2235
|
+
* @returns {boolean} `true` if the value is an object.
|
|
2236
|
+
*/
|
|
2237
|
+
function isObject(x) {
|
|
2238
|
+
return x !== null && typeof x === "object" //eslint-disable-line no-restricted-syntax
|
|
2239
|
+
}
|
|
2240
|
+
|
|
2241
|
+
/**
|
|
2242
|
+
* Get listeners.
|
|
2243
|
+
* @param {EventTarget} eventTarget The event target to get.
|
|
2244
|
+
* @returns {Map<string, ListenerNode>} The listeners.
|
|
2245
|
+
* @private
|
|
2246
|
+
*/
|
|
2247
|
+
function getListeners(eventTarget) {
|
|
2248
|
+
const listeners = listenersMap.get(eventTarget);
|
|
2249
|
+
if (listeners == null) {
|
|
2250
|
+
throw new TypeError(
|
|
2251
|
+
"'this' is expected an EventTarget object, but got another value."
|
|
2252
|
+
)
|
|
2253
|
+
}
|
|
2254
|
+
return listeners
|
|
2255
|
+
}
|
|
2256
|
+
|
|
2257
|
+
/**
|
|
2258
|
+
* Get the property descriptor for the event attribute of a given event.
|
|
2259
|
+
* @param {string} eventName The event name to get property descriptor.
|
|
2260
|
+
* @returns {PropertyDescriptor} The property descriptor.
|
|
2261
|
+
* @private
|
|
2262
|
+
*/
|
|
2263
|
+
function defineEventAttributeDescriptor(eventName) {
|
|
2264
|
+
return {
|
|
2265
|
+
get() {
|
|
2266
|
+
const listeners = getListeners(this);
|
|
2267
|
+
let node = listeners.get(eventName);
|
|
2268
|
+
while (node != null) {
|
|
2269
|
+
if (node.listenerType === ATTRIBUTE) {
|
|
2270
|
+
return node.listener
|
|
2271
|
+
}
|
|
2272
|
+
node = node.next;
|
|
2273
|
+
}
|
|
2274
|
+
return null
|
|
2275
|
+
},
|
|
2276
|
+
|
|
2277
|
+
set(listener) {
|
|
2278
|
+
if (typeof listener !== "function" && !isObject(listener)) {
|
|
2279
|
+
listener = null; // eslint-disable-line no-param-reassign
|
|
2280
|
+
}
|
|
2281
|
+
const listeners = getListeners(this);
|
|
2282
|
+
|
|
2283
|
+
// Traverse to the tail while removing old value.
|
|
2284
|
+
let prev = null;
|
|
2285
|
+
let node = listeners.get(eventName);
|
|
2286
|
+
while (node != null) {
|
|
2287
|
+
if (node.listenerType === ATTRIBUTE) {
|
|
2288
|
+
// Remove old value.
|
|
2289
|
+
if (prev !== null) {
|
|
2290
|
+
prev.next = node.next;
|
|
2291
|
+
} else if (node.next !== null) {
|
|
2292
|
+
listeners.set(eventName, node.next);
|
|
2293
|
+
} else {
|
|
2294
|
+
listeners.delete(eventName);
|
|
2295
|
+
}
|
|
2296
|
+
} else {
|
|
2297
|
+
prev = node;
|
|
2298
|
+
}
|
|
2299
|
+
|
|
2300
|
+
node = node.next;
|
|
2301
|
+
}
|
|
2302
|
+
|
|
2303
|
+
// Add new value.
|
|
2304
|
+
if (listener !== null) {
|
|
2305
|
+
const newNode = {
|
|
2306
|
+
listener,
|
|
2307
|
+
listenerType: ATTRIBUTE,
|
|
2308
|
+
passive: false,
|
|
2309
|
+
once: false,
|
|
2310
|
+
next: null,
|
|
2311
|
+
};
|
|
2312
|
+
if (prev === null) {
|
|
2313
|
+
listeners.set(eventName, newNode);
|
|
2314
|
+
} else {
|
|
2315
|
+
prev.next = newNode;
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2318
|
+
},
|
|
2319
|
+
configurable: true,
|
|
2320
|
+
enumerable: true,
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
|
|
2324
|
+
/**
|
|
2325
|
+
* Define an event attribute (e.g. `eventTarget.onclick`).
|
|
2326
|
+
* @param {Object} eventTargetPrototype The event target prototype to define an event attrbite.
|
|
2327
|
+
* @param {string} eventName The event name to define.
|
|
2328
|
+
* @returns {void}
|
|
2329
|
+
*/
|
|
2330
|
+
function defineEventAttribute(eventTargetPrototype, eventName) {
|
|
2331
|
+
Object.defineProperty(
|
|
2332
|
+
eventTargetPrototype,
|
|
2333
|
+
`on${eventName}`,
|
|
2334
|
+
defineEventAttributeDescriptor(eventName)
|
|
2335
|
+
);
|
|
2336
|
+
}
|
|
2337
|
+
|
|
2338
|
+
/**
|
|
2339
|
+
* Define a custom EventTarget with event attributes.
|
|
2340
|
+
* @param {string[]} eventNames Event names for event attributes.
|
|
2341
|
+
* @returns {EventTarget} The custom EventTarget.
|
|
2342
|
+
* @private
|
|
2343
|
+
*/
|
|
2344
|
+
function defineCustomEventTarget(eventNames) {
|
|
2345
|
+
/** CustomEventTarget */
|
|
2346
|
+
function CustomEventTarget() {
|
|
2347
|
+
EventTarget.call(this);
|
|
2348
|
+
}
|
|
2349
|
+
|
|
2350
|
+
CustomEventTarget.prototype = Object.create(EventTarget.prototype, {
|
|
2351
|
+
constructor: {
|
|
2352
|
+
value: CustomEventTarget,
|
|
2353
|
+
configurable: true,
|
|
2354
|
+
writable: true,
|
|
2355
|
+
},
|
|
2356
|
+
});
|
|
2357
|
+
|
|
2358
|
+
for (let i = 0; i < eventNames.length; ++i) {
|
|
2359
|
+
defineEventAttribute(CustomEventTarget.prototype, eventNames[i]);
|
|
2360
|
+
}
|
|
2361
|
+
|
|
2362
|
+
return CustomEventTarget
|
|
2363
|
+
}
|
|
2364
|
+
|
|
2365
|
+
/**
|
|
2366
|
+
* EventTarget.
|
|
2367
|
+
*
|
|
2368
|
+
* - This is constructor if no arguments.
|
|
2369
|
+
* - This is a function which returns a CustomEventTarget constructor if there are arguments.
|
|
2370
|
+
*
|
|
2371
|
+
* For example:
|
|
2372
|
+
*
|
|
2373
|
+
* class A extends EventTarget {}
|
|
2374
|
+
* class B extends EventTarget("message") {}
|
|
2375
|
+
* class C extends EventTarget("message", "error") {}
|
|
2376
|
+
* class D extends EventTarget(["message", "error"]) {}
|
|
2377
|
+
*/
|
|
2378
|
+
function EventTarget() {
|
|
2379
|
+
/*eslint-disable consistent-return */
|
|
2380
|
+
if (this instanceof EventTarget) {
|
|
2381
|
+
listenersMap.set(this, new Map());
|
|
2382
|
+
return
|
|
2383
|
+
}
|
|
2384
|
+
if (arguments.length === 1 && Array.isArray(arguments[0])) {
|
|
2385
|
+
return defineCustomEventTarget(arguments[0])
|
|
2386
|
+
}
|
|
2387
|
+
if (arguments.length > 0) {
|
|
2388
|
+
const types = new Array(arguments.length);
|
|
2389
|
+
for (let i = 0; i < arguments.length; ++i) {
|
|
2390
|
+
types[i] = arguments[i];
|
|
2391
|
+
}
|
|
2392
|
+
return defineCustomEventTarget(types)
|
|
2393
|
+
}
|
|
2394
|
+
throw new TypeError("Cannot call a class as a function")
|
|
2395
|
+
/*eslint-enable consistent-return */
|
|
2396
|
+
}
|
|
2397
|
+
|
|
2398
|
+
// Should be enumerable, but class methods are not enumerable.
|
|
2399
|
+
EventTarget.prototype = {
|
|
2400
|
+
/**
|
|
2401
|
+
* Add a given listener to this event target.
|
|
2402
|
+
* @param {string} eventName The event name to add.
|
|
2403
|
+
* @param {Function} listener The listener to add.
|
|
2404
|
+
* @param {boolean|{capture?:boolean,passive?:boolean,once?:boolean}} [options] The options for this listener.
|
|
2405
|
+
* @returns {void}
|
|
2406
|
+
*/
|
|
2407
|
+
addEventListener(eventName, listener, options) {
|
|
2408
|
+
if (listener == null) {
|
|
2409
|
+
return
|
|
2410
|
+
}
|
|
2411
|
+
if (typeof listener !== "function" && !isObject(listener)) {
|
|
2412
|
+
throw new TypeError("'listener' should be a function or an object.")
|
|
2413
|
+
}
|
|
2414
|
+
|
|
2415
|
+
const listeners = getListeners(this);
|
|
2416
|
+
const optionsIsObj = isObject(options);
|
|
2417
|
+
const capture = optionsIsObj
|
|
2418
|
+
? Boolean(options.capture)
|
|
2419
|
+
: Boolean(options);
|
|
2420
|
+
const listenerType = capture ? CAPTURE : BUBBLE;
|
|
2421
|
+
const newNode = {
|
|
2422
|
+
listener,
|
|
2423
|
+
listenerType,
|
|
2424
|
+
passive: optionsIsObj && Boolean(options.passive),
|
|
2425
|
+
once: optionsIsObj && Boolean(options.once),
|
|
2426
|
+
next: null,
|
|
2427
|
+
};
|
|
2428
|
+
|
|
2429
|
+
// Set it as the first node if the first node is null.
|
|
2430
|
+
let node = listeners.get(eventName);
|
|
2431
|
+
if (node === undefined) {
|
|
2432
|
+
listeners.set(eventName, newNode);
|
|
2433
|
+
return
|
|
2434
|
+
}
|
|
2435
|
+
|
|
2436
|
+
// Traverse to the tail while checking duplication..
|
|
2437
|
+
let prev = null;
|
|
2438
|
+
while (node != null) {
|
|
2439
|
+
if (
|
|
2440
|
+
node.listener === listener &&
|
|
2441
|
+
node.listenerType === listenerType
|
|
2442
|
+
) {
|
|
2443
|
+
// Should ignore duplication.
|
|
2444
|
+
return
|
|
2445
|
+
}
|
|
2446
|
+
prev = node;
|
|
2447
|
+
node = node.next;
|
|
2448
|
+
}
|
|
2449
|
+
|
|
2450
|
+
// Add it.
|
|
2451
|
+
prev.next = newNode;
|
|
2452
|
+
},
|
|
2453
|
+
|
|
2454
|
+
/**
|
|
2455
|
+
* Remove a given listener from this event target.
|
|
2456
|
+
* @param {string} eventName The event name to remove.
|
|
2457
|
+
* @param {Function} listener The listener to remove.
|
|
2458
|
+
* @param {boolean|{capture?:boolean,passive?:boolean,once?:boolean}} [options] The options for this listener.
|
|
2459
|
+
* @returns {void}
|
|
2460
|
+
*/
|
|
2461
|
+
removeEventListener(eventName, listener, options) {
|
|
2462
|
+
if (listener == null) {
|
|
2463
|
+
return
|
|
2464
|
+
}
|
|
2465
|
+
|
|
2466
|
+
const listeners = getListeners(this);
|
|
2467
|
+
const capture = isObject(options)
|
|
2468
|
+
? Boolean(options.capture)
|
|
2469
|
+
: Boolean(options);
|
|
2470
|
+
const listenerType = capture ? CAPTURE : BUBBLE;
|
|
2471
|
+
|
|
2472
|
+
let prev = null;
|
|
2473
|
+
let node = listeners.get(eventName);
|
|
2474
|
+
while (node != null) {
|
|
2475
|
+
if (
|
|
2476
|
+
node.listener === listener &&
|
|
2477
|
+
node.listenerType === listenerType
|
|
2478
|
+
) {
|
|
2479
|
+
if (prev !== null) {
|
|
2480
|
+
prev.next = node.next;
|
|
2481
|
+
} else if (node.next !== null) {
|
|
2482
|
+
listeners.set(eventName, node.next);
|
|
2483
|
+
} else {
|
|
2484
|
+
listeners.delete(eventName);
|
|
2485
|
+
}
|
|
2486
|
+
return
|
|
2487
|
+
}
|
|
2488
|
+
|
|
2489
|
+
prev = node;
|
|
2490
|
+
node = node.next;
|
|
2491
|
+
}
|
|
2492
|
+
},
|
|
2493
|
+
|
|
2494
|
+
/**
|
|
2495
|
+
* Dispatch a given event.
|
|
2496
|
+
* @param {Event|{type:string}} event The event to dispatch.
|
|
2497
|
+
* @returns {boolean} `false` if canceled.
|
|
2498
|
+
*/
|
|
2499
|
+
dispatchEvent(event) {
|
|
2500
|
+
if (event == null || typeof event.type !== "string") {
|
|
2501
|
+
throw new TypeError('"event.type" should be a string.')
|
|
2502
|
+
}
|
|
2503
|
+
|
|
2504
|
+
// If listeners aren't registered, terminate.
|
|
2505
|
+
const listeners = getListeners(this);
|
|
2506
|
+
const eventName = event.type;
|
|
2507
|
+
let node = listeners.get(eventName);
|
|
2508
|
+
if (node == null) {
|
|
2509
|
+
return true
|
|
2510
|
+
}
|
|
2511
|
+
|
|
2512
|
+
// Since we cannot rewrite several properties, so wrap object.
|
|
2513
|
+
const wrappedEvent = wrapEvent(this, event);
|
|
2514
|
+
|
|
2515
|
+
// This doesn't process capturing phase and bubbling phase.
|
|
2516
|
+
// This isn't participating in a tree.
|
|
2517
|
+
let prev = null;
|
|
2518
|
+
while (node != null) {
|
|
2519
|
+
// Remove this listener if it's once
|
|
2520
|
+
if (node.once) {
|
|
2521
|
+
if (prev !== null) {
|
|
2522
|
+
prev.next = node.next;
|
|
2523
|
+
} else if (node.next !== null) {
|
|
2524
|
+
listeners.set(eventName, node.next);
|
|
2525
|
+
} else {
|
|
2526
|
+
listeners.delete(eventName);
|
|
2527
|
+
}
|
|
2528
|
+
} else {
|
|
2529
|
+
prev = node;
|
|
2530
|
+
}
|
|
2531
|
+
|
|
2532
|
+
// Call this listener
|
|
2533
|
+
setPassiveListener(
|
|
2534
|
+
wrappedEvent,
|
|
2535
|
+
node.passive ? node.listener : null
|
|
2536
|
+
);
|
|
2537
|
+
if (typeof node.listener === "function") {
|
|
2538
|
+
try {
|
|
2539
|
+
node.listener.call(this, wrappedEvent);
|
|
2540
|
+
} catch (err) {
|
|
2541
|
+
if (
|
|
2542
|
+
typeof console !== "undefined" &&
|
|
2543
|
+
typeof console.error === "function"
|
|
2544
|
+
) {
|
|
2545
|
+
console.error(err);
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2548
|
+
} else if (
|
|
2549
|
+
node.listenerType !== ATTRIBUTE &&
|
|
2550
|
+
typeof node.listener.handleEvent === "function"
|
|
2551
|
+
) {
|
|
2552
|
+
node.listener.handleEvent(wrappedEvent);
|
|
2553
|
+
}
|
|
2554
|
+
|
|
2555
|
+
// Break if `event.stopImmediatePropagation` was called.
|
|
2556
|
+
if (isStopped(wrappedEvent)) {
|
|
2557
|
+
break
|
|
2558
|
+
}
|
|
2559
|
+
|
|
2560
|
+
node = node.next;
|
|
2561
|
+
}
|
|
2562
|
+
setPassiveListener(wrappedEvent, null);
|
|
2563
|
+
setEventPhase(wrappedEvent, 0);
|
|
2564
|
+
setCurrentTarget(wrappedEvent, null);
|
|
2565
|
+
|
|
2566
|
+
return !wrappedEvent.defaultPrevented
|
|
2567
|
+
},
|
|
2568
|
+
};
|
|
2569
|
+
|
|
2570
|
+
// `constructor` is not enumerable.
|
|
2571
|
+
Object.defineProperty(EventTarget.prototype, "constructor", {
|
|
2572
|
+
value: EventTarget,
|
|
2573
|
+
configurable: true,
|
|
2574
|
+
writable: true,
|
|
2575
|
+
});
|
|
2576
|
+
|
|
2577
|
+
// Ensure `eventTarget instanceof window.EventTarget` is `true`.
|
|
2578
|
+
if (
|
|
2579
|
+
typeof window !== "undefined" &&
|
|
2580
|
+
typeof window.EventTarget !== "undefined"
|
|
2581
|
+
) {
|
|
2582
|
+
Object.setPrototypeOf(EventTarget.prototype, window.EventTarget.prototype);
|
|
2583
|
+
}
|
|
2584
|
+
|
|
2585
|
+
/**
|
|
2586
|
+
* @author Toru Nagashima <https://github.com/mysticatea>
|
|
2587
|
+
* See LICENSE file in root directory for full license.
|
|
2588
|
+
*/
|
|
2589
|
+
|
|
2590
|
+
/**
|
|
2591
|
+
* The signal class.
|
|
2592
|
+
* @see https://dom.spec.whatwg.org/#abortsignal
|
|
2593
|
+
*/
|
|
2594
|
+
class AbortSignal extends EventTarget {
|
|
2595
|
+
/**
|
|
2596
|
+
* AbortSignal cannot be constructed directly.
|
|
2597
|
+
*/
|
|
2598
|
+
constructor() {
|
|
2599
|
+
super();
|
|
2600
|
+
throw new TypeError("AbortSignal cannot be constructed directly");
|
|
2601
|
+
}
|
|
2602
|
+
/**
|
|
2603
|
+
* Returns `true` if this `AbortSignal`'s `AbortController` has signaled to abort, and `false` otherwise.
|
|
2604
|
+
*/
|
|
2605
|
+
get aborted() {
|
|
2606
|
+
const aborted = abortedFlags.get(this);
|
|
2607
|
+
if (typeof aborted !== "boolean") {
|
|
2608
|
+
throw new TypeError(`Expected 'this' to be an 'AbortSignal' object, but got ${this === null ? "null" : typeof this}`);
|
|
2609
|
+
}
|
|
2610
|
+
return aborted;
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2613
|
+
defineEventAttribute(AbortSignal.prototype, "abort");
|
|
2614
|
+
/**
|
|
2615
|
+
* Create an AbortSignal object.
|
|
2616
|
+
*/
|
|
2617
|
+
function createAbortSignal() {
|
|
2618
|
+
const signal = Object.create(AbortSignal.prototype);
|
|
2619
|
+
EventTarget.call(signal);
|
|
2620
|
+
abortedFlags.set(signal, false);
|
|
2621
|
+
return signal;
|
|
2622
|
+
}
|
|
2623
|
+
/**
|
|
2624
|
+
* Abort a given signal.
|
|
2625
|
+
*/
|
|
2626
|
+
function abortSignal(signal) {
|
|
2627
|
+
if (abortedFlags.get(signal) !== false) {
|
|
2628
|
+
return;
|
|
2629
|
+
}
|
|
2630
|
+
abortedFlags.set(signal, true);
|
|
2631
|
+
signal.dispatchEvent({ type: "abort" });
|
|
2632
|
+
}
|
|
2633
|
+
/**
|
|
2634
|
+
* Aborted flag for each instances.
|
|
2635
|
+
*/
|
|
2636
|
+
const abortedFlags = new WeakMap();
|
|
2637
|
+
// Properties should be enumerable.
|
|
2638
|
+
Object.defineProperties(AbortSignal.prototype, {
|
|
2639
|
+
aborted: { enumerable: true },
|
|
2640
|
+
});
|
|
2641
|
+
// `toString()` should return `"[object AbortSignal]"`
|
|
2642
|
+
if (typeof Symbol === "function" && typeof Symbol.toStringTag === "symbol") {
|
|
2643
|
+
Object.defineProperty(AbortSignal.prototype, Symbol.toStringTag, {
|
|
2644
|
+
configurable: true,
|
|
2645
|
+
value: "AbortSignal",
|
|
2646
|
+
});
|
|
2647
|
+
}
|
|
2648
|
+
|
|
2649
|
+
/**
|
|
2650
|
+
* The AbortController.
|
|
2651
|
+
* @see https://dom.spec.whatwg.org/#abortcontroller
|
|
2652
|
+
*/
|
|
2653
|
+
let AbortController$1 = class AbortController {
|
|
2654
|
+
/**
|
|
2655
|
+
* Initialize this controller.
|
|
2656
|
+
*/
|
|
2657
|
+
constructor() {
|
|
2658
|
+
signals.set(this, createAbortSignal());
|
|
2659
|
+
}
|
|
2660
|
+
/**
|
|
2661
|
+
* Returns the `AbortSignal` object associated with this object.
|
|
2662
|
+
*/
|
|
2663
|
+
get signal() {
|
|
2664
|
+
return getSignal(this);
|
|
2665
|
+
}
|
|
2666
|
+
/**
|
|
2667
|
+
* Abort and signal to any observers that the associated activity is to be aborted.
|
|
2668
|
+
*/
|
|
2669
|
+
abort() {
|
|
2670
|
+
abortSignal(getSignal(this));
|
|
2671
|
+
}
|
|
2672
|
+
};
|
|
2673
|
+
/**
|
|
2674
|
+
* Associated signals.
|
|
2675
|
+
*/
|
|
2676
|
+
const signals = new WeakMap();
|
|
2677
|
+
/**
|
|
2678
|
+
* Get the associated signal of a given controller.
|
|
2679
|
+
*/
|
|
2680
|
+
function getSignal(controller) {
|
|
2681
|
+
const signal = signals.get(controller);
|
|
2682
|
+
if (signal == null) {
|
|
2683
|
+
throw new TypeError(`Expected 'this' to be an 'AbortController' object, but got ${controller === null ? "null" : typeof controller}`);
|
|
2684
|
+
}
|
|
2685
|
+
return signal;
|
|
2686
|
+
}
|
|
2687
|
+
// Properties should be enumerable.
|
|
2688
|
+
Object.defineProperties(AbortController$1.prototype, {
|
|
2689
|
+
signal: { enumerable: true },
|
|
2690
|
+
abort: { enumerable: true },
|
|
2691
|
+
});
|
|
2692
|
+
if (typeof Symbol === "function" && typeof Symbol.toStringTag === "symbol") {
|
|
2693
|
+
Object.defineProperty(AbortController$1.prototype, Symbol.toStringTag, {
|
|
2694
|
+
configurable: true,
|
|
2695
|
+
value: "AbortController",
|
|
2696
|
+
});
|
|
2697
|
+
}
|
|
2698
|
+
|
|
2699
|
+
/******************************************************************************
|
|
2700
|
+
Copyright (c) Microsoft Corporation.
|
|
2701
|
+
|
|
2702
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
2703
|
+
purpose with or without fee is hereby granted.
|
|
2704
|
+
|
|
2705
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
2706
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
2707
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
2708
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
2709
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
2710
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
2711
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
2712
|
+
***************************************************************************** */
|
|
2713
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
2714
|
+
|
|
2715
|
+
var extendStatics = function(d, b) {
|
|
2716
|
+
extendStatics = Object.setPrototypeOf ||
|
|
2717
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
2718
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
2719
|
+
return extendStatics(d, b);
|
|
2720
|
+
};
|
|
2721
|
+
|
|
2722
|
+
function __extends(d, b) {
|
|
2723
|
+
if (typeof b !== "function" && b !== null)
|
|
2724
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
2725
|
+
extendStatics(d, b);
|
|
2726
|
+
function __() { this.constructor = d; }
|
|
2727
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
2728
|
+
}
|
|
2729
|
+
|
|
2730
|
+
var __assign = function() {
|
|
2731
|
+
__assign = Object.assign || function __assign(t) {
|
|
2732
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
2733
|
+
s = arguments[i];
|
|
2734
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
2735
|
+
}
|
|
2736
|
+
return t;
|
|
2737
|
+
};
|
|
2738
|
+
return __assign.apply(this, arguments);
|
|
2739
|
+
};
|
|
2740
|
+
|
|
2741
|
+
function __rest(s, e) {
|
|
2742
|
+
var t = {};
|
|
2743
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
2744
|
+
t[p] = s[p];
|
|
2745
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
2746
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
2747
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
2748
|
+
t[p[i]] = s[p[i]];
|
|
2749
|
+
}
|
|
2750
|
+
return t;
|
|
2751
|
+
}
|
|
2752
|
+
|
|
2753
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
2754
|
+
var e = new Error(message);
|
|
2755
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
2756
|
+
};
|
|
2757
|
+
|
|
2758
|
+
var CustomAbortController;
|
|
2759
|
+
var httpRequest;
|
|
2760
|
+
var httpsRequest;
|
|
2761
|
+
var parse;
|
|
2762
|
+
var hasAbort = typeof AbortController !== "undefined";
|
|
2763
|
+
if (typeof window !== 'undefined' || hasAbort) {
|
|
2764
|
+
CustomAbortController = globalThis.AbortController;
|
|
2765
|
+
}
|
|
2766
|
+
else if (typeof require !== "undefined") {
|
|
2767
|
+
httpRequest = require("http").request;
|
|
2768
|
+
httpsRequest = require("https").request;
|
|
2769
|
+
parse = require("url").parse;
|
|
2770
|
+
CustomAbortController = require('abort-controller');
|
|
2771
|
+
}
|
|
2772
|
+
else if (typeof globalThis === "object") {
|
|
2773
|
+
httpRequest = http.request;
|
|
2774
|
+
httpsRequest = https.request;
|
|
2775
|
+
parse = url.parse;
|
|
2776
|
+
CustomAbortController = AbortController$1;
|
|
2777
|
+
}
|
|
2778
|
+
else {
|
|
2779
|
+
CustomAbortController = function () {
|
|
2780
|
+
throw new Error('AbortController is not defined');
|
|
2781
|
+
};
|
|
2782
|
+
}
|
|
2783
|
+
|
|
2784
|
+
var Interceptors = (function () {
|
|
2785
|
+
function Interceptors() {
|
|
2786
|
+
}
|
|
2787
|
+
Interceptors.prototype.use = function (type, fn) {
|
|
2788
|
+
switch (type) {
|
|
2789
|
+
case "request":
|
|
2790
|
+
this.requestSuccess = fn;
|
|
2791
|
+
break;
|
|
2792
|
+
case "response":
|
|
2793
|
+
this.responseSuccess = fn;
|
|
2794
|
+
break;
|
|
2795
|
+
case "error":
|
|
2796
|
+
this.error = fn;
|
|
2797
|
+
break;
|
|
2798
|
+
}
|
|
2799
|
+
return this;
|
|
2800
|
+
};
|
|
2801
|
+
Object.defineProperty(Interceptors.prototype, "reqFn", {
|
|
2802
|
+
get: function () {
|
|
2803
|
+
return this.requestSuccess;
|
|
2804
|
+
},
|
|
2805
|
+
enumerable: false,
|
|
2806
|
+
configurable: true
|
|
2807
|
+
});
|
|
2808
|
+
Object.defineProperty(Interceptors.prototype, "resFn", {
|
|
2809
|
+
get: function () {
|
|
2810
|
+
return this.responseSuccess;
|
|
2811
|
+
},
|
|
2812
|
+
enumerable: false,
|
|
2813
|
+
configurable: true
|
|
2814
|
+
});
|
|
2815
|
+
Object.defineProperty(Interceptors.prototype, "errFn", {
|
|
2816
|
+
get: function () {
|
|
2817
|
+
return this.error;
|
|
2818
|
+
},
|
|
2819
|
+
enumerable: false,
|
|
2820
|
+
configurable: true
|
|
2821
|
+
});
|
|
2822
|
+
return Interceptors;
|
|
2823
|
+
}());
|
|
2824
|
+
var RequestBase = (function (_super) {
|
|
2825
|
+
__extends(RequestBase, _super);
|
|
2826
|
+
function RequestBase(origin) {
|
|
2827
|
+
var _this = _super.call(this) || this;
|
|
2828
|
+
_this.chackUrl = function (url) {
|
|
2829
|
+
return url.startsWith('/');
|
|
2830
|
+
};
|
|
2831
|
+
_this.checkIsHttps = function (url) {
|
|
2832
|
+
return url.startsWith('https');
|
|
2833
|
+
};
|
|
2834
|
+
_this.fixOrigin = function (fixStr) {
|
|
2835
|
+
if (_this.chackUrl(fixStr))
|
|
2836
|
+
return _this.origin + fixStr;
|
|
2837
|
+
return fixStr;
|
|
2838
|
+
};
|
|
2839
|
+
_this.envDesc = function () {
|
|
2840
|
+
if (typeof Window !== "undefined") {
|
|
2841
|
+
return "Window";
|
|
2842
|
+
}
|
|
2843
|
+
return "Node";
|
|
2844
|
+
};
|
|
2845
|
+
_this.errorFn = function (reject) { return function (err) { var _a, _b; return reject((_b = (_a = _this.errFn) === null || _a === void 0 ? void 0 : _a.call(_this, err)) !== null && _b !== void 0 ? _b : err); }; };
|
|
2846
|
+
_this.clearTimer = function (opts) { return !!opts.timer && (clearTimeout(opts.timer), opts.timer = null); };
|
|
2847
|
+
_this.initAbort = function (params) {
|
|
2848
|
+
var controller = params.controller, timer = params.timer, timeout = params.timeout;
|
|
2849
|
+
!timer && (params.timer = setTimeout(function () { return controller.abort(); }, timeout));
|
|
2850
|
+
return params;
|
|
2851
|
+
};
|
|
2852
|
+
_this.requestType = function () {
|
|
2853
|
+
switch (_this.envDesc()) {
|
|
2854
|
+
case "Window":
|
|
2855
|
+
return _this.fetch;
|
|
2856
|
+
case "Node":
|
|
2857
|
+
return _this.http;
|
|
2858
|
+
}
|
|
2859
|
+
};
|
|
2860
|
+
_this.getDataByType = function (type, response) {
|
|
2861
|
+
switch (type) {
|
|
2862
|
+
case "text":
|
|
2863
|
+
case "json":
|
|
2864
|
+
case "blob":
|
|
2865
|
+
case "formData":
|
|
2866
|
+
case "arrayBuffer":
|
|
2867
|
+
return response[type]();
|
|
2868
|
+
default:
|
|
2869
|
+
return response['json']();
|
|
2870
|
+
}
|
|
2871
|
+
};
|
|
2872
|
+
_this.formatBodyString = function (bodyString) {
|
|
2873
|
+
return {
|
|
2874
|
+
text: function () { return bodyString; },
|
|
2875
|
+
json: function () { var _a; return (_a = stringToJson(bodyString)) !== null && _a !== void 0 ? _a : bodyString; },
|
|
2876
|
+
blob: function () { return stringToJson(bodyString); },
|
|
2877
|
+
formData: function () { return stringToJson(bodyString); },
|
|
2878
|
+
arrayBuffer: function () { return stringToJson(bodyString); },
|
|
2879
|
+
};
|
|
2880
|
+
};
|
|
2881
|
+
_this.origin = origin !== null && origin !== void 0 ? origin : '';
|
|
2882
|
+
return _this;
|
|
2883
|
+
}
|
|
2884
|
+
return RequestBase;
|
|
2885
|
+
}(Interceptors));
|
|
2886
|
+
var RequestInit = (function (_super) {
|
|
2887
|
+
__extends(RequestInit, _super);
|
|
2888
|
+
function RequestInit(origin) {
|
|
2889
|
+
var _this = _super.call(this, origin) || this;
|
|
2890
|
+
_this.initDefaultParams = function (url, _a) {
|
|
2891
|
+
var _b, _c;
|
|
2892
|
+
var _d = _a.method, method = _d === void 0 ? "GET" : _d, _e = _a.query, query = _e === void 0 ? {} : _e, _f = _a.headers, headers = _f === void 0 ? {} : _f, _g = _a.body, body = _g === void 0 ? null : _g, _h = _a.timeout, timeout = _h === void 0 ? 30 * 1000 : _h, _j = _a.controller, controller = _j === void 0 ? new CustomAbortController() : _j, _k = _a.type, type = _k === void 0 ? "json" : _k, others = __rest(_a, ["method", "query", "headers", "body", "timeout", "controller", "type"]);
|
|
2893
|
+
var __params = __assign({ url: url, method: method, query: query, headers: headers, body: method === "GET" ? null : jsonToString(body), timeout: timeout, signal: controller === null || controller === void 0 ? void 0 : controller.signal, controller: controller, type: type, timer: null }, others);
|
|
2894
|
+
var params = (_c = (_b = _this.reqFn) === null || _b === void 0 ? void 0 : _b.call(_this, __params)) !== null && _c !== void 0 ? _c : __params;
|
|
2895
|
+
params.url = urlJoin(_this.fixOrigin(url), __params.query);
|
|
2896
|
+
return params;
|
|
2897
|
+
};
|
|
2898
|
+
_this.initFetchParams = function (url, opts) {
|
|
2899
|
+
var _temp = _this.initAbort(_this.initDefaultParams(url, opts));
|
|
2900
|
+
return _temp;
|
|
2901
|
+
};
|
|
2902
|
+
_this.initHttpParams = function (url, opts) {
|
|
2903
|
+
var _temp = _this.initAbort(_this.initDefaultParams(url, opts));
|
|
2904
|
+
var options = parse(_temp.url, true);
|
|
2905
|
+
return __assign(__assign({}, _temp), options);
|
|
2906
|
+
};
|
|
2907
|
+
return _this;
|
|
2908
|
+
}
|
|
2909
|
+
return RequestInit;
|
|
2910
|
+
}(RequestBase));
|
|
2911
|
+
var Request = (function (_super) {
|
|
2912
|
+
__extends(Request, _super);
|
|
2913
|
+
function Request(origin) {
|
|
2914
|
+
var _this = _super.call(this, origin) || this;
|
|
2915
|
+
_this.fetch = function (_url, _opts) {
|
|
2916
|
+
var _a = defer(), promise = _a.promise, resolve = _a.resolve, reject = _a.reject;
|
|
2917
|
+
var _b = _this.initFetchParams(_url, _opts), url = _b.url, opts = __rest(_b, ["url"]);
|
|
2918
|
+
var signal = opts.signal;
|
|
2919
|
+
promise.finally(function () { return _this.clearTimer(opts); });
|
|
2920
|
+
signal.addEventListener('abort', function () { return _this.errorFn(reject); });
|
|
2921
|
+
fetch(url, opts).then(function (response) {
|
|
2922
|
+
if ((response === null || response === void 0 ? void 0 : response.status) >= 200 && (response === null || response === void 0 ? void 0 : response.status) < 300) {
|
|
2923
|
+
return _this.getDataByType(opts.type, response);
|
|
2924
|
+
}
|
|
2925
|
+
return _this.errorFn(reject);
|
|
2926
|
+
}).then(function (res) { var _a, _b; return resolve((_b = (_a = _this.resFn) === null || _a === void 0 ? void 0 : _a.call(_this, res)) !== null && _b !== void 0 ? _b : res); }).catch(_this.errorFn(reject));
|
|
2927
|
+
return promise;
|
|
2928
|
+
};
|
|
2929
|
+
_this.http = function (_url, _opts) {
|
|
2930
|
+
var _a = defer(), promise = _a.promise, resolve = _a.resolve, reject = _a.reject;
|
|
2931
|
+
var params = _this.initHttpParams(_url, _opts);
|
|
2932
|
+
var signal = params.signal, url = params.url, body = params.body;
|
|
2933
|
+
promise.finally(function () { return _this.clearTimer(params); });
|
|
2934
|
+
var request = _this.checkIsHttps(url) ? httpsRequest : httpRequest;
|
|
2935
|
+
var req = request(params, function (response) {
|
|
2936
|
+
var statusCode = response.statusCode, statusMessage = response.statusMessage;
|
|
2937
|
+
var data = "";
|
|
2938
|
+
response.setEncoding('utf8');
|
|
2939
|
+
response.on('data', function (chunk) { return data += chunk; });
|
|
2940
|
+
return response.on("end", function () {
|
|
2941
|
+
var _a, _b;
|
|
2942
|
+
var result = _this.getDataByType(params.type, _this.formatBodyString(data));
|
|
2943
|
+
if (statusCode >= 200 && statusCode < 300) {
|
|
2944
|
+
return resolve((_b = (_a = _this.resFn) === null || _a === void 0 ? void 0 : _a.call(_this, result)) !== null && _b !== void 0 ? _b : result);
|
|
2945
|
+
}
|
|
2946
|
+
return _this.errorFn(reject)({ statusCode: statusCode, statusMessage: statusMessage, result: result, data: data });
|
|
2947
|
+
});
|
|
2948
|
+
});
|
|
2949
|
+
signal.addEventListener('abort', function () { return _this.errorFn(reject)(req.destroy(new Error('request timeout'))); });
|
|
2950
|
+
body && req.write(body);
|
|
2951
|
+
req.on('error', _this.errorFn(reject));
|
|
2952
|
+
req.end();
|
|
2953
|
+
return promise;
|
|
2954
|
+
};
|
|
2955
|
+
_this.GET = function (url, query, _, opts) { return _this.request(url, __assign({ query: query, method: "GET" }, opts)); };
|
|
2956
|
+
_this.POST = function (url, query, body, opts) { return _this.request(url, __assign({ query: query, method: "POST", body: body }, opts)); };
|
|
2957
|
+
_this.PUT = function (url, query, body, opts) { return _this.request(url, __assign({ query: query, method: "PUT", body: body }, opts)); };
|
|
2958
|
+
_this.DELETE = function (url, query, body, opts) { return _this.request(url, __assign({ query: query, method: "DELETE", body: body }, opts)); };
|
|
2959
|
+
_this.OPTIONS = function (url, query, body, opts) { return _this.request(url, __assign({ query: query, method: "OPTIONS", body: body }, opts)); };
|
|
2960
|
+
_this.HEAD = function (url, query, body, opts) { return _this.request(url, __assign({ query: query, method: "HEAD", body: body }, opts)); };
|
|
2961
|
+
_this.PATCH = function (url, query, body, opts) { return _this.request(url, __assign({ query: query, method: "PATCH", body: body }, opts)); };
|
|
2962
|
+
_this.request = _this.requestType();
|
|
2963
|
+
return _this;
|
|
2964
|
+
}
|
|
2965
|
+
return Request;
|
|
2966
|
+
}(RequestInit));
|
|
2967
|
+
|
|
2968
|
+
var index = __assign$4(__assign$4(__assign$4(__assign$4(__assign$4(__assign$4(__assign$4(__assign$4(__assign$4(__assign$4(__assign$4({}, object$1), base$1), array$1), __function$1), element$1), __static$1), event$1), storage$1), log$1), animate$1), { eventMessageCenter: MessageCenter$1, taskQueueLib: TaskQueue$1, JSRequest: Request });
|
|
2969
|
+
|
|
2970
|
+
exports.AnimateFrame = AnimateFrame$1;
|
|
2971
|
+
exports.MessageCenter = MessageCenter$1;
|
|
2972
|
+
exports.NBezier = NBezier$1;
|
|
2973
|
+
exports.Request = Request;
|
|
2974
|
+
exports.TaskQueue = TaskQueue$1;
|
|
2975
|
+
exports.addHandler = addHandler$1;
|
|
2976
|
+
exports.arrayDemote = arrayDemote$1;
|
|
2977
|
+
exports.arrayRandom = arrayRandom$1;
|
|
2978
|
+
exports.arrayUniq = arrayUniq$1;
|
|
2979
|
+
exports.catchAwait = catchAwait$1;
|
|
2980
|
+
exports.classDecorator = classDecorator$1;
|
|
2981
|
+
exports.clearStorage = clearStorage$1;
|
|
2982
|
+
exports.cloneDeep = cloneDeep$1;
|
|
2983
|
+
exports.combination = combination$1;
|
|
2984
|
+
exports.createElement = createElement$1;
|
|
2985
|
+
exports.createObject = createObject$1;
|
|
2986
|
+
exports.createObjectVariable = createObjectVariable$1;
|
|
2987
|
+
exports.cubicBezier = cubicBezier$1;
|
|
2988
|
+
exports.debounce = debounce$1;
|
|
2989
|
+
exports.decoratorMessageCenter = decoratorMessageCenter$1;
|
|
2990
|
+
exports.decoratorTaskQueue = decoratorTaskQueue;
|
|
2991
|
+
exports.default = index;
|
|
2992
|
+
exports.defer = defer$1;
|
|
2993
|
+
exports.dispatchEvent = dispatchEvent$1;
|
|
2994
|
+
exports.enumInversion = enumInversion$1;
|
|
2995
|
+
exports.factorial = factorial$1;
|
|
2996
|
+
exports.getInstance = getInstance$1;
|
|
2997
|
+
exports.getStorage = getStorage$1;
|
|
2998
|
+
exports.getType = getType$1;
|
|
2999
|
+
exports.getTypeByList = getTypeByList$1;
|
|
3000
|
+
exports.getValue = getValue$1;
|
|
3001
|
+
exports.inherit = inherit$1;
|
|
3002
|
+
exports.isNotObject = isNotObject$1;
|
|
3003
|
+
exports.isWindow = isWindow$1;
|
|
3004
|
+
exports.jsonToString = jsonToString$1;
|
|
3005
|
+
exports.logLoop = logLoop$1;
|
|
3006
|
+
exports.logOneLine = logOneLine$1;
|
|
3007
|
+
exports.messageCenter = messageCenter;
|
|
3008
|
+
exports.mixIn = mixIn$1;
|
|
3009
|
+
exports.quadraticBezier = quadraticBezier$1;
|
|
3010
|
+
exports.randomNum = randomNum$1;
|
|
3011
|
+
exports.removeHandler = removeHandler$1;
|
|
3012
|
+
exports.setStorage = setStorage$1;
|
|
3013
|
+
exports.setValue = setValue$1;
|
|
3014
|
+
exports.stopBubble = stopBubble$1;
|
|
3015
|
+
exports.stopDefault = stopDefault$1;
|
|
3016
|
+
exports.stringToJson = stringToJson$1;
|
|
3017
|
+
exports.throttle = throttle$1;
|
|
3018
|
+
exports.urlJoin = urlJoin$1;
|
|
3019
|
+
exports.urlSplit = urlSplit$1;
|
|
3020
|
+
|
|
3021
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3022
|
+
|
|
3023
|
+
}));
|