@eva/eva.js 2.0.0-beta.8 → 2.0.0
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/EVA.js +48 -1089
- package/dist/EVA.min.js +1 -1
- package/dist/eva.js.cjs.js +40 -23
- package/dist/eva.js.cjs.prod.js +2 -2
- package/dist/eva.js.d.ts +1 -24
- package/dist/eva.js.esm.js +41 -23
- package/package.json +1 -1
package/dist/EVA.js
CHANGED
|
@@ -1889,7 +1889,7 @@ var _EVA_IIFE_EVA = function (exports, pixi_js) {
|
|
|
1889
1889
|
needScene = true
|
|
1890
1890
|
} = {}) {
|
|
1891
1891
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1892
|
-
if (window.__EVA_INSPECTOR_ENV__) {
|
|
1892
|
+
if (typeof window !== 'undefined' && window.__EVA_INSPECTOR_ENV__) {
|
|
1893
1893
|
window.__EVA_GAME_INSTANCE__ = this;
|
|
1894
1894
|
}
|
|
1895
1895
|
this.ticker = new Ticker$1({
|
|
@@ -2136,1085 +2136,6 @@ var _EVA_IIFE_EVA = function (exports, pixi_js) {
|
|
|
2136
2136
|
}
|
|
2137
2137
|
}
|
|
2138
2138
|
}
|
|
2139
|
-
var SignalBindingImpl = function () {
|
|
2140
|
-
function SignalBindingImpl(fn, once, thisArg) {
|
|
2141
|
-
if (once === void 0) {
|
|
2142
|
-
once = false;
|
|
2143
|
-
}
|
|
2144
|
-
this.next = null;
|
|
2145
|
-
this.prev = null;
|
|
2146
|
-
this.owner = null;
|
|
2147
|
-
this.fn = fn;
|
|
2148
|
-
this.once = once;
|
|
2149
|
-
this.thisArg = thisArg;
|
|
2150
|
-
}
|
|
2151
|
-
SignalBindingImpl.prototype.detach = function () {
|
|
2152
|
-
if (this.owner === null) return false;
|
|
2153
|
-
this.owner.detach(this);
|
|
2154
|
-
return true;
|
|
2155
|
-
};
|
|
2156
|
-
SignalBindingImpl.prototype.dispose = function () {
|
|
2157
|
-
this.detach();
|
|
2158
|
-
};
|
|
2159
|
-
return SignalBindingImpl;
|
|
2160
|
-
}();
|
|
2161
|
-
var Signal = function () {
|
|
2162
|
-
function Signal() {
|
|
2163
|
-
this._head = null;
|
|
2164
|
-
this._tail = null;
|
|
2165
|
-
this._filter = null;
|
|
2166
|
-
}
|
|
2167
|
-
Signal.prototype.handlers = function () {
|
|
2168
|
-
var node = this._head;
|
|
2169
|
-
var handlers = [];
|
|
2170
|
-
while (node) {
|
|
2171
|
-
handlers.push(node);
|
|
2172
|
-
node = node.next;
|
|
2173
|
-
}
|
|
2174
|
-
return handlers;
|
|
2175
|
-
};
|
|
2176
|
-
Signal.prototype.hasAny = function () {
|
|
2177
|
-
return !!this._head;
|
|
2178
|
-
};
|
|
2179
|
-
Signal.prototype.has = function (node) {
|
|
2180
|
-
return node.owner === this;
|
|
2181
|
-
};
|
|
2182
|
-
Signal.prototype.dispatch = function () {
|
|
2183
|
-
var args = [];
|
|
2184
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2185
|
-
args[_i] = arguments[_i];
|
|
2186
|
-
}
|
|
2187
|
-
var node = this._head;
|
|
2188
|
-
if (!node) return false;
|
|
2189
|
-
if (this._filter && !this._filter.apply(this, args)) return false;
|
|
2190
|
-
while (node) {
|
|
2191
|
-
if (node.once) this.detach(node);
|
|
2192
|
-
node.fn.apply(node.thisArg, args);
|
|
2193
|
-
node = node.next;
|
|
2194
|
-
}
|
|
2195
|
-
return true;
|
|
2196
|
-
};
|
|
2197
|
-
Signal.prototype.add = function (fn, thisArg) {
|
|
2198
|
-
if (thisArg === void 0) {
|
|
2199
|
-
thisArg = null;
|
|
2200
|
-
}
|
|
2201
|
-
return this._addSignalBinding(new SignalBindingImpl(fn, false, thisArg));
|
|
2202
|
-
};
|
|
2203
|
-
Signal.prototype.once = function (fn, thisArg) {
|
|
2204
|
-
if (thisArg === void 0) {
|
|
2205
|
-
thisArg = null;
|
|
2206
|
-
}
|
|
2207
|
-
return this._addSignalBinding(new SignalBindingImpl(fn, true, thisArg));
|
|
2208
|
-
};
|
|
2209
|
-
Signal.prototype.detach = function (node_) {
|
|
2210
|
-
var node = node_;
|
|
2211
|
-
if (node.owner !== this) return this;
|
|
2212
|
-
if (node.prev) node.prev.next = node.next;
|
|
2213
|
-
if (node.next) node.next.prev = node.prev;
|
|
2214
|
-
if (node === this._head) {
|
|
2215
|
-
this._head = node.next;
|
|
2216
|
-
if (node.next === null) {
|
|
2217
|
-
this._tail = null;
|
|
2218
|
-
}
|
|
2219
|
-
} else if (node === this._tail) {
|
|
2220
|
-
this._tail = node.prev;
|
|
2221
|
-
if (this._tail) this._tail.next = null;
|
|
2222
|
-
}
|
|
2223
|
-
node.owner = null;
|
|
2224
|
-
return this;
|
|
2225
|
-
};
|
|
2226
|
-
Signal.prototype.detachAll = function () {
|
|
2227
|
-
var node = this._head;
|
|
2228
|
-
if (!node) return this;
|
|
2229
|
-
this._head = null;
|
|
2230
|
-
this._tail = null;
|
|
2231
|
-
while (node) {
|
|
2232
|
-
node.owner = null;
|
|
2233
|
-
node = node.next;
|
|
2234
|
-
}
|
|
2235
|
-
return this;
|
|
2236
|
-
};
|
|
2237
|
-
Signal.prototype.filter = function (filter) {
|
|
2238
|
-
this._filter = filter;
|
|
2239
|
-
};
|
|
2240
|
-
Signal.prototype.proxy = function () {
|
|
2241
|
-
var _this = this;
|
|
2242
|
-
var signals = [];
|
|
2243
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2244
|
-
signals[_i] = arguments[_i];
|
|
2245
|
-
}
|
|
2246
|
-
var fn = function () {
|
|
2247
|
-
var args = [];
|
|
2248
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2249
|
-
args[_i] = arguments[_i];
|
|
2250
|
-
}
|
|
2251
|
-
return _this.dispatch.apply(_this, args);
|
|
2252
|
-
};
|
|
2253
|
-
for (var i = 0; i < signals.length; ++i) {
|
|
2254
|
-
signals[i].add(fn);
|
|
2255
|
-
}
|
|
2256
|
-
return this;
|
|
2257
|
-
};
|
|
2258
|
-
Signal.prototype._addSignalBinding = function (node_) {
|
|
2259
|
-
var node = node_;
|
|
2260
|
-
if (!this._head) {
|
|
2261
|
-
this._head = node;
|
|
2262
|
-
this._tail = node;
|
|
2263
|
-
} else {
|
|
2264
|
-
if (this._tail) this._tail.next = node;
|
|
2265
|
-
node.prev = this._tail;
|
|
2266
|
-
this._tail = node;
|
|
2267
|
-
}
|
|
2268
|
-
node.owner = this;
|
|
2269
|
-
return node;
|
|
2270
|
-
};
|
|
2271
|
-
return Signal;
|
|
2272
|
-
}();
|
|
2273
|
-
var src = (str, opts = {}) => {
|
|
2274
|
-
if (!str) return undefined;
|
|
2275
|
-
const o = {
|
|
2276
|
-
key: ['source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'],
|
|
2277
|
-
q: {
|
|
2278
|
-
name: 'queryKey',
|
|
2279
|
-
parser: /(?:^|&)([^&=]*)=?([^&]*)/g
|
|
2280
|
-
},
|
|
2281
|
-
parser: {
|
|
2282
|
-
strict: /^(?:([^:/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:/?#]*)(?::(\d*))?))?((((?:[^?#/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
|
|
2283
|
-
loose: /^(?:(?![^:@]+:[^:@/]*@)([^:/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#/]*\.[^?#/.]+(?:[?#]|$)))*\/?)?([^?#/]*))(?:\?([^#]*))?(?:#(.*))?)/
|
|
2284
|
-
}
|
|
2285
|
-
};
|
|
2286
|
-
const m = o.parser[opts.strictMode ? 'strict' : 'loose'].exec(str);
|
|
2287
|
-
const uri = {};
|
|
2288
|
-
let i = 14;
|
|
2289
|
-
while (i--) uri[o.key[i]] = m[i] || '';
|
|
2290
|
-
uri[o.q.name] = {};
|
|
2291
|
-
uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
|
|
2292
|
-
if ($1) uri[o.q.name][$1] = $2;
|
|
2293
|
-
});
|
|
2294
|
-
return uri;
|
|
2295
|
-
};
|
|
2296
|
-
var parseUri = src;
|
|
2297
|
-
var AbstractLoadStrategy = function () {
|
|
2298
|
-
function AbstractLoadStrategy(config) {
|
|
2299
|
-
this.config = config;
|
|
2300
|
-
this.onError = new Signal();
|
|
2301
|
-
this.onComplete = new Signal();
|
|
2302
|
-
this.onProgress = new Signal();
|
|
2303
|
-
}
|
|
2304
|
-
return AbstractLoadStrategy;
|
|
2305
|
-
}();
|
|
2306
|
-
var extendStatics = function (d, b) {
|
|
2307
|
-
extendStatics = Object.setPrototypeOf || {
|
|
2308
|
-
__proto__: []
|
|
2309
|
-
} instanceof Array && function (d, b) {
|
|
2310
|
-
d.__proto__ = b;
|
|
2311
|
-
} || function (d, b) {
|
|
2312
|
-
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
|
2313
|
-
};
|
|
2314
|
-
return extendStatics(d, b);
|
|
2315
|
-
};
|
|
2316
|
-
function __extends(d, b) {
|
|
2317
|
-
extendStatics(d, b);
|
|
2318
|
-
function __() {
|
|
2319
|
-
this.constructor = d;
|
|
2320
|
-
}
|
|
2321
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
2322
|
-
}
|
|
2323
|
-
function __spreadArrays() {
|
|
2324
|
-
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
2325
|
-
for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j];
|
|
2326
|
-
return r;
|
|
2327
|
-
}
|
|
2328
|
-
function getExtension(url) {
|
|
2329
|
-
var isDataUrl = url.indexOf('data:') === 0;
|
|
2330
|
-
var ext = '';
|
|
2331
|
-
if (isDataUrl) {
|
|
2332
|
-
var slashIndex = url.indexOf('/');
|
|
2333
|
-
ext = url.substring(slashIndex + 1, url.indexOf(';', slashIndex));
|
|
2334
|
-
} else {
|
|
2335
|
-
var queryStart = url.indexOf('?');
|
|
2336
|
-
var hashStart = url.indexOf('#');
|
|
2337
|
-
var index = Math.min(queryStart > -1 ? queryStart : url.length, hashStart > -1 ? hashStart : url.length);
|
|
2338
|
-
url = url.substring(0, index);
|
|
2339
|
-
ext = url.substring(url.lastIndexOf('.') + 1);
|
|
2340
|
-
}
|
|
2341
|
-
return ext.toLowerCase();
|
|
2342
|
-
}
|
|
2343
|
-
function assertNever(x) {
|
|
2344
|
-
throw new Error('Unexpected value. Should have been never.');
|
|
2345
|
-
}
|
|
2346
|
-
var ResourceType;
|
|
2347
|
-
(function (ResourceType) {
|
|
2348
|
-
ResourceType[ResourceType["Unknown"] = 0] = "Unknown";
|
|
2349
|
-
ResourceType[ResourceType["Buffer"] = 1] = "Buffer";
|
|
2350
|
-
ResourceType[ResourceType["Blob"] = 2] = "Blob";
|
|
2351
|
-
ResourceType[ResourceType["Json"] = 3] = "Json";
|
|
2352
|
-
ResourceType[ResourceType["Xml"] = 4] = "Xml";
|
|
2353
|
-
ResourceType[ResourceType["Image"] = 5] = "Image";
|
|
2354
|
-
ResourceType[ResourceType["Audio"] = 6] = "Audio";
|
|
2355
|
-
ResourceType[ResourceType["Video"] = 7] = "Video";
|
|
2356
|
-
ResourceType[ResourceType["Text"] = 8] = "Text";
|
|
2357
|
-
})(ResourceType || (ResourceType = {}));
|
|
2358
|
-
var ResourceState;
|
|
2359
|
-
(function (ResourceState) {
|
|
2360
|
-
ResourceState[ResourceState["NotStarted"] = 0] = "NotStarted";
|
|
2361
|
-
ResourceState[ResourceState["Loading"] = 1] = "Loading";
|
|
2362
|
-
ResourceState[ResourceState["Complete"] = 2] = "Complete";
|
|
2363
|
-
})(ResourceState || (ResourceState = {}));
|
|
2364
|
-
var MediaElementLoadStrategy = function (_super) {
|
|
2365
|
-
__extends(MediaElementLoadStrategy, _super);
|
|
2366
|
-
function MediaElementLoadStrategy(config, elementType) {
|
|
2367
|
-
var _this = _super.call(this, config) || this;
|
|
2368
|
-
_this.elementType = elementType;
|
|
2369
|
-
_this._boundOnLoad = _this._onLoad.bind(_this);
|
|
2370
|
-
_this._boundOnError = _this._onError.bind(_this);
|
|
2371
|
-
_this._boundOnTimeout = _this._onTimeout.bind(_this);
|
|
2372
|
-
_this._element = _this._createElement();
|
|
2373
|
-
_this._elementTimer = 0;
|
|
2374
|
-
return _this;
|
|
2375
|
-
}
|
|
2376
|
-
MediaElementLoadStrategy.prototype.load = function () {
|
|
2377
|
-
var config = this.config;
|
|
2378
|
-
if (config.crossOrigin) this._element.crossOrigin = config.crossOrigin;
|
|
2379
|
-
var urls = config.sourceSet || [config.url];
|
|
2380
|
-
if (navigator.isCocoonJS) {
|
|
2381
|
-
this._element.src = urls[0];
|
|
2382
|
-
} else {
|
|
2383
|
-
for (var i = 0; i < urls.length; ++i) {
|
|
2384
|
-
var url = urls[i];
|
|
2385
|
-
var mimeType = config.mimeTypes ? config.mimeTypes[i] : undefined;
|
|
2386
|
-
if (!mimeType) mimeType = this.elementType + "/" + getExtension(url);
|
|
2387
|
-
var source = document.createElement('source');
|
|
2388
|
-
source.src = url;
|
|
2389
|
-
source.type = mimeType;
|
|
2390
|
-
this._element.appendChild(source);
|
|
2391
|
-
}
|
|
2392
|
-
}
|
|
2393
|
-
this._element.addEventListener('load', this._boundOnLoad, false);
|
|
2394
|
-
this._element.addEventListener('canplaythrough', this._boundOnLoad, false);
|
|
2395
|
-
this._element.addEventListener('error', this._boundOnError, false);
|
|
2396
|
-
this._element.load();
|
|
2397
|
-
if (config.timeout) this._elementTimer = window.setTimeout(this._boundOnTimeout, config.timeout);
|
|
2398
|
-
};
|
|
2399
|
-
MediaElementLoadStrategy.prototype.abort = function () {
|
|
2400
|
-
this._clearEvents();
|
|
2401
|
-
while (this._element.firstChild) {
|
|
2402
|
-
this._element.removeChild(this._element.firstChild);
|
|
2403
|
-
}
|
|
2404
|
-
this._error(this.elementType + " load aborted by the user.");
|
|
2405
|
-
};
|
|
2406
|
-
MediaElementLoadStrategy.prototype._createElement = function () {
|
|
2407
|
-
if (this.config.loadElement) return this.config.loadElement;else return document.createElement(this.elementType);
|
|
2408
|
-
};
|
|
2409
|
-
MediaElementLoadStrategy.prototype._clearEvents = function () {
|
|
2410
|
-
clearTimeout(this._elementTimer);
|
|
2411
|
-
this._element.removeEventListener('load', this._boundOnLoad, false);
|
|
2412
|
-
this._element.removeEventListener('canplaythrough', this._boundOnLoad, false);
|
|
2413
|
-
this._element.removeEventListener('error', this._boundOnError, false);
|
|
2414
|
-
};
|
|
2415
|
-
MediaElementLoadStrategy.prototype._error = function (errMessage) {
|
|
2416
|
-
this._clearEvents();
|
|
2417
|
-
this.onError.dispatch(errMessage);
|
|
2418
|
-
};
|
|
2419
|
-
MediaElementLoadStrategy.prototype._complete = function () {
|
|
2420
|
-
this._clearEvents();
|
|
2421
|
-
var resourceType = ResourceType.Unknown;
|
|
2422
|
-
switch (this.elementType) {
|
|
2423
|
-
case 'audio':
|
|
2424
|
-
resourceType = ResourceType.Audio;
|
|
2425
|
-
break;
|
|
2426
|
-
case 'video':
|
|
2427
|
-
resourceType = ResourceType.Video;
|
|
2428
|
-
break;
|
|
2429
|
-
default:
|
|
2430
|
-
assertNever(this.elementType);
|
|
2431
|
-
}
|
|
2432
|
-
this.onComplete.dispatch(resourceType, this._element);
|
|
2433
|
-
};
|
|
2434
|
-
MediaElementLoadStrategy.prototype._onLoad = function () {
|
|
2435
|
-
this._complete();
|
|
2436
|
-
};
|
|
2437
|
-
MediaElementLoadStrategy.prototype._onError = function () {
|
|
2438
|
-
this._error(this.elementType + " failed to load.");
|
|
2439
|
-
};
|
|
2440
|
-
MediaElementLoadStrategy.prototype._onTimeout = function () {
|
|
2441
|
-
this._error(this.elementType + " load timed out.");
|
|
2442
|
-
};
|
|
2443
|
-
return MediaElementLoadStrategy;
|
|
2444
|
-
}(AbstractLoadStrategy);
|
|
2445
|
-
var AudioLoadStrategy = function (_super) {
|
|
2446
|
-
__extends(AudioLoadStrategy, _super);
|
|
2447
|
-
function AudioLoadStrategy(config) {
|
|
2448
|
-
return _super.call(this, config, 'audio') || this;
|
|
2449
|
-
}
|
|
2450
|
-
return AudioLoadStrategy;
|
|
2451
|
-
}(MediaElementLoadStrategy);
|
|
2452
|
-
var EMPTY_GIF = 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==';
|
|
2453
|
-
var ImageLoadStrategy = function (_super) {
|
|
2454
|
-
__extends(ImageLoadStrategy, _super);
|
|
2455
|
-
function ImageLoadStrategy() {
|
|
2456
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
2457
|
-
_this._boundOnLoad = _this._onLoad.bind(_this);
|
|
2458
|
-
_this._boundOnError = _this._onError.bind(_this);
|
|
2459
|
-
_this._boundOnTimeout = _this._onTimeout.bind(_this);
|
|
2460
|
-
_this._element = _this._createElement();
|
|
2461
|
-
_this._elementTimer = 0;
|
|
2462
|
-
return _this;
|
|
2463
|
-
}
|
|
2464
|
-
ImageLoadStrategy.prototype.load = function () {
|
|
2465
|
-
var config = this.config;
|
|
2466
|
-
if (config.crossOrigin) this._element.crossOrigin = config.crossOrigin;
|
|
2467
|
-
this._element.src = config.url;
|
|
2468
|
-
this._element.addEventListener('load', this._boundOnLoad, false);
|
|
2469
|
-
this._element.addEventListener('error', this._boundOnError, false);
|
|
2470
|
-
if (config.timeout) this._elementTimer = window.setTimeout(this._boundOnTimeout, config.timeout);
|
|
2471
|
-
};
|
|
2472
|
-
ImageLoadStrategy.prototype.abort = function () {
|
|
2473
|
-
this._clearEvents();
|
|
2474
|
-
this._element.src = EMPTY_GIF;
|
|
2475
|
-
this._error('Image load aborted by the user.');
|
|
2476
|
-
};
|
|
2477
|
-
ImageLoadStrategy.prototype._createElement = function () {
|
|
2478
|
-
if (this.config.loadElement) return this.config.loadElement;else return document.createElement('img');
|
|
2479
|
-
};
|
|
2480
|
-
ImageLoadStrategy.prototype._clearEvents = function () {
|
|
2481
|
-
clearTimeout(this._elementTimer);
|
|
2482
|
-
this._element.removeEventListener('load', this._boundOnLoad, false);
|
|
2483
|
-
this._element.removeEventListener('error', this._boundOnError, false);
|
|
2484
|
-
};
|
|
2485
|
-
ImageLoadStrategy.prototype._error = function (errMessage) {
|
|
2486
|
-
this._clearEvents();
|
|
2487
|
-
this.onError.dispatch(errMessage);
|
|
2488
|
-
};
|
|
2489
|
-
ImageLoadStrategy.prototype._complete = function () {
|
|
2490
|
-
this._clearEvents();
|
|
2491
|
-
this.onComplete.dispatch(ResourceType.Image, this._element);
|
|
2492
|
-
};
|
|
2493
|
-
ImageLoadStrategy.prototype._onLoad = function () {
|
|
2494
|
-
this._complete();
|
|
2495
|
-
};
|
|
2496
|
-
ImageLoadStrategy.prototype._onError = function () {
|
|
2497
|
-
this._error('Image failed to load.');
|
|
2498
|
-
};
|
|
2499
|
-
ImageLoadStrategy.prototype._onTimeout = function () {
|
|
2500
|
-
this._error('Image load timed out.');
|
|
2501
|
-
};
|
|
2502
|
-
return ImageLoadStrategy;
|
|
2503
|
-
}(AbstractLoadStrategy);
|
|
2504
|
-
var VideoLoadStrategy = function (_super) {
|
|
2505
|
-
__extends(VideoLoadStrategy, _super);
|
|
2506
|
-
function VideoLoadStrategy(config) {
|
|
2507
|
-
return _super.call(this, config, 'video') || this;
|
|
2508
|
-
}
|
|
2509
|
-
return VideoLoadStrategy;
|
|
2510
|
-
}(MediaElementLoadStrategy);
|
|
2511
|
-
var useXdr = !!(window.XDomainRequest && !('withCredentials' in new XMLHttpRequest()));
|
|
2512
|
-
var XhrResponseType;
|
|
2513
|
-
(function (XhrResponseType) {
|
|
2514
|
-
XhrResponseType["Default"] = "text";
|
|
2515
|
-
XhrResponseType["Buffer"] = "arraybuffer";
|
|
2516
|
-
XhrResponseType["Blob"] = "blob";
|
|
2517
|
-
XhrResponseType["Document"] = "document";
|
|
2518
|
-
XhrResponseType["Json"] = "json";
|
|
2519
|
-
XhrResponseType["Text"] = "text";
|
|
2520
|
-
})(XhrResponseType || (XhrResponseType = {}));
|
|
2521
|
-
function reqType(xhr) {
|
|
2522
|
-
return xhr.toString().replace('object ', '');
|
|
2523
|
-
}
|
|
2524
|
-
var XhrLoadStrategy = function (_super) {
|
|
2525
|
-
__extends(XhrLoadStrategy, _super);
|
|
2526
|
-
function XhrLoadStrategy() {
|
|
2527
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
2528
|
-
_this._boundOnLoad = _this._onLoad.bind(_this);
|
|
2529
|
-
_this._boundOnAbort = _this._onAbort.bind(_this);
|
|
2530
|
-
_this._boundOnError = _this._onError.bind(_this);
|
|
2531
|
-
_this._boundOnTimeout = _this._onTimeout.bind(_this);
|
|
2532
|
-
_this._boundOnProgress = _this._onProgress.bind(_this);
|
|
2533
|
-
_this._xhr = _this._createRequest();
|
|
2534
|
-
_this._xhrType = XhrResponseType.Default;
|
|
2535
|
-
return _this;
|
|
2536
|
-
}
|
|
2537
|
-
XhrLoadStrategy.prototype.load = function () {
|
|
2538
|
-
var config = this.config;
|
|
2539
|
-
var ext = getExtension(config.url);
|
|
2540
|
-
if (typeof config.xhrType !== 'string') {
|
|
2541
|
-
config.xhrType = this._determineXhrType(ext);
|
|
2542
|
-
}
|
|
2543
|
-
var xhr = this._xhr;
|
|
2544
|
-
this._xhrType = config.xhrType || XhrResponseType.Default;
|
|
2545
|
-
if (useXdr) {
|
|
2546
|
-
xhr.timeout = config.timeout || 5000;
|
|
2547
|
-
xhr.onload = this._boundOnLoad;
|
|
2548
|
-
xhr.onerror = this._boundOnError;
|
|
2549
|
-
xhr.ontimeout = this._boundOnTimeout;
|
|
2550
|
-
xhr.onprogress = this._boundOnProgress;
|
|
2551
|
-
xhr.open('GET', config.url, true);
|
|
2552
|
-
setTimeout(function () {
|
|
2553
|
-
xhr.send();
|
|
2554
|
-
}, 0);
|
|
2555
|
-
} else {
|
|
2556
|
-
xhr.open('GET', config.url, true);
|
|
2557
|
-
if (config.timeout) xhr.timeout = config.timeout;
|
|
2558
|
-
if (config.xhrType === XhrResponseType.Json || config.xhrType === XhrResponseType.Document) xhr.responseType = XhrResponseType.Text;else xhr.responseType = config.xhrType;
|
|
2559
|
-
xhr.addEventListener('load', this._boundOnLoad, false);
|
|
2560
|
-
xhr.addEventListener('abort', this._boundOnAbort, false);
|
|
2561
|
-
xhr.addEventListener('error', this._boundOnError, false);
|
|
2562
|
-
xhr.addEventListener('timeout', this._boundOnTimeout, false);
|
|
2563
|
-
xhr.addEventListener('progress', this._boundOnProgress, false);
|
|
2564
|
-
xhr.send();
|
|
2565
|
-
}
|
|
2566
|
-
};
|
|
2567
|
-
XhrLoadStrategy.prototype.abort = function () {
|
|
2568
|
-
if (useXdr) {
|
|
2569
|
-
this._clearEvents();
|
|
2570
|
-
this._xhr.abort();
|
|
2571
|
-
this._onAbort();
|
|
2572
|
-
} else {
|
|
2573
|
-
this._xhr.abort();
|
|
2574
|
-
}
|
|
2575
|
-
};
|
|
2576
|
-
XhrLoadStrategy.prototype._createRequest = function () {
|
|
2577
|
-
if (useXdr) return new window.XDomainRequest();else return new XMLHttpRequest();
|
|
2578
|
-
};
|
|
2579
|
-
XhrLoadStrategy.prototype._determineXhrType = function (ext) {
|
|
2580
|
-
return XhrLoadStrategy._xhrTypeMap[ext] || XhrResponseType.Default;
|
|
2581
|
-
};
|
|
2582
|
-
XhrLoadStrategy.prototype._clearEvents = function () {
|
|
2583
|
-
if (useXdr) {
|
|
2584
|
-
this._xhr.onload = null;
|
|
2585
|
-
this._xhr.onerror = null;
|
|
2586
|
-
this._xhr.ontimeout = null;
|
|
2587
|
-
this._xhr.onprogress = null;
|
|
2588
|
-
} else {
|
|
2589
|
-
this._xhr.removeEventListener('load', this._boundOnLoad, false);
|
|
2590
|
-
this._xhr.removeEventListener('abort', this._boundOnAbort, false);
|
|
2591
|
-
this._xhr.removeEventListener('error', this._boundOnError, false);
|
|
2592
|
-
this._xhr.removeEventListener('timeout', this._boundOnTimeout, false);
|
|
2593
|
-
this._xhr.removeEventListener('progress', this._boundOnProgress, false);
|
|
2594
|
-
}
|
|
2595
|
-
};
|
|
2596
|
-
XhrLoadStrategy.prototype._error = function (errMessage) {
|
|
2597
|
-
this._clearEvents();
|
|
2598
|
-
this.onError.dispatch(errMessage);
|
|
2599
|
-
};
|
|
2600
|
-
XhrLoadStrategy.prototype._complete = function (type, data) {
|
|
2601
|
-
this._clearEvents();
|
|
2602
|
-
this.onComplete.dispatch(type, data);
|
|
2603
|
-
};
|
|
2604
|
-
XhrLoadStrategy.prototype._onLoad = function () {
|
|
2605
|
-
var xhr = this._xhr;
|
|
2606
|
-
var text = '';
|
|
2607
|
-
var status = typeof xhr.status === 'undefined' ? 200 : xhr.status;
|
|
2608
|
-
if (typeof xhr.responseType === 'undefined' || xhr.responseType === '' || xhr.responseType === 'text') {
|
|
2609
|
-
text = xhr.responseText;
|
|
2610
|
-
}
|
|
2611
|
-
if (status === 0 && (text.length > 0 || xhr.responseType === XhrResponseType.Buffer)) {
|
|
2612
|
-
status = 200;
|
|
2613
|
-
} else if (status === 1223) {
|
|
2614
|
-
status = 204;
|
|
2615
|
-
}
|
|
2616
|
-
var flattenedStatus = Math.floor(status / 100) * 100;
|
|
2617
|
-
if (flattenedStatus !== 200) {
|
|
2618
|
-
this._error("[" + xhr.status + "] " + xhr.statusText + ": " + xhr.responseURL);
|
|
2619
|
-
return;
|
|
2620
|
-
}
|
|
2621
|
-
switch (this._xhrType) {
|
|
2622
|
-
case XhrResponseType.Buffer:
|
|
2623
|
-
this._complete(ResourceType.Buffer, xhr.response);
|
|
2624
|
-
break;
|
|
2625
|
-
case XhrResponseType.Blob:
|
|
2626
|
-
this._complete(ResourceType.Blob, xhr.response);
|
|
2627
|
-
break;
|
|
2628
|
-
case XhrResponseType.Document:
|
|
2629
|
-
this._parseDocument(text);
|
|
2630
|
-
break;
|
|
2631
|
-
case XhrResponseType.Json:
|
|
2632
|
-
this._parseJson(text);
|
|
2633
|
-
break;
|
|
2634
|
-
case XhrResponseType.Default:
|
|
2635
|
-
case XhrResponseType.Text:
|
|
2636
|
-
this._complete(ResourceType.Text, text);
|
|
2637
|
-
break;
|
|
2638
|
-
default:
|
|
2639
|
-
assertNever(this._xhrType);
|
|
2640
|
-
}
|
|
2641
|
-
};
|
|
2642
|
-
XhrLoadStrategy.prototype._parseDocument = function (text) {
|
|
2643
|
-
try {
|
|
2644
|
-
if (window.DOMParser) {
|
|
2645
|
-
var parser = new DOMParser();
|
|
2646
|
-
var data = parser.parseFromString(text, 'text/xml');
|
|
2647
|
-
this._complete(ResourceType.Xml, data);
|
|
2648
|
-
} else {
|
|
2649
|
-
var div = document.createElement('div');
|
|
2650
|
-
div.innerHTML = text;
|
|
2651
|
-
this._complete(ResourceType.Xml, div);
|
|
2652
|
-
}
|
|
2653
|
-
} catch (e) {
|
|
2654
|
-
this._error("Error trying to parse loaded xml: " + e);
|
|
2655
|
-
}
|
|
2656
|
-
};
|
|
2657
|
-
XhrLoadStrategy.prototype._parseJson = function (text) {
|
|
2658
|
-
try {
|
|
2659
|
-
var data = JSON.parse(text);
|
|
2660
|
-
this._complete(ResourceType.Json, data);
|
|
2661
|
-
} catch (e) {
|
|
2662
|
-
this._error("Error trying to parse loaded json: " + e);
|
|
2663
|
-
}
|
|
2664
|
-
};
|
|
2665
|
-
XhrLoadStrategy.prototype._onAbort = function () {
|
|
2666
|
-
var xhr = this._xhr;
|
|
2667
|
-
this._error(reqType(xhr) + " Request was aborted by the user.");
|
|
2668
|
-
};
|
|
2669
|
-
XhrLoadStrategy.prototype._onError = function () {
|
|
2670
|
-
var xhr = this._xhr;
|
|
2671
|
-
this._error(reqType(xhr) + " Request failed. Status: " + xhr.status + ", text: \"" + xhr.statusText + "\"");
|
|
2672
|
-
};
|
|
2673
|
-
XhrLoadStrategy.prototype._onTimeout = function () {
|
|
2674
|
-
var xhr = this._xhr;
|
|
2675
|
-
this._error(reqType(xhr) + " Request timed out.");
|
|
2676
|
-
};
|
|
2677
|
-
XhrLoadStrategy.prototype._onProgress = function (event) {
|
|
2678
|
-
if (event && event.lengthComputable) {
|
|
2679
|
-
this.onProgress.dispatch(event.loaded / event.total);
|
|
2680
|
-
}
|
|
2681
|
-
};
|
|
2682
|
-
XhrLoadStrategy.setExtensionXhrType = function (extname, xhrType) {
|
|
2683
|
-
if (extname && extname.indexOf('.') === 0) extname = extname.substring(1);
|
|
2684
|
-
if (!extname) return;
|
|
2685
|
-
XhrLoadStrategy._xhrTypeMap[extname] = xhrType;
|
|
2686
|
-
};
|
|
2687
|
-
XhrLoadStrategy.ResponseType = XhrResponseType;
|
|
2688
|
-
XhrLoadStrategy._xhrTypeMap = {
|
|
2689
|
-
xhtml: XhrResponseType.Document,
|
|
2690
|
-
html: XhrResponseType.Document,
|
|
2691
|
-
htm: XhrResponseType.Document,
|
|
2692
|
-
xml: XhrResponseType.Document,
|
|
2693
|
-
tmx: XhrResponseType.Document,
|
|
2694
|
-
svg: XhrResponseType.Document,
|
|
2695
|
-
tsx: XhrResponseType.Document,
|
|
2696
|
-
gif: XhrResponseType.Blob,
|
|
2697
|
-
png: XhrResponseType.Blob,
|
|
2698
|
-
bmp: XhrResponseType.Blob,
|
|
2699
|
-
jpg: XhrResponseType.Blob,
|
|
2700
|
-
jpeg: XhrResponseType.Blob,
|
|
2701
|
-
tif: XhrResponseType.Blob,
|
|
2702
|
-
tiff: XhrResponseType.Blob,
|
|
2703
|
-
webp: XhrResponseType.Blob,
|
|
2704
|
-
tga: XhrResponseType.Blob,
|
|
2705
|
-
json: XhrResponseType.Json,
|
|
2706
|
-
text: XhrResponseType.Text,
|
|
2707
|
-
txt: XhrResponseType.Text,
|
|
2708
|
-
ttf: XhrResponseType.Buffer,
|
|
2709
|
-
otf: XhrResponseType.Buffer
|
|
2710
|
-
};
|
|
2711
|
-
return XhrLoadStrategy;
|
|
2712
|
-
}(AbstractLoadStrategy);
|
|
2713
|
-
function onlyOnce(func) {
|
|
2714
|
-
var fn = func;
|
|
2715
|
-
return function onceWrapper() {
|
|
2716
|
-
var args = [];
|
|
2717
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2718
|
-
args[_i] = arguments[_i];
|
|
2719
|
-
}
|
|
2720
|
-
if (fn === null) throw new Error('Callback was already called.');
|
|
2721
|
-
var callFn = fn;
|
|
2722
|
-
fn = null;
|
|
2723
|
-
return callFn.apply(this, args);
|
|
2724
|
-
};
|
|
2725
|
-
}
|
|
2726
|
-
var AsyncQueue = function () {
|
|
2727
|
-
function AsyncQueue(worker, concurrency) {
|
|
2728
|
-
if (concurrency === void 0) {
|
|
2729
|
-
concurrency = 1;
|
|
2730
|
-
}
|
|
2731
|
-
this.worker = worker;
|
|
2732
|
-
this.concurrency = concurrency;
|
|
2733
|
-
this.workers = 0;
|
|
2734
|
-
this.buffer = 0;
|
|
2735
|
-
this.paused = false;
|
|
2736
|
-
this._started = false;
|
|
2737
|
-
this._tasks = [];
|
|
2738
|
-
this.onSaturated = new Signal();
|
|
2739
|
-
this.onUnsaturated = new Signal();
|
|
2740
|
-
this.onEmpty = new Signal();
|
|
2741
|
-
this.onDrain = new Signal();
|
|
2742
|
-
this.onError = new Signal();
|
|
2743
|
-
if (concurrency === 0) throw new Error('Concurrency must not be zero');
|
|
2744
|
-
this.buffer = concurrency / 4;
|
|
2745
|
-
}
|
|
2746
|
-
Object.defineProperty(AsyncQueue.prototype, "started", {
|
|
2747
|
-
get: function () {
|
|
2748
|
-
return this._started;
|
|
2749
|
-
},
|
|
2750
|
-
enumerable: true,
|
|
2751
|
-
configurable: true
|
|
2752
|
-
});
|
|
2753
|
-
AsyncQueue.prototype.reset = function () {
|
|
2754
|
-
this.onDrain.detachAll();
|
|
2755
|
-
this.workers = 0;
|
|
2756
|
-
this._started = false;
|
|
2757
|
-
this._tasks = [];
|
|
2758
|
-
};
|
|
2759
|
-
AsyncQueue.prototype.push = function (data, callback) {
|
|
2760
|
-
this._insert(data, false, callback);
|
|
2761
|
-
};
|
|
2762
|
-
AsyncQueue.prototype.unshift = function (data, callback) {
|
|
2763
|
-
this._insert(data, true, callback);
|
|
2764
|
-
};
|
|
2765
|
-
AsyncQueue.prototype.process = function () {
|
|
2766
|
-
while (!this.paused && this.workers < this.concurrency && this._tasks.length) {
|
|
2767
|
-
var task = this._tasks.shift();
|
|
2768
|
-
if (this._tasks.length === 0) this.onEmpty.dispatch();
|
|
2769
|
-
this.workers += 1;
|
|
2770
|
-
if (this.workers === this.concurrency) this.onSaturated.dispatch();
|
|
2771
|
-
this.worker(task.data, onlyOnce(this._next(task)));
|
|
2772
|
-
}
|
|
2773
|
-
};
|
|
2774
|
-
AsyncQueue.prototype.length = function () {
|
|
2775
|
-
return this._tasks.length;
|
|
2776
|
-
};
|
|
2777
|
-
AsyncQueue.prototype.running = function () {
|
|
2778
|
-
return this.workers;
|
|
2779
|
-
};
|
|
2780
|
-
AsyncQueue.prototype.idle = function () {
|
|
2781
|
-
return this._tasks.length + this.workers === 0;
|
|
2782
|
-
};
|
|
2783
|
-
AsyncQueue.prototype.pause = function () {
|
|
2784
|
-
if (this.paused === true) return;
|
|
2785
|
-
this.paused = true;
|
|
2786
|
-
};
|
|
2787
|
-
AsyncQueue.prototype.resume = function () {
|
|
2788
|
-
if (this.paused === false) return;
|
|
2789
|
-
this.paused = false;
|
|
2790
|
-
for (var w = 1; w <= this.concurrency; w++) {
|
|
2791
|
-
this.process();
|
|
2792
|
-
}
|
|
2793
|
-
};
|
|
2794
|
-
AsyncQueue.prototype.getTask = function (index) {
|
|
2795
|
-
return this._tasks[index];
|
|
2796
|
-
};
|
|
2797
|
-
AsyncQueue.prototype._insert = function (data, insertAtFront, callback) {
|
|
2798
|
-
var _this = this;
|
|
2799
|
-
if (callback != null && typeof callback !== 'function') {
|
|
2800
|
-
throw new Error('task callback must be a function');
|
|
2801
|
-
}
|
|
2802
|
-
this._started = true;
|
|
2803
|
-
if (data == null && this.idle()) {
|
|
2804
|
-
setTimeout(function () {
|
|
2805
|
-
return _this.onDrain.dispatch();
|
|
2806
|
-
}, 1);
|
|
2807
|
-
return;
|
|
2808
|
-
}
|
|
2809
|
-
var task = {
|
|
2810
|
-
data: data,
|
|
2811
|
-
callback: callback
|
|
2812
|
-
};
|
|
2813
|
-
if (insertAtFront) this._tasks.unshift(task);else this._tasks.push(task);
|
|
2814
|
-
setTimeout(function () {
|
|
2815
|
-
return _this.process();
|
|
2816
|
-
}, 1);
|
|
2817
|
-
};
|
|
2818
|
-
AsyncQueue.prototype._next = function (task) {
|
|
2819
|
-
var _this = this;
|
|
2820
|
-
return function (err) {
|
|
2821
|
-
var args = [];
|
|
2822
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
2823
|
-
args[_i - 1] = arguments[_i];
|
|
2824
|
-
}
|
|
2825
|
-
_this.workers -= 1;
|
|
2826
|
-
if (task.callback) task.callback.apply(task, __spreadArrays([err], args));
|
|
2827
|
-
if (err) _this.onError.dispatch(err, task.data);
|
|
2828
|
-
if (_this.workers <= _this.concurrency - _this.buffer) _this.onUnsaturated.dispatch();
|
|
2829
|
-
if (_this.idle()) _this.onDrain.dispatch();
|
|
2830
|
-
_this.process();
|
|
2831
|
-
};
|
|
2832
|
-
};
|
|
2833
|
-
return AsyncQueue;
|
|
2834
|
-
}();
|
|
2835
|
-
var Resource$1 = function () {
|
|
2836
|
-
function Resource(name, options) {
|
|
2837
|
-
this.children = [];
|
|
2838
|
-
this.onStart = new Signal();
|
|
2839
|
-
this.onProgress = new Signal();
|
|
2840
|
-
this.onComplete = new Signal();
|
|
2841
|
-
this.onAfterMiddleware = new Signal();
|
|
2842
|
-
this.data = null;
|
|
2843
|
-
this.type = ResourceType.Unknown;
|
|
2844
|
-
this.error = '';
|
|
2845
|
-
this.progressChunk = 0;
|
|
2846
|
-
this._dequeue = function () {};
|
|
2847
|
-
this._onCompleteBinding = null;
|
|
2848
|
-
this._state = ResourceState.NotStarted;
|
|
2849
|
-
this.name = name;
|
|
2850
|
-
this.metadata = options.metadata;
|
|
2851
|
-
if (typeof options.crossOrigin !== 'string') options.crossOrigin = this._determineCrossOrigin(options.url);
|
|
2852
|
-
if (options.strategy && typeof options.strategy !== 'function') {
|
|
2853
|
-
this._strategy = options.strategy;
|
|
2854
|
-
this._strategy.config = options;
|
|
2855
|
-
} else {
|
|
2856
|
-
var StrategyCtor = options.strategy;
|
|
2857
|
-
if (!StrategyCtor) StrategyCtor = Resource._loadStrategyMap[getExtension(options.url)];
|
|
2858
|
-
if (!StrategyCtor) StrategyCtor = Resource._defaultLoadStrategy;
|
|
2859
|
-
this._strategy = new StrategyCtor(options);
|
|
2860
|
-
}
|
|
2861
|
-
this._strategy.onError.add(this._error, this);
|
|
2862
|
-
this._strategy.onComplete.add(this._complete, this);
|
|
2863
|
-
this._strategy.onProgress.add(this._progress, this);
|
|
2864
|
-
}
|
|
2865
|
-
Resource.setDefaultLoadStrategy = function (strategy) {
|
|
2866
|
-
Resource._defaultLoadStrategy = strategy;
|
|
2867
|
-
};
|
|
2868
|
-
Resource.setLoadStrategy = function (extname, strategy) {
|
|
2869
|
-
if (extname && extname.indexOf('.') === 0) extname = extname.substring(1);
|
|
2870
|
-
if (!extname) return;
|
|
2871
|
-
Resource._loadStrategyMap[extname] = strategy;
|
|
2872
|
-
};
|
|
2873
|
-
Object.defineProperty(Resource.prototype, "strategy", {
|
|
2874
|
-
get: function () {
|
|
2875
|
-
return this._strategy;
|
|
2876
|
-
},
|
|
2877
|
-
enumerable: true,
|
|
2878
|
-
configurable: true
|
|
2879
|
-
});
|
|
2880
|
-
Object.defineProperty(Resource.prototype, "url", {
|
|
2881
|
-
get: function () {
|
|
2882
|
-
return this._strategy.config.url;
|
|
2883
|
-
},
|
|
2884
|
-
enumerable: true,
|
|
2885
|
-
configurable: true
|
|
2886
|
-
});
|
|
2887
|
-
Object.defineProperty(Resource.prototype, "isLoading", {
|
|
2888
|
-
get: function () {
|
|
2889
|
-
return this._state === ResourceState.Loading;
|
|
2890
|
-
},
|
|
2891
|
-
enumerable: true,
|
|
2892
|
-
configurable: true
|
|
2893
|
-
});
|
|
2894
|
-
Object.defineProperty(Resource.prototype, "isComplete", {
|
|
2895
|
-
get: function () {
|
|
2896
|
-
return this._state === ResourceState.Complete;
|
|
2897
|
-
},
|
|
2898
|
-
enumerable: true,
|
|
2899
|
-
configurable: true
|
|
2900
|
-
});
|
|
2901
|
-
Resource.prototype.abort = function () {
|
|
2902
|
-
this._strategy.abort();
|
|
2903
|
-
};
|
|
2904
|
-
Resource.prototype.load = function () {
|
|
2905
|
-
this._state = ResourceState.Loading;
|
|
2906
|
-
this.onStart.dispatch(this);
|
|
2907
|
-
this._strategy.load();
|
|
2908
|
-
};
|
|
2909
|
-
Resource.prototype._error = function (errMessage) {
|
|
2910
|
-
this._state = ResourceState.Complete;
|
|
2911
|
-
this.error = errMessage;
|
|
2912
|
-
this.onComplete.dispatch(this);
|
|
2913
|
-
};
|
|
2914
|
-
Resource.prototype._complete = function (type, data) {
|
|
2915
|
-
this._state = ResourceState.Complete;
|
|
2916
|
-
this.type = type;
|
|
2917
|
-
this.data = data;
|
|
2918
|
-
this.onComplete.dispatch(this);
|
|
2919
|
-
};
|
|
2920
|
-
Resource.prototype._progress = function (percent) {
|
|
2921
|
-
this.onProgress.dispatch(this, percent);
|
|
2922
|
-
};
|
|
2923
|
-
Resource.prototype._determineCrossOrigin = function (url, loc) {
|
|
2924
|
-
if (loc === void 0) {
|
|
2925
|
-
loc = window.location;
|
|
2926
|
-
}
|
|
2927
|
-
if (url.indexOf('data:') === 0 || url.indexOf('javascript:') === 0) return '';
|
|
2928
|
-
if (window.origin !== window.location.origin) return 'anonymous';
|
|
2929
|
-
if (!Resource._tempAnchor) Resource._tempAnchor = document.createElement('a');
|
|
2930
|
-
Resource._tempAnchor.href = url;
|
|
2931
|
-
var parsed = parseUri(Resource._tempAnchor.href, {
|
|
2932
|
-
strictMode: true
|
|
2933
|
-
});
|
|
2934
|
-
var samePort = !parsed.port && loc.port === '' || parsed.port === loc.port;
|
|
2935
|
-
var protocol = parsed.protocol ? parsed.protocol + ":" : '';
|
|
2936
|
-
if (parsed.host !== loc.hostname || !samePort || protocol !== loc.protocol) return 'anonymous';
|
|
2937
|
-
return '';
|
|
2938
|
-
};
|
|
2939
|
-
Resource._tempAnchor = null;
|
|
2940
|
-
Resource._defaultLoadStrategy = XhrLoadStrategy;
|
|
2941
|
-
Resource._loadStrategyMap = {
|
|
2942
|
-
gif: ImageLoadStrategy,
|
|
2943
|
-
png: ImageLoadStrategy,
|
|
2944
|
-
bmp: ImageLoadStrategy,
|
|
2945
|
-
jpg: ImageLoadStrategy,
|
|
2946
|
-
jpeg: ImageLoadStrategy,
|
|
2947
|
-
tif: ImageLoadStrategy,
|
|
2948
|
-
tiff: ImageLoadStrategy,
|
|
2949
|
-
webp: ImageLoadStrategy,
|
|
2950
|
-
tga: ImageLoadStrategy,
|
|
2951
|
-
svg: ImageLoadStrategy,
|
|
2952
|
-
'svg+xml': ImageLoadStrategy,
|
|
2953
|
-
mp3: AudioLoadStrategy,
|
|
2954
|
-
ogg: AudioLoadStrategy,
|
|
2955
|
-
wav: AudioLoadStrategy,
|
|
2956
|
-
mp4: VideoLoadStrategy,
|
|
2957
|
-
webm: VideoLoadStrategy,
|
|
2958
|
-
mov: VideoLoadStrategy
|
|
2959
|
-
};
|
|
2960
|
-
return Resource;
|
|
2961
|
-
}();
|
|
2962
|
-
function eachSeries(array, iterator, callback, deferNext) {
|
|
2963
|
-
if (deferNext === void 0) {
|
|
2964
|
-
deferNext = false;
|
|
2965
|
-
}
|
|
2966
|
-
var i = 0;
|
|
2967
|
-
var len = array.length;
|
|
2968
|
-
(function next(err) {
|
|
2969
|
-
if (err || i === len) {
|
|
2970
|
-
if (callback) callback(err);
|
|
2971
|
-
return;
|
|
2972
|
-
}
|
|
2973
|
-
if (deferNext) setTimeout(function () {
|
|
2974
|
-
return iterator(array[i++], next);
|
|
2975
|
-
}, 1);else iterator(array[i++], next);
|
|
2976
|
-
})();
|
|
2977
|
-
}
|
|
2978
|
-
var MAX_PROGRESS = 100;
|
|
2979
|
-
var rgxExtractUrlHash = /(#[\w-]+)?$/;
|
|
2980
|
-
var Loader = function () {
|
|
2981
|
-
function Loader(baseUrl, concurrency) {
|
|
2982
|
-
if (baseUrl === void 0) {
|
|
2983
|
-
baseUrl = '';
|
|
2984
|
-
}
|
|
2985
|
-
if (concurrency === void 0) {
|
|
2986
|
-
concurrency = 10;
|
|
2987
|
-
}
|
|
2988
|
-
this.progress = 0;
|
|
2989
|
-
this.loading = false;
|
|
2990
|
-
this.defaultQueryString = '';
|
|
2991
|
-
this.resources = {};
|
|
2992
|
-
this.onError = new Signal();
|
|
2993
|
-
this.onLoad = new Signal();
|
|
2994
|
-
this.onStart = new Signal();
|
|
2995
|
-
this.onComplete = new Signal();
|
|
2996
|
-
this.onProgress = new Signal();
|
|
2997
|
-
this._baseUrl = '';
|
|
2998
|
-
this._urlResolvers = [];
|
|
2999
|
-
this._middleware = [];
|
|
3000
|
-
this._resourcesParsing = [];
|
|
3001
|
-
this._boundLoadResource = this._loadResource.bind(this);
|
|
3002
|
-
this.baseUrl = baseUrl;
|
|
3003
|
-
this._queue = new AsyncQueue(this._boundLoadResource, concurrency);
|
|
3004
|
-
this._queue.pause();
|
|
3005
|
-
this._middleware = Loader._defaultMiddleware.slice();
|
|
3006
|
-
}
|
|
3007
|
-
Object.defineProperty(Loader.prototype, "baseUrl", {
|
|
3008
|
-
get: function () {
|
|
3009
|
-
return this._baseUrl;
|
|
3010
|
-
},
|
|
3011
|
-
set: function (url) {
|
|
3012
|
-
while (url.length && url.charAt(url.length - 1) === '/') {
|
|
3013
|
-
url = url.slice(0, -1);
|
|
3014
|
-
}
|
|
3015
|
-
this._baseUrl = url;
|
|
3016
|
-
},
|
|
3017
|
-
enumerable: true,
|
|
3018
|
-
configurable: true
|
|
3019
|
-
});
|
|
3020
|
-
Loader.prototype.add = function (options, url_) {
|
|
3021
|
-
if (Array.isArray(options)) {
|
|
3022
|
-
for (var i = 0; i < options.length; ++i) {
|
|
3023
|
-
this.add(options[i]);
|
|
3024
|
-
}
|
|
3025
|
-
return this;
|
|
3026
|
-
}
|
|
3027
|
-
var url = '';
|
|
3028
|
-
var name = '';
|
|
3029
|
-
var baseUrl = this._baseUrl;
|
|
3030
|
-
var resOptions = {
|
|
3031
|
-
url: ''
|
|
3032
|
-
};
|
|
3033
|
-
if (typeof options === 'object') {
|
|
3034
|
-
url = options.url;
|
|
3035
|
-
name = options.name || options.url;
|
|
3036
|
-
baseUrl = options.baseUrl || baseUrl;
|
|
3037
|
-
resOptions = options;
|
|
3038
|
-
} else {
|
|
3039
|
-
name = options;
|
|
3040
|
-
if (typeof url_ === 'string') url = url_;else url = name;
|
|
3041
|
-
}
|
|
3042
|
-
if (!url) throw new Error('You must specify the `url` property.');
|
|
3043
|
-
if (this.loading && !resOptions.parentResource) {
|
|
3044
|
-
throw new Error('Cannot add root resources while the loader is running.');
|
|
3045
|
-
}
|
|
3046
|
-
if (this.resources[name]) {
|
|
3047
|
-
throw new Error("Resource named \"" + name + "\" already exists.");
|
|
3048
|
-
}
|
|
3049
|
-
url = this._prepareUrl(url, baseUrl);
|
|
3050
|
-
resOptions.url = url;
|
|
3051
|
-
var resource = new Resource$1(name, resOptions);
|
|
3052
|
-
this.resources[name] = resource;
|
|
3053
|
-
if (typeof resOptions.onComplete === 'function') {
|
|
3054
|
-
resource.onAfterMiddleware.once(resOptions.onComplete);
|
|
3055
|
-
}
|
|
3056
|
-
if (this.loading) {
|
|
3057
|
-
var parent_1 = resOptions.parentResource;
|
|
3058
|
-
var incompleteChildren = [];
|
|
3059
|
-
for (var i = 0; i < parent_1.children.length; ++i) {
|
|
3060
|
-
if (!parent_1.children[i].isComplete) {
|
|
3061
|
-
incompleteChildren.push(parent_1.children[i]);
|
|
3062
|
-
}
|
|
3063
|
-
}
|
|
3064
|
-
var fullChunk = parent_1.progressChunk * (incompleteChildren.length + 1);
|
|
3065
|
-
var eachChunk = fullChunk / (incompleteChildren.length + 2);
|
|
3066
|
-
parent_1.children.push(resource);
|
|
3067
|
-
parent_1.progressChunk = eachChunk;
|
|
3068
|
-
for (var i = 0; i < incompleteChildren.length; ++i) {
|
|
3069
|
-
incompleteChildren[i].progressChunk = eachChunk;
|
|
3070
|
-
}
|
|
3071
|
-
resource.progressChunk = eachChunk;
|
|
3072
|
-
}
|
|
3073
|
-
this._queue.push(resource);
|
|
3074
|
-
return this;
|
|
3075
|
-
};
|
|
3076
|
-
Loader.prototype.use = function (fn, priority) {
|
|
3077
|
-
if (priority === void 0) {
|
|
3078
|
-
priority = Loader.DefaultMiddlewarePriority;
|
|
3079
|
-
}
|
|
3080
|
-
this._middleware.push({
|
|
3081
|
-
fn: fn,
|
|
3082
|
-
priority: priority
|
|
3083
|
-
});
|
|
3084
|
-
this._middleware.sort(function (a, b) {
|
|
3085
|
-
return a.priority - b.priority;
|
|
3086
|
-
});
|
|
3087
|
-
return this;
|
|
3088
|
-
};
|
|
3089
|
-
Loader.prototype.reset = function () {
|
|
3090
|
-
this.progress = 0;
|
|
3091
|
-
this.loading = false;
|
|
3092
|
-
this._queue.reset();
|
|
3093
|
-
this._queue.pause();
|
|
3094
|
-
for (var k in this.resources) {
|
|
3095
|
-
var res = this.resources[k];
|
|
3096
|
-
if (!res) continue;
|
|
3097
|
-
if (res._onCompleteBinding) res._onCompleteBinding.detach();
|
|
3098
|
-
if (res.isLoading) res.abort();
|
|
3099
|
-
}
|
|
3100
|
-
this.resources = {};
|
|
3101
|
-
return this;
|
|
3102
|
-
};
|
|
3103
|
-
Loader.prototype.load = function (cb) {
|
|
3104
|
-
if (typeof cb === 'function') this.onComplete.once(cb);
|
|
3105
|
-
if (this.loading) return this;
|
|
3106
|
-
if (this._queue.idle()) {
|
|
3107
|
-
this._onStart();
|
|
3108
|
-
this._onComplete();
|
|
3109
|
-
} else {
|
|
3110
|
-
var numTasks = this._queue.length();
|
|
3111
|
-
var chunk = MAX_PROGRESS / numTasks;
|
|
3112
|
-
for (var i = 0; i < this._queue.length(); ++i) {
|
|
3113
|
-
this._queue.getTask(i).data.progressChunk = chunk;
|
|
3114
|
-
}
|
|
3115
|
-
this._onStart();
|
|
3116
|
-
this._queue.resume();
|
|
3117
|
-
}
|
|
3118
|
-
return this;
|
|
3119
|
-
};
|
|
3120
|
-
Object.defineProperty(Loader.prototype, "concurrency", {
|
|
3121
|
-
get: function () {
|
|
3122
|
-
return this._queue.concurrency;
|
|
3123
|
-
},
|
|
3124
|
-
set: function (concurrency) {
|
|
3125
|
-
this._queue.concurrency = concurrency;
|
|
3126
|
-
},
|
|
3127
|
-
enumerable: true,
|
|
3128
|
-
configurable: true
|
|
3129
|
-
});
|
|
3130
|
-
Loader.prototype.addUrlResolver = function (func) {
|
|
3131
|
-
this._urlResolvers.push(func);
|
|
3132
|
-
return this;
|
|
3133
|
-
};
|
|
3134
|
-
Loader.prototype._prepareUrl = function (url, baseUrl) {
|
|
3135
|
-
var parsed = parseUri(url, {
|
|
3136
|
-
strictMode: true
|
|
3137
|
-
});
|
|
3138
|
-
this._urlResolvers.forEach(function (resolver) {
|
|
3139
|
-
url = resolver(url, parsed);
|
|
3140
|
-
parsed = parseUri(url, {
|
|
3141
|
-
strictMode: true
|
|
3142
|
-
});
|
|
3143
|
-
});
|
|
3144
|
-
if (!parsed.protocol && url.indexOf('//') !== 0) {
|
|
3145
|
-
if (baseUrl.length && url.charAt(0) !== '/') url = baseUrl + "/" + url;else url = baseUrl + url;
|
|
3146
|
-
}
|
|
3147
|
-
if (this.defaultQueryString) {
|
|
3148
|
-
var match = rgxExtractUrlHash.exec(url);
|
|
3149
|
-
if (match) {
|
|
3150
|
-
var hash = match[0];
|
|
3151
|
-
url = url.substr(0, url.length - hash.length);
|
|
3152
|
-
if (url.indexOf('?') !== -1) url += "&" + this.defaultQueryString;else url += "?" + this.defaultQueryString;
|
|
3153
|
-
url += hash;
|
|
3154
|
-
}
|
|
3155
|
-
}
|
|
3156
|
-
return url;
|
|
3157
|
-
};
|
|
3158
|
-
Loader.prototype._loadResource = function (resource, dequeue) {
|
|
3159
|
-
resource._dequeue = dequeue;
|
|
3160
|
-
resource._onCompleteBinding = resource.onComplete.once(this._onLoad, this);
|
|
3161
|
-
resource.load();
|
|
3162
|
-
};
|
|
3163
|
-
Loader.prototype._onStart = function () {
|
|
3164
|
-
this.progress = 0;
|
|
3165
|
-
this.loading = true;
|
|
3166
|
-
this.onStart.dispatch(this);
|
|
3167
|
-
};
|
|
3168
|
-
Loader.prototype._onComplete = function () {
|
|
3169
|
-
this.progress = MAX_PROGRESS;
|
|
3170
|
-
this.loading = false;
|
|
3171
|
-
this.onComplete.dispatch(this, this.resources);
|
|
3172
|
-
};
|
|
3173
|
-
Loader.prototype._onLoad = function (resource) {
|
|
3174
|
-
var _this = this;
|
|
3175
|
-
resource._onCompleteBinding = null;
|
|
3176
|
-
this._resourcesParsing.push(resource);
|
|
3177
|
-
resource._dequeue();
|
|
3178
|
-
eachSeries(this._middleware, function (middleware, next) {
|
|
3179
|
-
middleware.fn.call(_this, resource, next);
|
|
3180
|
-
}, function () {
|
|
3181
|
-
resource.onAfterMiddleware.dispatch(resource);
|
|
3182
|
-
_this.progress = Math.min(MAX_PROGRESS, _this.progress + resource.progressChunk);
|
|
3183
|
-
_this.onProgress.dispatch(_this, resource);
|
|
3184
|
-
if (resource.error) _this.onError.dispatch(resource.error, _this, resource);else _this.onLoad.dispatch(_this, resource);
|
|
3185
|
-
_this._resourcesParsing.splice(_this._resourcesParsing.indexOf(resource), 1);
|
|
3186
|
-
if (_this._queue.idle() && _this._resourcesParsing.length === 0) _this._onComplete();
|
|
3187
|
-
}, true);
|
|
3188
|
-
};
|
|
3189
|
-
Loader.use = function (fn, priority) {
|
|
3190
|
-
if (priority === void 0) {
|
|
3191
|
-
priority = Loader.DefaultMiddlewarePriority;
|
|
3192
|
-
}
|
|
3193
|
-
Loader._defaultMiddleware.push({
|
|
3194
|
-
fn: fn,
|
|
3195
|
-
priority: priority
|
|
3196
|
-
});
|
|
3197
|
-
Loader._defaultMiddleware.sort(function (a, b) {
|
|
3198
|
-
return a.priority - b.priority;
|
|
3199
|
-
});
|
|
3200
|
-
return Loader;
|
|
3201
|
-
};
|
|
3202
|
-
Loader.DefaultMiddlewarePriority = 50;
|
|
3203
|
-
Loader._defaultMiddleware = [];
|
|
3204
|
-
return Loader;
|
|
3205
|
-
}();
|
|
3206
|
-
const resourceLoader = {
|
|
3207
|
-
AbstractLoadStrategy,
|
|
3208
|
-
AudioLoadStrategy,
|
|
3209
|
-
ImageLoadStrategy,
|
|
3210
|
-
XhrResponseType,
|
|
3211
|
-
MediaElementLoadStrategy,
|
|
3212
|
-
VideoLoadStrategy,
|
|
3213
|
-
Loader,
|
|
3214
|
-
Resource: Resource$1,
|
|
3215
|
-
ResourceType,
|
|
3216
|
-
ResourceState
|
|
3217
|
-
};
|
|
3218
2139
|
exports.LOAD_EVENT = void 0;
|
|
3219
2140
|
(function (LOAD_EVENT) {
|
|
3220
2141
|
LOAD_EVENT["START"] = "start";
|
|
@@ -3346,7 +2267,7 @@ var _EVA_IIFE_EVA = function (exports, pixi_js) {
|
|
|
3346
2267
|
const unLoadNames = names.filter(name => !this.promiseMap[name] && this.resourcesMap[name]);
|
|
3347
2268
|
if (!unLoadNames.length) return;
|
|
3348
2269
|
const resolves = {};
|
|
3349
|
-
unLoadNames.forEach(name => {
|
|
2270
|
+
unLoadNames.forEach(name => __awaiter(this, void 0, void 0, function* () {
|
|
3350
2271
|
var _a;
|
|
3351
2272
|
this.promiseMap[name] = new Promise(r => resolves[name] = r);
|
|
3352
2273
|
const res = this.resourcesMap[name];
|
|
@@ -3360,22 +2281,61 @@ var _EVA_IIFE_EVA = function (exports, pixi_js) {
|
|
|
3360
2281
|
this.doComplete(name, resolves[name], preload);
|
|
3361
2282
|
} else {
|
|
3362
2283
|
let url = (_a = res.src[key]) === null || _a === void 0 ? void 0 : _a.url;
|
|
2284
|
+
console.log(url);
|
|
3363
2285
|
if (typeof url === 'string' && url.startsWith('//')) {
|
|
3364
|
-
url =
|
|
2286
|
+
url = `https:${res.src[key].url}`;
|
|
3365
2287
|
}
|
|
3366
2288
|
if (key === 'atlas') {
|
|
2289
|
+
const loadImagePromise = pixi_js.Assets.load(res.src['image'].url).catch(e => {
|
|
2290
|
+
this.onError({
|
|
2291
|
+
preload,
|
|
2292
|
+
errMsg: e.message,
|
|
2293
|
+
resource: {
|
|
2294
|
+
metadata: {
|
|
2295
|
+
key,
|
|
2296
|
+
name,
|
|
2297
|
+
resolves
|
|
2298
|
+
}
|
|
2299
|
+
}
|
|
2300
|
+
});
|
|
2301
|
+
});
|
|
3367
2302
|
pixi_js.Assets.add({
|
|
3368
2303
|
alias: url,
|
|
3369
2304
|
src: url,
|
|
3370
2305
|
data: {
|
|
3371
|
-
resolve: () =>
|
|
2306
|
+
resolve: () => loadImagePromise,
|
|
2307
|
+
imageTexture: yield loadImagePromise
|
|
3372
2308
|
}
|
|
3373
2309
|
});
|
|
3374
2310
|
} else {
|
|
3375
|
-
|
|
2311
|
+
const options = {
|
|
3376
2312
|
alias: url,
|
|
3377
2313
|
src: url
|
|
3378
|
-
}
|
|
2314
|
+
};
|
|
2315
|
+
if (res.type === exports.RESOURCE_TYPE.SPRITE || res.type === exports.RESOURCE_TYPE.SPRITE_ANIMATION) {
|
|
2316
|
+
if (res.src[key].type === 'json') {
|
|
2317
|
+
try {
|
|
2318
|
+
const data = yield pixi_js.Assets.load(res.src['image'].url);
|
|
2319
|
+
options.data = {
|
|
2320
|
+
texture: data
|
|
2321
|
+
};
|
|
2322
|
+
} catch (e) {
|
|
2323
|
+
console.log('>>>E', e);
|
|
2324
|
+
this.onError({
|
|
2325
|
+
preload,
|
|
2326
|
+
errMsg: e.message,
|
|
2327
|
+
resource: {
|
|
2328
|
+
metadata: {
|
|
2329
|
+
key,
|
|
2330
|
+
name,
|
|
2331
|
+
resolves
|
|
2332
|
+
}
|
|
2333
|
+
}
|
|
2334
|
+
});
|
|
2335
|
+
}
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
pixi_js.Assets.add(options);
|
|
3379
2339
|
}
|
|
3380
2340
|
pixi_js.Assets.load(url).then(data => {
|
|
3381
2341
|
this.onLoad({
|
|
@@ -3405,7 +2365,7 @@ var _EVA_IIFE_EVA = function (exports, pixi_js) {
|
|
|
3405
2365
|
});
|
|
3406
2366
|
}
|
|
3407
2367
|
}
|
|
3408
|
-
});
|
|
2368
|
+
}));
|
|
3409
2369
|
}
|
|
3410
2370
|
doComplete(name, resolve, preload = false) {
|
|
3411
2371
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -3490,7 +2450,7 @@ var _EVA_IIFE_EVA = function (exports, pixi_js) {
|
|
|
3490
2450
|
IDEProp,
|
|
3491
2451
|
componentObserver
|
|
3492
2452
|
};
|
|
3493
|
-
const version = '2.0.0-beta.
|
|
2453
|
+
const version = '2.0.0-beta.22';
|
|
3494
2454
|
console.log(`Eva.js version: ${version}`);
|
|
3495
2455
|
const RESOURCE_TYPE_STRATEGY = {};
|
|
3496
2456
|
exports.Component = Component$1;
|
|
@@ -3504,11 +2464,10 @@ var _EVA_IIFE_EVA = function (exports, pixi_js) {
|
|
|
3504
2464
|
exports.componentObserver = componentObserver;
|
|
3505
2465
|
exports.decorators = decorators;
|
|
3506
2466
|
exports.resource = resource;
|
|
3507
|
-
exports.resourceLoader = resourceLoader;
|
|
3508
2467
|
exports.version = version;
|
|
3509
2468
|
Object.defineProperty(exports, '__esModule', {
|
|
3510
2469
|
value: true
|
|
3511
2470
|
});
|
|
3512
2471
|
return exports;
|
|
3513
2472
|
}({}, PIXI);
|
|
3514
|
-
|
|
2473
|
+
globalThis.EVA = globalThis.EVA || _EVA_IIFE_EVA;
|