@revues/web-sdk-core 0.0.1-beta.9 → 1.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/web-sdk-core.js +37 -1994
- package/package.json +8 -3
package/dist/web-sdk-core.js
CHANGED
|
@@ -3,1997 +3,40 @@
|
|
|
3
3
|
* (c) 2024-2024 Alex
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
(function (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
43
|
-
s = arguments[i];
|
|
44
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
45
|
-
}
|
|
46
|
-
return t;
|
|
47
|
-
};
|
|
48
|
-
return __assign.apply(this, arguments);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
52
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
53
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
54
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
55
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
56
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
57
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function __generator(thisArg, body) {
|
|
62
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
63
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
64
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
65
|
-
function step(op) {
|
|
66
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
67
|
-
while (_) try {
|
|
68
|
-
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;
|
|
69
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
70
|
-
switch (op[0]) {
|
|
71
|
-
case 0: case 1: t = op; break;
|
|
72
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
73
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
74
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
75
|
-
default:
|
|
76
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
77
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
78
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
79
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
80
|
-
if (t[2]) _.ops.pop();
|
|
81
|
-
_.trys.pop(); continue;
|
|
82
|
-
}
|
|
83
|
-
op = body.call(thisArg, _);
|
|
84
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
85
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function __spreadArrays() {
|
|
90
|
-
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
91
|
-
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
92
|
-
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
93
|
-
r[k] = a[j];
|
|
94
|
-
return r;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function getSystem() {
|
|
98
|
-
var e = window.navigator.userAgent.toLowerCase();
|
|
99
|
-
return /(iphone|ipad)/.test(e)
|
|
100
|
-
? 'IOS'
|
|
101
|
-
: /android/.test(e)
|
|
102
|
-
? 'Android'
|
|
103
|
-
: 'Windows For HUYA';
|
|
104
|
-
}
|
|
105
|
-
function resolveUrl(url) {
|
|
106
|
-
var _a = url.split('?'), path = _a[0], queryStr = _a[1];
|
|
107
|
-
var query = {};
|
|
108
|
-
if (queryStr != null && queryStr !== '') {
|
|
109
|
-
queryStr.split('&').reduce(function (acc, item) {
|
|
110
|
-
var kv = item.split('=');
|
|
111
|
-
acc[kv[0]] = decodeURIComponent(kv[1]);
|
|
112
|
-
return acc;
|
|
113
|
-
}, query);
|
|
114
|
-
}
|
|
115
|
-
return {
|
|
116
|
-
path: path,
|
|
117
|
-
query: query
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
function arrayBufferToBase64(buffer) {
|
|
121
|
-
var binary = '';
|
|
122
|
-
var bytes = new Uint8Array(buffer);
|
|
123
|
-
var len = bytes.byteLength;
|
|
124
|
-
for (var i = 0; i < len; i++) {
|
|
125
|
-
binary += String.fromCharCode(bytes[i]);
|
|
126
|
-
}
|
|
127
|
-
return window.btoa(binary);
|
|
128
|
-
}
|
|
129
|
-
function delay(duration) {
|
|
130
|
-
return new Promise(function (resolve) {
|
|
131
|
-
setTimeout(resolve, duration);
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
var promiseTimeout = function (ms, promise, handleTimeout) {
|
|
135
|
-
var id;
|
|
136
|
-
// Create a promise that rejects in <ms> milliseconds
|
|
137
|
-
var timeout = new Promise(function (resolve, reject) {
|
|
138
|
-
id = setTimeout(function () {
|
|
139
|
-
handleTimeout && handleTimeout(ms);
|
|
140
|
-
reject(new Error('Timed out in ' + ms + 'ms.'));
|
|
141
|
-
}, ms);
|
|
142
|
-
});
|
|
143
|
-
// Returns a race between our timeout and the passed in promise
|
|
144
|
-
return new Promise(function (resolve, reject) {
|
|
145
|
-
Promise.race([
|
|
146
|
-
promise,
|
|
147
|
-
timeout
|
|
148
|
-
]).then(function (res) {
|
|
149
|
-
clearTimeout(id);
|
|
150
|
-
resolve(res);
|
|
151
|
-
}).catch(reject);
|
|
152
|
-
});
|
|
153
|
-
};
|
|
154
|
-
function formatPagePath(v) {
|
|
155
|
-
return v.replace(/\.html$/, '');
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
var basePath = location.protocol + '//' + location.host + location.pathname.replace(/index\.html$/, '');
|
|
159
|
-
// 视图层逻辑模版
|
|
160
|
-
var viewTemplatePath = basePath + 'view.html';
|
|
161
|
-
// 先开着
|
|
162
|
-
var debug = window.__debug != null ? window.__debug : true;
|
|
163
|
-
var Terminal = {
|
|
164
|
-
Service: 'service',
|
|
165
|
-
View: 'view'
|
|
166
|
-
};
|
|
167
|
-
var packageExtConfig = window.__packageExtConfig;
|
|
168
|
-
var launchOption = {
|
|
169
|
-
path: packageExtConfig ? packageExtConfig.entryPagePath : 'index',
|
|
170
|
-
query: {},
|
|
171
|
-
referrerInfo: {},
|
|
172
|
-
scene: 1001
|
|
173
|
-
};
|
|
174
|
-
var onLoadSubPackageTaskStateChange = 'onLoadSubPackageTaskStateChange';
|
|
175
|
-
var onTaskProgressUpdate = 'onTaskProgressUpdate';
|
|
176
|
-
var onTaskHeadersReceived = 'onTaskHeadersReceived';
|
|
177
|
-
var miniGame = 'miniGame';
|
|
178
|
-
var miniProgram = 'miniProgram';
|
|
179
|
-
var localPathPerfix = 'finfile://';
|
|
180
|
-
var imgSets = new Set(['.png', '.jpg', '.jpeg', '.gif', '.svg', '.mp4', '.mp3']);
|
|
181
|
-
|
|
182
|
-
function requestSource(url, opts, cb) {
|
|
183
|
-
var xhr = new XMLHttpRequest();
|
|
184
|
-
var asyncRequest = true;
|
|
185
|
-
if (opts.sync != null) {
|
|
186
|
-
asyncRequest = !opts.sync;
|
|
187
|
-
}
|
|
188
|
-
if (opts.responseType != null) {
|
|
189
|
-
xhr.responseType = opts.responseType;
|
|
190
|
-
}
|
|
191
|
-
xhr.open('GET', url, asyncRequest);
|
|
192
|
-
if (opts.header != null) {
|
|
193
|
-
for (var key in opts.header) {
|
|
194
|
-
xhr.setRequestHeader(key, opts.header[key]);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
xhr.onload = function (e) {
|
|
198
|
-
cb(null, xhr.response, { e: e, xhr: xhr });
|
|
199
|
-
};
|
|
200
|
-
xhr.onerror = function (e) {
|
|
201
|
-
cb(new Error('request settings failed!'), null, { e: e, xhr: xhr });
|
|
202
|
-
};
|
|
203
|
-
xhr.send(null);
|
|
204
|
-
}
|
|
205
|
-
function processFilePath(file) {
|
|
206
|
-
// TODO: 需要判断同域同源才处理
|
|
207
|
-
if (file.endsWith('.wasm')) {
|
|
208
|
-
return file + '.txt';
|
|
209
|
-
}
|
|
210
|
-
return file;
|
|
211
|
-
}
|
|
212
|
-
var cache = {};
|
|
213
|
-
function cacheRequest(url, opts, cb) {
|
|
214
|
-
if (cache[url] != null) {
|
|
215
|
-
return cache[url];
|
|
216
|
-
}
|
|
217
|
-
requestSource(url, opts, function (err, data, eventInfo) {
|
|
218
|
-
if (err !== null) {
|
|
219
|
-
cache[url] = data;
|
|
220
|
-
}
|
|
221
|
-
cb(err, data, eventInfo);
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
function createCommonjsModule(fn, basedir, module) {
|
|
226
|
-
return module = {
|
|
227
|
-
path: basedir,
|
|
228
|
-
exports: {},
|
|
229
|
-
require: function (path, base) {
|
|
230
|
-
return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
|
|
231
|
-
}
|
|
232
|
-
}, fn(module, module.exports), module.exports;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
function commonjsRequire () {
|
|
236
|
-
throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
var eventemitter3 = createCommonjsModule(function (module) {
|
|
240
|
-
|
|
241
|
-
var has = Object.prototype.hasOwnProperty
|
|
242
|
-
, prefix = '~';
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Constructor to create a storage for our `EE` objects.
|
|
246
|
-
* An `Events` instance is a plain object whose properties are event names.
|
|
247
|
-
*
|
|
248
|
-
* @constructor
|
|
249
|
-
* @private
|
|
250
|
-
*/
|
|
251
|
-
function Events() {}
|
|
252
|
-
|
|
253
|
-
//
|
|
254
|
-
// We try to not inherit from `Object.prototype`. In some engines creating an
|
|
255
|
-
// instance in this way is faster than calling `Object.create(null)` directly.
|
|
256
|
-
// If `Object.create(null)` is not supported we prefix the event names with a
|
|
257
|
-
// character to make sure that the built-in object properties are not
|
|
258
|
-
// overridden or used as an attack vector.
|
|
259
|
-
//
|
|
260
|
-
if (Object.create) {
|
|
261
|
-
Events.prototype = Object.create(null);
|
|
262
|
-
|
|
263
|
-
//
|
|
264
|
-
// This hack is needed because the `__proto__` property is still inherited in
|
|
265
|
-
// some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
|
|
266
|
-
//
|
|
267
|
-
if (!new Events().__proto__) prefix = false;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Representation of a single event listener.
|
|
272
|
-
*
|
|
273
|
-
* @param {Function} fn The listener function.
|
|
274
|
-
* @param {*} context The context to invoke the listener with.
|
|
275
|
-
* @param {Boolean} [once=false] Specify if the listener is a one-time listener.
|
|
276
|
-
* @constructor
|
|
277
|
-
* @private
|
|
278
|
-
*/
|
|
279
|
-
function EE(fn, context, once) {
|
|
280
|
-
this.fn = fn;
|
|
281
|
-
this.context = context;
|
|
282
|
-
this.once = once || false;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* Add a listener for a given event.
|
|
287
|
-
*
|
|
288
|
-
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
289
|
-
* @param {(String|Symbol)} event The event name.
|
|
290
|
-
* @param {Function} fn The listener function.
|
|
291
|
-
* @param {*} context The context to invoke the listener with.
|
|
292
|
-
* @param {Boolean} once Specify if the listener is a one-time listener.
|
|
293
|
-
* @returns {EventEmitter}
|
|
294
|
-
* @private
|
|
295
|
-
*/
|
|
296
|
-
function addListener(emitter, event, fn, context, once) {
|
|
297
|
-
if (typeof fn !== 'function') {
|
|
298
|
-
throw new TypeError('The listener must be a function');
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
var listener = new EE(fn, context || emitter, once)
|
|
302
|
-
, evt = prefix ? prefix + event : event;
|
|
303
|
-
|
|
304
|
-
if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
|
|
305
|
-
else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
|
|
306
|
-
else emitter._events[evt] = [emitter._events[evt], listener];
|
|
307
|
-
|
|
308
|
-
return emitter;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
* Clear event by name.
|
|
313
|
-
*
|
|
314
|
-
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
315
|
-
* @param {(String|Symbol)} evt The Event name.
|
|
316
|
-
* @private
|
|
317
|
-
*/
|
|
318
|
-
function clearEvent(emitter, evt) {
|
|
319
|
-
if (--emitter._eventsCount === 0) emitter._events = new Events();
|
|
320
|
-
else delete emitter._events[evt];
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
/**
|
|
324
|
-
* Minimal `EventEmitter` interface that is molded against the Node.js
|
|
325
|
-
* `EventEmitter` interface.
|
|
326
|
-
*
|
|
327
|
-
* @constructor
|
|
328
|
-
* @public
|
|
329
|
-
*/
|
|
330
|
-
function EventEmitter() {
|
|
331
|
-
this._events = new Events();
|
|
332
|
-
this._eventsCount = 0;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* Return an array listing the events for which the emitter has registered
|
|
337
|
-
* listeners.
|
|
338
|
-
*
|
|
339
|
-
* @returns {Array}
|
|
340
|
-
* @public
|
|
341
|
-
*/
|
|
342
|
-
EventEmitter.prototype.eventNames = function eventNames() {
|
|
343
|
-
var names = []
|
|
344
|
-
, events
|
|
345
|
-
, name;
|
|
346
|
-
|
|
347
|
-
if (this._eventsCount === 0) return names;
|
|
348
|
-
|
|
349
|
-
for (name in (events = this._events)) {
|
|
350
|
-
if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
if (Object.getOwnPropertySymbols) {
|
|
354
|
-
return names.concat(Object.getOwnPropertySymbols(events));
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
return names;
|
|
358
|
-
};
|
|
359
|
-
|
|
360
|
-
/**
|
|
361
|
-
* Return the listeners registered for a given event.
|
|
362
|
-
*
|
|
363
|
-
* @param {(String|Symbol)} event The event name.
|
|
364
|
-
* @returns {Array} The registered listeners.
|
|
365
|
-
* @public
|
|
366
|
-
*/
|
|
367
|
-
EventEmitter.prototype.listeners = function listeners(event) {
|
|
368
|
-
var evt = prefix ? prefix + event : event
|
|
369
|
-
, handlers = this._events[evt];
|
|
370
|
-
|
|
371
|
-
if (!handlers) return [];
|
|
372
|
-
if (handlers.fn) return [handlers.fn];
|
|
373
|
-
|
|
374
|
-
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
|
|
375
|
-
ee[i] = handlers[i].fn;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
return ee;
|
|
379
|
-
};
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* Return the number of listeners listening to a given event.
|
|
383
|
-
*
|
|
384
|
-
* @param {(String|Symbol)} event The event name.
|
|
385
|
-
* @returns {Number} The number of listeners.
|
|
386
|
-
* @public
|
|
387
|
-
*/
|
|
388
|
-
EventEmitter.prototype.listenerCount = function listenerCount(event) {
|
|
389
|
-
var evt = prefix ? prefix + event : event
|
|
390
|
-
, listeners = this._events[evt];
|
|
391
|
-
|
|
392
|
-
if (!listeners) return 0;
|
|
393
|
-
if (listeners.fn) return 1;
|
|
394
|
-
return listeners.length;
|
|
395
|
-
};
|
|
396
|
-
|
|
397
|
-
/**
|
|
398
|
-
* Calls each of the listeners registered for a given event.
|
|
399
|
-
*
|
|
400
|
-
* @param {(String|Symbol)} event The event name.
|
|
401
|
-
* @returns {Boolean} `true` if the event had listeners, else `false`.
|
|
402
|
-
* @public
|
|
403
|
-
*/
|
|
404
|
-
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
405
|
-
var evt = prefix ? prefix + event : event;
|
|
406
|
-
|
|
407
|
-
if (!this._events[evt]) return false;
|
|
408
|
-
|
|
409
|
-
var listeners = this._events[evt]
|
|
410
|
-
, len = arguments.length
|
|
411
|
-
, args
|
|
412
|
-
, i;
|
|
413
|
-
|
|
414
|
-
if (listeners.fn) {
|
|
415
|
-
if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
|
|
416
|
-
|
|
417
|
-
switch (len) {
|
|
418
|
-
case 1: return listeners.fn.call(listeners.context), true;
|
|
419
|
-
case 2: return listeners.fn.call(listeners.context, a1), true;
|
|
420
|
-
case 3: return listeners.fn.call(listeners.context, a1, a2), true;
|
|
421
|
-
case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
|
|
422
|
-
case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
|
|
423
|
-
case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
for (i = 1, args = new Array(len -1); i < len; i++) {
|
|
427
|
-
args[i - 1] = arguments[i];
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
listeners.fn.apply(listeners.context, args);
|
|
431
|
-
} else {
|
|
432
|
-
var length = listeners.length
|
|
433
|
-
, j;
|
|
434
|
-
|
|
435
|
-
for (i = 0; i < length; i++) {
|
|
436
|
-
if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
|
|
437
|
-
|
|
438
|
-
switch (len) {
|
|
439
|
-
case 1: listeners[i].fn.call(listeners[i].context); break;
|
|
440
|
-
case 2: listeners[i].fn.call(listeners[i].context, a1); break;
|
|
441
|
-
case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
|
|
442
|
-
case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
|
|
443
|
-
default:
|
|
444
|
-
if (!args) for (j = 1, args = new Array(len -1); j < len; j++) {
|
|
445
|
-
args[j - 1] = arguments[j];
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
listeners[i].fn.apply(listeners[i].context, args);
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
return true;
|
|
454
|
-
};
|
|
455
|
-
|
|
456
|
-
/**
|
|
457
|
-
* Add a listener for a given event.
|
|
458
|
-
*
|
|
459
|
-
* @param {(String|Symbol)} event The event name.
|
|
460
|
-
* @param {Function} fn The listener function.
|
|
461
|
-
* @param {*} [context=this] The context to invoke the listener with.
|
|
462
|
-
* @returns {EventEmitter} `this`.
|
|
463
|
-
* @public
|
|
464
|
-
*/
|
|
465
|
-
EventEmitter.prototype.on = function on(event, fn, context) {
|
|
466
|
-
return addListener(this, event, fn, context, false);
|
|
467
|
-
};
|
|
468
|
-
|
|
469
|
-
/**
|
|
470
|
-
* Add a one-time listener for a given event.
|
|
471
|
-
*
|
|
472
|
-
* @param {(String|Symbol)} event The event name.
|
|
473
|
-
* @param {Function} fn The listener function.
|
|
474
|
-
* @param {*} [context=this] The context to invoke the listener with.
|
|
475
|
-
* @returns {EventEmitter} `this`.
|
|
476
|
-
* @public
|
|
477
|
-
*/
|
|
478
|
-
EventEmitter.prototype.once = function once(event, fn, context) {
|
|
479
|
-
return addListener(this, event, fn, context, true);
|
|
480
|
-
};
|
|
481
|
-
|
|
482
|
-
/**
|
|
483
|
-
* Remove the listeners of a given event.
|
|
484
|
-
*
|
|
485
|
-
* @param {(String|Symbol)} event The event name.
|
|
486
|
-
* @param {Function} fn Only remove the listeners that match this function.
|
|
487
|
-
* @param {*} context Only remove the listeners that have this context.
|
|
488
|
-
* @param {Boolean} once Only remove one-time listeners.
|
|
489
|
-
* @returns {EventEmitter} `this`.
|
|
490
|
-
* @public
|
|
491
|
-
*/
|
|
492
|
-
EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
|
|
493
|
-
var evt = prefix ? prefix + event : event;
|
|
494
|
-
|
|
495
|
-
if (!this._events[evt]) return this;
|
|
496
|
-
if (!fn) {
|
|
497
|
-
clearEvent(this, evt);
|
|
498
|
-
return this;
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
var listeners = this._events[evt];
|
|
502
|
-
|
|
503
|
-
if (listeners.fn) {
|
|
504
|
-
if (
|
|
505
|
-
listeners.fn === fn &&
|
|
506
|
-
(!once || listeners.once) &&
|
|
507
|
-
(!context || listeners.context === context)
|
|
508
|
-
) {
|
|
509
|
-
clearEvent(this, evt);
|
|
510
|
-
}
|
|
511
|
-
} else {
|
|
512
|
-
for (var i = 0, events = [], length = listeners.length; i < length; i++) {
|
|
513
|
-
if (
|
|
514
|
-
listeners[i].fn !== fn ||
|
|
515
|
-
(once && !listeners[i].once) ||
|
|
516
|
-
(context && listeners[i].context !== context)
|
|
517
|
-
) {
|
|
518
|
-
events.push(listeners[i]);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
//
|
|
523
|
-
// Reset the array, or remove it completely if we have no more listeners.
|
|
524
|
-
//
|
|
525
|
-
if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
|
|
526
|
-
else clearEvent(this, evt);
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
return this;
|
|
530
|
-
};
|
|
531
|
-
|
|
532
|
-
/**
|
|
533
|
-
* Remove all listeners, or those of the specified event.
|
|
534
|
-
*
|
|
535
|
-
* @param {(String|Symbol)} [event] The event name.
|
|
536
|
-
* @returns {EventEmitter} `this`.
|
|
537
|
-
* @public
|
|
538
|
-
*/
|
|
539
|
-
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
540
|
-
var evt;
|
|
541
|
-
|
|
542
|
-
if (event) {
|
|
543
|
-
evt = prefix ? prefix + event : event;
|
|
544
|
-
if (this._events[evt]) clearEvent(this, evt);
|
|
545
|
-
} else {
|
|
546
|
-
this._events = new Events();
|
|
547
|
-
this._eventsCount = 0;
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
return this;
|
|
551
|
-
};
|
|
552
|
-
|
|
553
|
-
//
|
|
554
|
-
// Alias methods names because people roll like that.
|
|
555
|
-
//
|
|
556
|
-
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
557
|
-
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
|
|
558
|
-
|
|
559
|
-
//
|
|
560
|
-
// Expose the prefix.
|
|
561
|
-
//
|
|
562
|
-
EventEmitter.prefixed = prefix;
|
|
563
|
-
|
|
564
|
-
//
|
|
565
|
-
// Allow `EventEmitter` to be imported as module namespace.
|
|
566
|
-
//
|
|
567
|
-
EventEmitter.EventEmitter = EventEmitter;
|
|
568
|
-
|
|
569
|
-
//
|
|
570
|
-
// Expose the module.
|
|
571
|
-
//
|
|
572
|
-
{
|
|
573
|
-
module.exports = EventEmitter;
|
|
574
|
-
}
|
|
575
|
-
});
|
|
576
|
-
|
|
577
|
-
var IframeManager = /** @class */ (function () {
|
|
578
|
-
function IframeManager(el) {
|
|
579
|
-
this.sync = false;
|
|
580
|
-
this.events = new eventemitter3();
|
|
581
|
-
this.el = el;
|
|
582
|
-
this.isReady = false;
|
|
583
|
-
}
|
|
584
|
-
IframeManager.prototype.getWindow = function () {
|
|
585
|
-
return this.el.contentWindow;
|
|
586
|
-
};
|
|
587
|
-
IframeManager.prototype.getBridge = function () { };
|
|
588
|
-
IframeManager.prototype.emitSync = function (event) {
|
|
589
|
-
var _a;
|
|
590
|
-
var args = [];
|
|
591
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
592
|
-
args[_i - 1] = arguments[_i];
|
|
593
|
-
}
|
|
594
|
-
this.sync = true;
|
|
595
|
-
(_a = this.events).emit.apply(_a, __spreadArrays([event], args));
|
|
596
|
-
this.sync = false;
|
|
597
|
-
};
|
|
598
|
-
return IframeManager;
|
|
599
|
-
}());
|
|
600
|
-
|
|
601
|
-
var ViewIframeManager = /** @class */ (function (_super) {
|
|
602
|
-
__extends(ViewIframeManager, _super);
|
|
603
|
-
function ViewIframeManager(e) {
|
|
604
|
-
var _this = _super.call(this, e) || this;
|
|
605
|
-
_this.webviewId = null;
|
|
606
|
-
_this.pagePath = '';
|
|
607
|
-
_this.wrapper = null;
|
|
608
|
-
_this.isDestoryed = false;
|
|
609
|
-
_this.active = false;
|
|
610
|
-
_this.isTabView = false;
|
|
611
|
-
return _this;
|
|
612
|
-
}
|
|
613
|
-
ViewIframeManager.prototype.appendContainer = function () {
|
|
614
|
-
var el = this.el;
|
|
615
|
-
el.className = 'webview';
|
|
616
|
-
el.setAttribute('frameborder', '0');
|
|
617
|
-
this.hide();
|
|
618
|
-
var wrapper = document.getElementById('webview-container');
|
|
619
|
-
this.wrapper = wrapper;
|
|
620
|
-
if (wrapper != null) {
|
|
621
|
-
wrapper.appendChild(el);
|
|
622
|
-
}
|
|
623
|
-
};
|
|
624
|
-
ViewIframeManager.prototype.show = function () {
|
|
625
|
-
var el = this.el;
|
|
626
|
-
el.style.zIndex = '2';
|
|
627
|
-
el.style.opacity = '1';
|
|
628
|
-
this.active = true;
|
|
629
|
-
};
|
|
630
|
-
ViewIframeManager.prototype.hide = function () {
|
|
631
|
-
var el = this.el;
|
|
632
|
-
el.style.zIndex = '1';
|
|
633
|
-
el.style.opacity = '0';
|
|
634
|
-
this.active = false;
|
|
635
|
-
};
|
|
636
|
-
ViewIframeManager.prototype.updateWebviewId = function (v) {
|
|
637
|
-
this.webviewId = v;
|
|
638
|
-
this.updateId();
|
|
639
|
-
};
|
|
640
|
-
ViewIframeManager.prototype.updateId = function () {
|
|
641
|
-
this.el.id = "webview-" + this.webviewId;
|
|
642
|
-
};
|
|
643
|
-
ViewIframeManager.prototype.updateSrc = function (pagePath) {
|
|
644
|
-
this.el.src = viewTemplatePath;
|
|
645
|
-
this.pagePath = pagePath;
|
|
646
|
-
};
|
|
647
|
-
ViewIframeManager.prototype.injectScript = function () {
|
|
648
|
-
var _this = this;
|
|
649
|
-
var innerWindow = this.getWindow();
|
|
650
|
-
if (innerWindow != null && this.pagePath != '') {
|
|
651
|
-
var pagePath = this.pagePath.endsWith('.html')
|
|
652
|
-
? this.pagePath
|
|
653
|
-
: this.pagePath + '.html';
|
|
654
|
-
var reqUrl_1 = basePath + pagePath;
|
|
655
|
-
cacheRequest(reqUrl_1, { sync: true }, function (err, data) {
|
|
656
|
-
if (err != null) {
|
|
657
|
-
console.error("init page fail in " + _this.pagePath + ", req: " + reqUrl_1 + " \n " + err);
|
|
658
|
-
}
|
|
659
|
-
else {
|
|
660
|
-
// @ts-ignore
|
|
661
|
-
innerWindow.injectHtml(innerWindow.document.body, {
|
|
662
|
-
content: data
|
|
663
|
-
});
|
|
664
|
-
}
|
|
665
|
-
});
|
|
666
|
-
}
|
|
667
|
-
};
|
|
668
|
-
ViewIframeManager.prototype.getBridge = function () {
|
|
669
|
-
// @ts-ignore
|
|
670
|
-
return this.getWindow().FinChatJSBridge;
|
|
671
|
-
};
|
|
672
|
-
ViewIframeManager.prototype.sendToView = function (event, data) {
|
|
673
|
-
var _this = this;
|
|
674
|
-
if (this.sync) {
|
|
675
|
-
debug && console.log("%c " + event, "color: green;", data, this.webviewId);
|
|
676
|
-
this.getBridge().subscribeHandler(event, data, this.webviewId);
|
|
677
|
-
}
|
|
678
|
-
else {
|
|
679
|
-
// 事件交互 必须异步发送到视图层,不然可能会成闭塞环引发 bug
|
|
680
|
-
setTimeout(function () {
|
|
681
|
-
debug &&
|
|
682
|
-
console.log("%c " + event, "color: green;", data, _this.webviewId);
|
|
683
|
-
_this.getBridge().subscribeHandler(event, data, _this.webviewId);
|
|
684
|
-
});
|
|
685
|
-
}
|
|
686
|
-
};
|
|
687
|
-
ViewIframeManager.prototype.destory = function () {
|
|
688
|
-
if (this.wrapper !== null) {
|
|
689
|
-
this.wrapper.removeChild(this.el);
|
|
690
|
-
// @ts-ignore
|
|
691
|
-
this.el = null;
|
|
692
|
-
this.wrapper = null;
|
|
693
|
-
this.isDestoryed = true;
|
|
694
|
-
this.active = false;
|
|
695
|
-
}
|
|
696
|
-
};
|
|
697
|
-
return ViewIframeManager;
|
|
698
|
-
}(IframeManager));
|
|
699
|
-
|
|
700
|
-
var Router = /** @class */ (function () {
|
|
701
|
-
function Router() {
|
|
702
|
-
this._slotStack = [];
|
|
703
|
-
this._extraStack = [];
|
|
704
|
-
this._slots = [];
|
|
705
|
-
this._webviewId = 0;
|
|
706
|
-
this.rootIndex = 0;
|
|
707
|
-
}
|
|
708
|
-
Object.defineProperty(Router.prototype, "pagePath", {
|
|
709
|
-
get: function () {
|
|
710
|
-
var _a;
|
|
711
|
-
return ((_a = this.currPage) === null || _a === void 0 ? void 0 : _a.pagePath) || null;
|
|
712
|
-
},
|
|
713
|
-
enumerable: false,
|
|
714
|
-
configurable: true
|
|
715
|
-
});
|
|
716
|
-
Object.defineProperty(Router.prototype, "currPage", {
|
|
717
|
-
get: function () {
|
|
718
|
-
return this.stack[this.stack.length - 2] || null;
|
|
719
|
-
},
|
|
720
|
-
enumerable: false,
|
|
721
|
-
configurable: true
|
|
722
|
-
});
|
|
723
|
-
Object.defineProperty(Router.prototype, "top", {
|
|
724
|
-
get: function () {
|
|
725
|
-
return this.stack[this.stack.length - 1];
|
|
726
|
-
},
|
|
727
|
-
enumerable: false,
|
|
728
|
-
configurable: true
|
|
729
|
-
});
|
|
730
|
-
Object.defineProperty(Router.prototype, "stack", {
|
|
731
|
-
get: function () {
|
|
732
|
-
var root = this._slotStack[this.rootIndex];
|
|
733
|
-
if (root == null)
|
|
734
|
-
return [];
|
|
735
|
-
return __spreadArrays([root], this._extraStack);
|
|
736
|
-
},
|
|
737
|
-
enumerable: false,
|
|
738
|
-
configurable: true
|
|
739
|
-
});
|
|
740
|
-
Object.defineProperty(Router.prototype, "allPages", {
|
|
741
|
-
get: function () {
|
|
742
|
-
var root = this._slotStack[this.rootIndex];
|
|
743
|
-
if (root == null)
|
|
744
|
-
return [];
|
|
745
|
-
return __spreadArrays([root], this._extraStack.slice(0, this._extraStack.length - 1));
|
|
746
|
-
},
|
|
747
|
-
enumerable: false,
|
|
748
|
-
configurable: true
|
|
749
|
-
});
|
|
750
|
-
Router.prototype.initFirstPage = function (slots, pagePath) {
|
|
751
|
-
if (!Array.isArray(slots) || slots.length === 0) {
|
|
752
|
-
throw new Error('slots must exist.');
|
|
753
|
-
}
|
|
754
|
-
var targetIndex = findSlotIndex(this, pagePath);
|
|
755
|
-
this._slots = slots;
|
|
756
|
-
for (var i = 0; i < slots.length; i++) {
|
|
757
|
-
var iframe = document.createElement('iframe');
|
|
758
|
-
var viewIfameManager = new ViewIframeManager(iframe);
|
|
759
|
-
viewIfameManager.appendContainer();
|
|
760
|
-
this._slotStack.push(viewIfameManager);
|
|
761
|
-
}
|
|
762
|
-
if (targetIndex > -1) {
|
|
763
|
-
this.rootIndex = targetIndex;
|
|
764
|
-
}
|
|
765
|
-
var first = this._slotStack[this.rootIndex];
|
|
766
|
-
first.updateSrc(pagePath);
|
|
767
|
-
this.initEmptyPage();
|
|
768
|
-
};
|
|
769
|
-
Router.prototype.reinitPages = function (pagePath) {
|
|
770
|
-
var slotStack = this._slotStack;
|
|
771
|
-
var extraStack = this._extraStack;
|
|
772
|
-
slotStack.forEach(function (page) {
|
|
773
|
-
page.destory();
|
|
774
|
-
});
|
|
775
|
-
extraStack.forEach(function (page) {
|
|
776
|
-
page.destory();
|
|
777
|
-
});
|
|
778
|
-
this._slotStack = [];
|
|
779
|
-
this._extraStack = [];
|
|
780
|
-
this.initFirstPage(this._slots, pagePath);
|
|
781
|
-
this.currPage.updateWebviewId(this._webviewId++);
|
|
782
|
-
};
|
|
783
|
-
Router.prototype.reLaunch = function (pagePath) {
|
|
784
|
-
this.reinitPages(pagePath);
|
|
785
|
-
};
|
|
786
|
-
Router.prototype.redirectTo = function (pagePath) {
|
|
787
|
-
var targetIndex = findSlotIndex(this, pagePath);
|
|
788
|
-
if (targetIndex > -1) {
|
|
789
|
-
throw new Error('不允许跳转到 tabbar 页面:' + pagePath);
|
|
790
|
-
}
|
|
791
|
-
var extraStack = this._extraStack;
|
|
792
|
-
if (extraStack.length > 1) {
|
|
793
|
-
var pendingPage = extraStack.pop();
|
|
794
|
-
var currPage = extraStack.pop();
|
|
795
|
-
currPage.destory();
|
|
796
|
-
pendingPage.updateSrc(pagePath);
|
|
797
|
-
pendingPage.updateWebviewId(this._webviewId++);
|
|
798
|
-
extraStack.push(pendingPage);
|
|
799
|
-
this.initEmptyPage();
|
|
800
|
-
}
|
|
801
|
-
else {
|
|
802
|
-
// TODO: 可以优化的方案是 单个replace,而不是全销毁
|
|
803
|
-
var pendingPage = extraStack.pop();
|
|
804
|
-
pendingPage === null || pendingPage === void 0 ? void 0 : pendingPage.destory();
|
|
805
|
-
this._slotStack.forEach(function (page) {
|
|
806
|
-
page.destory();
|
|
807
|
-
});
|
|
808
|
-
this.reinitPages(pagePath);
|
|
809
|
-
}
|
|
810
|
-
};
|
|
811
|
-
Router.prototype.initSlotWebviewId = function (id) {
|
|
812
|
-
this._webviewId = id;
|
|
813
|
-
this._slotStack[this.rootIndex].updateWebviewId(this._webviewId++);
|
|
814
|
-
};
|
|
815
|
-
Router.prototype.initEmptyPage = function () {
|
|
816
|
-
var iframe = document.createElement('iframe');
|
|
817
|
-
var viewIfameManager = new ViewIframeManager(iframe);
|
|
818
|
-
viewIfameManager.appendContainer();
|
|
819
|
-
this._extraStack.push(viewIfameManager);
|
|
820
|
-
};
|
|
821
|
-
Router.prototype.initNextPage = function (page) {
|
|
822
|
-
var curr = this.currPage;
|
|
823
|
-
var pendingPage = this.top;
|
|
824
|
-
curr.hide();
|
|
825
|
-
pendingPage.updateSrc(page);
|
|
826
|
-
pendingPage.updateWebviewId(this._webviewId++);
|
|
827
|
-
this.initEmptyPage();
|
|
828
|
-
return pendingPage;
|
|
829
|
-
};
|
|
830
|
-
Router.prototype.switch = function (page, index) {
|
|
831
|
-
index = index != null ? index : findSlotIndex(this, page);
|
|
832
|
-
var stack = this._slotStack;
|
|
833
|
-
var view = stack[index];
|
|
834
|
-
if (view == null) {
|
|
835
|
-
throw new Error("switchTab url is invalid: " + page);
|
|
836
|
-
}
|
|
837
|
-
this.resetExtraStack();
|
|
838
|
-
stack.forEach(function (page) {
|
|
839
|
-
if (page.isReady) {
|
|
840
|
-
page.hide();
|
|
841
|
-
}
|
|
842
|
-
});
|
|
843
|
-
this.rootIndex = index;
|
|
844
|
-
if (view.isReady) {
|
|
845
|
-
view.show();
|
|
846
|
-
}
|
|
847
|
-
else {
|
|
848
|
-
view.updateWebviewId(this._webviewId++);
|
|
849
|
-
view.updateSrc(page);
|
|
850
|
-
}
|
|
851
|
-
return view;
|
|
852
|
-
};
|
|
853
|
-
Router.prototype.go = function (page) {
|
|
854
|
-
var targetIndex = findSlotIndex(this, page);
|
|
855
|
-
if (targetIndex > -1) {
|
|
856
|
-
return this.switch(page, targetIndex);
|
|
857
|
-
}
|
|
858
|
-
else {
|
|
859
|
-
return this.initNextPage(page);
|
|
860
|
-
}
|
|
861
|
-
};
|
|
862
|
-
Router.prototype.back = function (delta) {
|
|
863
|
-
var _a;
|
|
864
|
-
var extraStack = this._extraStack.slice();
|
|
865
|
-
var pending = extraStack.pop();
|
|
866
|
-
var len = extraStack.length;
|
|
867
|
-
if (delta <= 0) {
|
|
868
|
-
throw new Error('delta 不能 <= 0');
|
|
869
|
-
}
|
|
870
|
-
if (len < delta) {
|
|
871
|
-
throw new Error('delta 不能超过总栈长度:' + (len + 1));
|
|
872
|
-
}
|
|
873
|
-
var gapIndex = len - delta;
|
|
874
|
-
var reaminList = extraStack.slice(0, gapIndex);
|
|
875
|
-
var removeList = extraStack.slice(gapIndex, len);
|
|
876
|
-
removeList.forEach(function (item) {
|
|
877
|
-
item.destory();
|
|
878
|
-
});
|
|
879
|
-
if (reaminList.length > 0) {
|
|
880
|
-
var nestedPage = reaminList[reaminList.length - 1];
|
|
881
|
-
nestedPage.show();
|
|
882
|
-
}
|
|
883
|
-
else {
|
|
884
|
-
(_a = this._slotStack[this.rootIndex]) === null || _a === void 0 ? void 0 : _a.show();
|
|
885
|
-
}
|
|
886
|
-
pending && reaminList.push(pending);
|
|
887
|
-
this._extraStack = reaminList;
|
|
888
|
-
};
|
|
889
|
-
Router.prototype.resetExtraStack = function () {
|
|
890
|
-
if (this._extraStack.length === 0)
|
|
891
|
-
return;
|
|
892
|
-
var pendingPage = this.top;
|
|
893
|
-
this._extraStack.slice(0, this._extraStack.length - 1).forEach(function (page) {
|
|
894
|
-
page.destory();
|
|
895
|
-
});
|
|
896
|
-
this._extraStack = [pendingPage];
|
|
897
|
-
};
|
|
898
|
-
return Router;
|
|
899
|
-
}());
|
|
900
|
-
function findSlotIndex(router, pagePath) {
|
|
901
|
-
var slots = router._slots;
|
|
902
|
-
return slots.findIndex(function (a) { return a === formatPagePath(pagePath); });
|
|
903
|
-
}
|
|
904
|
-
var router = new Router;
|
|
905
|
-
|
|
906
|
-
var ServiceIframeManagerEventNames = {
|
|
907
|
-
'onViewDOMContentLoaded': 'onViewDOMContentLoaded',
|
|
908
|
-
'onInjectHTMLCallback': 'onInjectHTMLCallback',
|
|
909
|
-
};
|
|
910
|
-
var loadedMap = {};
|
|
911
|
-
function isLoadedPackage(root) {
|
|
912
|
-
return loadedMap[root];
|
|
913
|
-
}
|
|
914
|
-
var ServiceIframeManager = /** @class */ (function (_super) {
|
|
915
|
-
__extends(ServiceIframeManager, _super);
|
|
916
|
-
function ServiceIframeManager(e) {
|
|
917
|
-
return _super.call(this, e) || this;
|
|
918
|
-
}
|
|
919
|
-
ServiceIframeManager.prototype.sendToSerivce = function (event, data, webviewId) {
|
|
920
|
-
debug && console.log("%c " + event, "color: blue;", data, webviewId);
|
|
921
|
-
this.getBridge().subscribeHandler(event, data, webviewId);
|
|
922
|
-
};
|
|
923
|
-
// 加载子包
|
|
924
|
-
ServiceIframeManager.prototype.loadSubBundle = function (root, bundlePath) {
|
|
925
|
-
if (loadedMap[root] === true)
|
|
926
|
-
return;
|
|
927
|
-
var innerWindow = this.getWindow();
|
|
928
|
-
if (innerWindow != null) {
|
|
929
|
-
// @ts-ignore
|
|
930
|
-
innerWindow.injectHtml(innerWindow.document.body, {
|
|
931
|
-
content: "<script charset=\"utf-8\" src=\"" + bundlePath + "\"></script>"
|
|
932
|
-
});
|
|
933
|
-
loadedMap[root] = true;
|
|
934
|
-
}
|
|
935
|
-
};
|
|
936
|
-
ServiceIframeManager.prototype.invokeCallbackHandler = function (cbId, data, apiName) {
|
|
937
|
-
debug &&
|
|
938
|
-
console.log("%c " + (apiName || 'API') + " call callback", "color: blue;", cbId, data);
|
|
939
|
-
this.getBridge().invokeCallbackHandler(cbId, data);
|
|
940
|
-
};
|
|
941
|
-
ServiceIframeManager.prototype.getBridge = function () {
|
|
942
|
-
// @ts-ignore
|
|
943
|
-
return this.getWindow().ServiceJSBridge;
|
|
944
|
-
};
|
|
945
|
-
return ServiceIframeManager;
|
|
946
|
-
}(IframeManager));
|
|
947
|
-
|
|
948
|
-
var serviceIframeId = 'webview-service';
|
|
949
|
-
var iframeManagerMap = new Map();
|
|
950
|
-
function getIframeManager(id) {
|
|
951
|
-
var target = iframeManagerMap.get(id);
|
|
952
|
-
if (target)
|
|
953
|
-
return target;
|
|
954
|
-
var iframe = document.getElementById(id);
|
|
955
|
-
if (iframe != null) {
|
|
956
|
-
var Manager = id === serviceIframeId ? ServiceIframeManager : ViewIframeManager;
|
|
957
|
-
var manager = new Manager(iframe);
|
|
958
|
-
iframeManagerMap.set(id, manager);
|
|
959
|
-
return manager;
|
|
960
|
-
}
|
|
961
|
-
throw new Error("\u83B7\u53D6IframeManager\u5931\u8D25, id: " + id);
|
|
962
|
-
}
|
|
963
|
-
function getServiceIframeManager() {
|
|
964
|
-
return getIframeManager(serviceIframeId);
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
function invokeServiceCallbackHandler(cbId, data, apiName) {
|
|
968
|
-
var service = getIframeManager(serviceIframeId);
|
|
969
|
-
service.invokeCallbackHandler(cbId, data, apiName);
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
function dispatchViewEvent(event, data, webviewIds) {
|
|
973
|
-
router.stack.forEach(function (manager) {
|
|
974
|
-
if (manager.webviewId == null)
|
|
975
|
-
return;
|
|
976
|
-
if (webviewIds.indexOf(manager.webviewId) > -1) {
|
|
977
|
-
if (manager.isReady) {
|
|
978
|
-
manager.sendToView(event, data);
|
|
979
|
-
}
|
|
980
|
-
else {
|
|
981
|
-
console.error("shouldn't exctute");
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
});
|
|
985
|
-
}
|
|
986
|
-
function dispatchServiceEvent(event, data, webviewId) {
|
|
987
|
-
var service = getIframeManager(serviceIframeId);
|
|
988
|
-
service.sendToSerivce(event, data, webviewId);
|
|
989
|
-
}
|
|
990
|
-
|
|
991
|
-
var AdapterTarget = null;
|
|
992
|
-
function setTarget(target) {
|
|
993
|
-
AdapterTarget = target;
|
|
994
|
-
}
|
|
995
|
-
function getTarget() {
|
|
996
|
-
return AdapterTarget;
|
|
997
|
-
}
|
|
998
|
-
|
|
999
|
-
var CoreAdapter = /** @class */ (function () {
|
|
1000
|
-
function CoreAdapter() {
|
|
1001
|
-
// SDK 接口调用
|
|
1002
|
-
this._invokeServiceCallbackHandler = invokeServiceCallbackHandler;
|
|
1003
|
-
// 往 ui/逻辑 进程发消息
|
|
1004
|
-
this._dispatchViewEvent = dispatchViewEvent;
|
|
1005
|
-
this._dispatchServiceEvent = dispatchServiceEvent;
|
|
1006
|
-
// 获得当前页面信息,发消息 所需要的 webviewId,可以从这些接口拿
|
|
1007
|
-
this._getCurrentPage = function () {
|
|
1008
|
-
return router.currPage;
|
|
1009
|
-
};
|
|
1010
|
-
this._getAllPages = function () {
|
|
1011
|
-
return router.allPages;
|
|
1012
|
-
};
|
|
1013
|
-
}
|
|
1014
|
-
CoreAdapter.prototype.init = function () {
|
|
1015
|
-
setTarget(this);
|
|
1016
|
-
};
|
|
1017
|
-
return CoreAdapter;
|
|
1018
|
-
}());
|
|
1019
|
-
window.__CoreAdapter = CoreAdapter;
|
|
1020
|
-
|
|
1021
|
-
function toLocalTempFilePath(url) {
|
|
1022
|
-
return url.replace(/^http(s?)\:\/\//, localPathPerfix);
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
|
-
function headersStr2Obj(headers) {
|
|
1026
|
-
var arr = headers.trim().split(/[\r\n]+/);
|
|
1027
|
-
// Create a map of header names to values
|
|
1028
|
-
var headerMap = {};
|
|
1029
|
-
arr.forEach(function (line) {
|
|
1030
|
-
var parts = line.split(": ");
|
|
1031
|
-
var header = parts.shift();
|
|
1032
|
-
var value = parts.join(": ");
|
|
1033
|
-
headerMap[header] = value;
|
|
1034
|
-
});
|
|
1035
|
-
return headerMap;
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
function nextTick(cb) {
|
|
1039
|
-
setTimeout(cb, 17);
|
|
1040
|
-
}
|
|
1041
|
-
|
|
1042
|
-
var fsUtilApis = {
|
|
1043
|
-
readFileSync: function (opts) {
|
|
1044
|
-
var filePath = opts.filePath;
|
|
1045
|
-
// 本地文件 不能通过http请求的,走缓存系统
|
|
1046
|
-
if (filePath.startsWith(localPathPerfix)) {
|
|
1047
|
-
var cache = localStorage.getItem(filePath);
|
|
1048
|
-
if (cache != null) {
|
|
1049
|
-
return { data: cache, errMsg: 'readFileSync:ok' };
|
|
1050
|
-
}
|
|
1051
|
-
else {
|
|
1052
|
-
return { data: null, errMsg: "readFileSync:fail " + filePath + " not exist" };
|
|
1053
|
-
}
|
|
1054
|
-
}
|
|
1055
|
-
filePath = processFilePath(filePath);
|
|
1056
|
-
var rsp = null;
|
|
1057
|
-
var rspErr = null;
|
|
1058
|
-
requestSource(basePath + filePath, { sync: true }, function (err, data) {
|
|
1059
|
-
rsp = data;
|
|
1060
|
-
rspErr = err;
|
|
1061
|
-
});
|
|
1062
|
-
if (rsp != null) {
|
|
1063
|
-
return { data: rsp, errMsg: 'readFileSync:ok' };
|
|
1064
|
-
}
|
|
1065
|
-
else if (rspErr != null) {
|
|
1066
|
-
return {
|
|
1067
|
-
data: null,
|
|
1068
|
-
errMsg: 'readFileSync:fail ' + rspErr.message
|
|
1069
|
-
};
|
|
1070
|
-
}
|
|
1071
|
-
return { data: null, errMsg: 'readFileSync:fail' };
|
|
1072
|
-
},
|
|
1073
|
-
// 异步读取
|
|
1074
|
-
readFile: function (opts, callbackId) {
|
|
1075
|
-
var filePath = opts.filePath, encoding = opts.encoding;
|
|
1076
|
-
var isBase64 = encoding === 'base64';
|
|
1077
|
-
var url = basePath + filePath;
|
|
1078
|
-
if (filePath.startsWith(localPathPerfix)) {
|
|
1079
|
-
nextTick(function () {
|
|
1080
|
-
var result = localStorage.getItem(filePath);
|
|
1081
|
-
if (result != null) {
|
|
1082
|
-
invokeServiceCallbackHandler(callbackId, {
|
|
1083
|
-
data: result,
|
|
1084
|
-
errMsg: 'readFile:ok'
|
|
1085
|
-
});
|
|
1086
|
-
}
|
|
1087
|
-
else {
|
|
1088
|
-
invokeServiceCallbackHandler(callbackId, {
|
|
1089
|
-
errMsg: "readFile:fail " + filePath + " is not existed"
|
|
1090
|
-
});
|
|
1091
|
-
}
|
|
1092
|
-
});
|
|
1093
|
-
return;
|
|
1094
|
-
}
|
|
1095
|
-
requestSource(url, {
|
|
1096
|
-
responseType: isBase64 ? 'arraybuffer' : ''
|
|
1097
|
-
}, function (err, data) {
|
|
1098
|
-
if (err != null) {
|
|
1099
|
-
invokeServiceCallbackHandler(callbackId, {
|
|
1100
|
-
errMsg: 'readFile:fail ' + err.message
|
|
1101
|
-
});
|
|
1102
|
-
return;
|
|
1103
|
-
}
|
|
1104
|
-
invokeServiceCallbackHandler(callbackId, {
|
|
1105
|
-
data: isBase64 ? arrayBufferToBase64(data) : data,
|
|
1106
|
-
errMsg: 'readFile:ok'
|
|
1107
|
-
});
|
|
1108
|
-
});
|
|
1109
|
-
},
|
|
1110
|
-
// 文件是否存在
|
|
1111
|
-
access: function () {
|
|
1112
|
-
return { errMsg: 'access:ok' };
|
|
1113
|
-
},
|
|
1114
|
-
mkdirSync: function () {
|
|
1115
|
-
return { errMsg: 'mkdirSync:ok' };
|
|
1116
|
-
},
|
|
1117
|
-
writeFileSync: function (_a) {
|
|
1118
|
-
var filePath = _a.filePath, data = _a.data;
|
|
1119
|
-
// 缓存模拟文件系统
|
|
1120
|
-
localStorage.setItem(filePath, data);
|
|
1121
|
-
return { errMsg: 'writeFileSync:ok' };
|
|
1122
|
-
},
|
|
1123
|
-
unlink: function (_a, callbackId) {
|
|
1124
|
-
var filePath = _a.filePath;
|
|
1125
|
-
nextTick(function () {
|
|
1126
|
-
localStorage.removeItem(filePath);
|
|
1127
|
-
invokeServiceCallbackHandler(callbackId, {
|
|
1128
|
-
errMsg: 'unlink:ok'
|
|
1129
|
-
});
|
|
1130
|
-
});
|
|
1131
|
-
},
|
|
1132
|
-
downloadFile: function (_a, callbackId) {
|
|
1133
|
-
var url = _a.url, _b = _a.timeout, timeout = _b === void 0 ? 6000 : _b; _a.taskId; _a.header; _a.filePath;
|
|
1134
|
-
promiseTimeout(timeout, doDownload({
|
|
1135
|
-
url: url,
|
|
1136
|
-
callbackId: callbackId
|
|
1137
|
-
}), function (ms) {
|
|
1138
|
-
invokeServiceCallbackHandler(callbackId, {
|
|
1139
|
-
errMsg: "downloadFile:fail timeout in " + ms + "ms."
|
|
1140
|
-
});
|
|
1141
|
-
});
|
|
1142
|
-
}
|
|
1143
|
-
};
|
|
1144
|
-
function doDownload(_a) {
|
|
1145
|
-
var url = _a.url, callbackId = _a.callbackId, filePath = _a.filePath, header = _a.header;
|
|
1146
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1147
|
-
return __generator(this, function (_b) {
|
|
1148
|
-
requestSource(url, { header: header }, function (err, data, info) {
|
|
1149
|
-
var e = info.e, xhr = info.xhr;
|
|
1150
|
-
if (err != null) {
|
|
1151
|
-
invokeServiceCallbackHandler(callbackId, {
|
|
1152
|
-
errMsg: 'downloadFile:fail ' + err.message
|
|
1153
|
-
});
|
|
1154
|
-
return;
|
|
1155
|
-
}
|
|
1156
|
-
// 格式化
|
|
1157
|
-
var tempFilePath = toLocalTempFilePath(url);
|
|
1158
|
-
var usedFilePath = filePath || tempFilePath;
|
|
1159
|
-
localStorage.setItem(usedFilePath, data);
|
|
1160
|
-
var rspHeaders = xhr.getAllResponseHeaders();
|
|
1161
|
-
var headerMap = headersStr2Obj(rspHeaders);
|
|
1162
|
-
var rspCookies = (headerMap['set-cookie'] || '').split(',');
|
|
1163
|
-
// 推送两个事件
|
|
1164
|
-
dispatchServiceEvent(onTaskProgressUpdate, {
|
|
1165
|
-
cookies: [],
|
|
1166
|
-
progress: 100,
|
|
1167
|
-
totalBytesExpectedToWrite: e.loaded,
|
|
1168
|
-
totalBytesWritten: e.loaded
|
|
1169
|
-
});
|
|
1170
|
-
dispatchServiceEvent(onTaskHeadersReceived, {
|
|
1171
|
-
cookies: rspCookies,
|
|
1172
|
-
header: headerMap
|
|
1173
|
-
});
|
|
1174
|
-
var processedTempFilePath = processTempFilePath(tempFilePath, url);
|
|
1175
|
-
invokeServiceCallbackHandler(callbackId, {
|
|
1176
|
-
filePath: filePath,
|
|
1177
|
-
tempFilePath: filePath ? undefined : processedTempFilePath,
|
|
1178
|
-
profile: [],
|
|
1179
|
-
statusCode: 200,
|
|
1180
|
-
errMsg: 'downloadFile:ok'
|
|
1181
|
-
});
|
|
1182
|
-
});
|
|
1183
|
-
return [2 /*return*/];
|
|
1184
|
-
});
|
|
1185
|
-
});
|
|
1186
|
-
}
|
|
1187
|
-
function processTempFilePath(tempFilePath, url) {
|
|
1188
|
-
var arr = tempFilePath.split('.');
|
|
1189
|
-
var suffix = arr[arr.length - 1];
|
|
1190
|
-
if (imgSets.has('.' + suffix)) {
|
|
1191
|
-
return url;
|
|
1192
|
-
}
|
|
1193
|
-
return tempFilePath;
|
|
1194
|
-
}
|
|
1195
|
-
|
|
1196
|
-
var globalApis = {
|
|
1197
|
-
getGlobalVariables: function (data) {
|
|
1198
|
-
var variable = data.variable;
|
|
1199
|
-
if (variable === '_launchOption') {
|
|
1200
|
-
// 先写死
|
|
1201
|
-
return {
|
|
1202
|
-
_launchOption: launchOption
|
|
1203
|
-
};
|
|
1204
|
-
}
|
|
1205
|
-
return null;
|
|
1206
|
-
},
|
|
1207
|
-
// 上报的
|
|
1208
|
-
reportApmMonitor: function (data) { },
|
|
1209
|
-
addPerformance: function () { },
|
|
1210
|
-
// dom渲染完成
|
|
1211
|
-
// 这里关闭加载遮罩
|
|
1212
|
-
initReady: function () {
|
|
1213
|
-
//
|
|
1214
|
-
},
|
|
1215
|
-
updateAppData: function () { },
|
|
1216
|
-
injectHtmlCallback: function (data, cbId, from) {
|
|
1217
|
-
if (from === 'service') {
|
|
1218
|
-
getServiceIframeManager().events.emit(ServiceIframeManagerEventNames.onInjectHTMLCallback);
|
|
1219
|
-
}
|
|
1220
|
-
},
|
|
1221
|
-
pageScrollTo: function (opts, callbackId) {
|
|
1222
|
-
var scrollTop = opts.scrollTop; opts.duration;
|
|
1223
|
-
var curPage = router.currPage;
|
|
1224
|
-
var innerW = curPage.getWindow();
|
|
1225
|
-
innerW === null || innerW === void 0 ? void 0 : innerW.scrollTo({
|
|
1226
|
-
top: scrollTop,
|
|
1227
|
-
behavior: "smooth",
|
|
1228
|
-
});
|
|
1229
|
-
return {
|
|
1230
|
-
errMsg: 'pageScrollTo:ok'
|
|
1231
|
-
};
|
|
1232
|
-
}
|
|
1233
|
-
};
|
|
1234
|
-
|
|
1235
|
-
var wxConfig = null;
|
|
1236
|
-
function setWxConfig(v) {
|
|
1237
|
-
wxConfig = v;
|
|
1238
|
-
}
|
|
1239
|
-
function getWxConfig() {
|
|
1240
|
-
if (wxConfig == null) {
|
|
1241
|
-
throw new Error("WxConfig is not ready.");
|
|
1242
|
-
}
|
|
1243
|
-
return wxConfig;
|
|
1244
|
-
}
|
|
1245
|
-
|
|
1246
|
-
var WebFrameEventBus = new eventemitter3();
|
|
1247
|
-
function emitAppDataChangeEvent(params) {
|
|
1248
|
-
var payload = __assign({}, params.data);
|
|
1249
|
-
var wxConfig = getWxConfig();
|
|
1250
|
-
var currPath = payload.options.path;
|
|
1251
|
-
var pages = wxConfig.windows.pages;
|
|
1252
|
-
if (pages != null && pages[currPath]) {
|
|
1253
|
-
payload.windowConfig = pages[currPath];
|
|
1254
|
-
}
|
|
1255
|
-
payload.pages = router.allPages;
|
|
1256
|
-
WebFrameEventBus.emit('appDataChange', payload);
|
|
1257
|
-
}
|
|
1258
|
-
function emitUpdateAppDataEvent() {
|
|
1259
|
-
var payload = {};
|
|
1260
|
-
var wxConfig = getWxConfig();
|
|
1261
|
-
var currPage = router.currPage;
|
|
1262
|
-
var currPath = currPage.pagePath.replace(/\.html$/, '');
|
|
1263
|
-
var pages = wxConfig.windows.pages;
|
|
1264
|
-
if (pages != null && pages[currPath]) {
|
|
1265
|
-
payload.windowConfig = pages[currPath];
|
|
1266
|
-
}
|
|
1267
|
-
payload.pages = router.allPages;
|
|
1268
|
-
payload.currPage = currPath;
|
|
1269
|
-
WebFrameEventBus.emit('updateAppData', payload);
|
|
1270
|
-
}
|
|
1271
|
-
function emitTabItemChangedEvent(pagePath) {
|
|
1272
|
-
var payload = {};
|
|
1273
|
-
var wxConfig = getWxConfig();
|
|
1274
|
-
var currPath = pagePath;
|
|
1275
|
-
var pages = wxConfig.windows.pages;
|
|
1276
|
-
if (pages != null && pages[currPath]) {
|
|
1277
|
-
payload.windowConfig = pages[currPath];
|
|
1278
|
-
}
|
|
1279
|
-
WebFrameEventBus.emit('tabItemChanged', payload);
|
|
1280
|
-
}
|
|
1281
|
-
function initWebFrame(config) {
|
|
1282
|
-
if (typeof window.__initWebFrame === 'undefined')
|
|
1283
|
-
return;
|
|
1284
|
-
WebFrameEventBus.on('NavigatorBarTools:onMore', function () {
|
|
1285
|
-
console.log('onMore');
|
|
1286
|
-
});
|
|
1287
|
-
WebFrameEventBus.on('NavigatorBarTools:onClose', function () {
|
|
1288
|
-
console.log('onClose');
|
|
1289
|
-
});
|
|
1290
|
-
WebFrameEventBus.on('NavigatorBar:onBack', function () {
|
|
1291
|
-
routeApis.navigateBack({ delta: 1 });
|
|
1292
|
-
console.log('onBack');
|
|
1293
|
-
});
|
|
1294
|
-
WebFrameEventBus.on('TabBar:change', function (data) {
|
|
1295
|
-
dispatchServiceEvent('onTabItemTap', {
|
|
1296
|
-
index: data.index,
|
|
1297
|
-
pagePath: data.item.pagePath,
|
|
1298
|
-
text: data.item.text
|
|
1299
|
-
});
|
|
1300
|
-
routeApis.switchTab({ url: data.item.pagePath }, -1);
|
|
1301
|
-
emitTabItemChangedEvent(data.item.pagePath);
|
|
1302
|
-
});
|
|
1303
|
-
WebFrameEventBus.on('invokeCallbackHandler', function (payload) {
|
|
1304
|
-
invokeServiceCallbackHandler(payload.callbackId, payload.data);
|
|
1305
|
-
});
|
|
1306
|
-
//
|
|
1307
|
-
window.__initWebFrame(config, WebFrameEventBus);
|
|
1308
|
-
}
|
|
1309
|
-
|
|
1310
|
-
var interactionApis = {
|
|
1311
|
-
hideToast: function (opts) {
|
|
1312
|
-
WebFrameEventBus.emit('hideToast', opts);
|
|
1313
|
-
return { errMsg: 'hideToast:ok' };
|
|
1314
|
-
},
|
|
1315
|
-
showToast: function (opts) {
|
|
1316
|
-
WebFrameEventBus.emit('showToast', opts);
|
|
1317
|
-
return { errMsg: 'showToast:ok' };
|
|
1318
|
-
},
|
|
1319
|
-
showLoading: function (opts) {
|
|
1320
|
-
WebFrameEventBus.emit('showLoading', opts);
|
|
1321
|
-
return { errMsg: 'showLoading:ok' };
|
|
1322
|
-
},
|
|
1323
|
-
hideLoading: function (opts) {
|
|
1324
|
-
WebFrameEventBus.emit('hideLoading', opts);
|
|
1325
|
-
return { errMsg: 'hideLoading:ok' };
|
|
1326
|
-
},
|
|
1327
|
-
showModal: function (opts, callbackId) {
|
|
1328
|
-
WebFrameEventBus.emit('showModal', opts, callbackId);
|
|
1329
|
-
},
|
|
1330
|
-
showActionSheet: function (opts, callbackId) {
|
|
1331
|
-
WebFrameEventBus.emit('showActionSheet', opts, callbackId);
|
|
1332
|
-
}
|
|
1333
|
-
};
|
|
1334
|
-
|
|
1335
|
-
var LoadSubPackageTaskManager = /** @class */ (function () {
|
|
1336
|
-
function LoadSubPackageTaskManager(opts) {
|
|
1337
|
-
this.taskId = opts.taskId;
|
|
1338
|
-
this.moduleName = opts.moduleName;
|
|
1339
|
-
this.projectType = opts.projectType;
|
|
1340
|
-
this.status = 'none';
|
|
1341
|
-
}
|
|
1342
|
-
LoadSubPackageTaskManager.prototype.notifyProgressUpdate = function (state, extra) {
|
|
1343
|
-
dispatchServiceEvent(onLoadSubPackageTaskStateChange, __assign({ moduleName: this.moduleName, state: state, taskId: this.taskId }, extra));
|
|
1344
|
-
};
|
|
1345
|
-
LoadSubPackageTaskManager.prototype.injectScript = function () { };
|
|
1346
|
-
LoadSubPackageTaskManager.prototype.getEntry = function () { };
|
|
1347
|
-
LoadSubPackageTaskManager.prototype.load = function () {
|
|
1348
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1349
|
-
return __generator(this, function (_a) {
|
|
1350
|
-
switch (_a.label) {
|
|
1351
|
-
case 0:
|
|
1352
|
-
this.notifyProgressUpdate('progressUpdate', { progress: 0 });
|
|
1353
|
-
return [4 /*yield*/, delay(15)
|
|
1354
|
-
// 这部分是解压的
|
|
1355
|
-
];
|
|
1356
|
-
case 1:
|
|
1357
|
-
_a.sent();
|
|
1358
|
-
// 这部分是解压的
|
|
1359
|
-
this.notifyProgressUpdate('progressUpdate', { progress: 50 });
|
|
1360
|
-
return [4 /*yield*/, delay(30)
|
|
1361
|
-
// 这部分是插入脚本
|
|
1362
|
-
];
|
|
1363
|
-
case 2:
|
|
1364
|
-
_a.sent();
|
|
1365
|
-
// 这部分是插入脚本
|
|
1366
|
-
this.injectScript();
|
|
1367
|
-
this.notifyProgressUpdate('progressUpdate', { progress: 100 });
|
|
1368
|
-
return [4 /*yield*/, delay(15)
|
|
1369
|
-
// 提示完成
|
|
1370
|
-
];
|
|
1371
|
-
case 3:
|
|
1372
|
-
_a.sent();
|
|
1373
|
-
// 提示完成
|
|
1374
|
-
this.status = 'success';
|
|
1375
|
-
this.notifyProgressUpdate('success', {
|
|
1376
|
-
entryPath: this.getEntry()
|
|
1377
|
-
});
|
|
1378
|
-
return [2 /*return*/];
|
|
1379
|
-
}
|
|
1380
|
-
});
|
|
1381
|
-
});
|
|
1382
|
-
};
|
|
1383
|
-
return LoadSubPackageTaskManager;
|
|
1384
|
-
}());
|
|
1385
|
-
|
|
1386
|
-
function generateScriptContent(projectType, opts) {
|
|
1387
|
-
if (projectType === miniGame) {
|
|
1388
|
-
return "<script charset=\"utf-8\" src=\"" + opts.moduleName + "game.js\"></script>";
|
|
1389
|
-
}
|
|
1390
|
-
if (projectType === miniProgram) {
|
|
1391
|
-
return opts.content;
|
|
1392
|
-
}
|
|
1393
|
-
throw Error('unsupported projectType: ' + projectType);
|
|
1394
|
-
}
|
|
1395
|
-
function generateEntryPath(projectType, opts) {
|
|
1396
|
-
if (projectType === miniGame) {
|
|
1397
|
-
return opts.moduleName + "game.js";
|
|
1398
|
-
}
|
|
1399
|
-
return '';
|
|
1400
|
-
}
|
|
1401
|
-
|
|
1402
|
-
var LoadGameSubPackageTaskManager = /** @class */ (function (_super) {
|
|
1403
|
-
__extends(LoadGameSubPackageTaskManager, _super);
|
|
1404
|
-
function LoadGameSubPackageTaskManager(opts) {
|
|
1405
|
-
return _super.call(this, __assign(__assign({}, opts), { projectType: miniGame })) || this;
|
|
1406
|
-
}
|
|
1407
|
-
LoadGameSubPackageTaskManager.prototype.injectScript = function () {
|
|
1408
|
-
var serviceFrameManager = getIframeManager(serviceIframeId);
|
|
1409
|
-
var innerWindow = serviceFrameManager.getWindow();
|
|
1410
|
-
innerWindow.injectHtml(innerWindow.document.body, {
|
|
1411
|
-
content: generateScriptContent(this.projectType, {
|
|
1412
|
-
moduleName: this.moduleName
|
|
1413
|
-
})
|
|
1414
|
-
});
|
|
1415
|
-
};
|
|
1416
|
-
LoadGameSubPackageTaskManager.prototype.getEntry = function () {
|
|
1417
|
-
return generateEntryPath(this.projectType, {
|
|
1418
|
-
moduleName: this.moduleName
|
|
1419
|
-
});
|
|
1420
|
-
};
|
|
1421
|
-
return LoadGameSubPackageTaskManager;
|
|
1422
|
-
}(LoadSubPackageTaskManager));
|
|
1423
|
-
|
|
1424
|
-
var taskId = 0;
|
|
1425
|
-
var taskManagerMap = {};
|
|
1426
|
-
var loadSubpackageApis = {
|
|
1427
|
-
// 游戏分包特有的加载接口
|
|
1428
|
-
createLoadSubPackageTask: function (_a) {
|
|
1429
|
-
var moduleName = _a.moduleName;
|
|
1430
|
-
var manager = taskManagerMap[moduleName];
|
|
1431
|
-
if (manager && manager.status === 'success') {
|
|
1432
|
-
return {
|
|
1433
|
-
errMsg: 'createLoadSubPackageTask:fail sub package already loaded.'
|
|
1434
|
-
};
|
|
1435
|
-
}
|
|
1436
|
-
++taskId;
|
|
1437
|
-
var taskIdStr = String(taskId);
|
|
1438
|
-
manager = new LoadGameSubPackageTaskManager({ taskId: taskIdStr, moduleName: moduleName });
|
|
1439
|
-
taskManagerMap[moduleName] = manager;
|
|
1440
|
-
manager.load();
|
|
1441
|
-
return {
|
|
1442
|
-
errMsg: 'createLoadSubPackageTask:ok',
|
|
1443
|
-
loadTaskId: taskIdStr
|
|
1444
|
-
};
|
|
1445
|
-
}
|
|
1446
|
-
};
|
|
1447
|
-
|
|
1448
|
-
var navApis = {
|
|
1449
|
-
showNavigationBarLoading: function () {
|
|
1450
|
-
WebFrameEventBus.emit('showNavigationBarLoading');
|
|
1451
|
-
return {
|
|
1452
|
-
errMsg: "showNavigationBarLoading:ok"
|
|
1453
|
-
};
|
|
1454
|
-
},
|
|
1455
|
-
setNavigationBarTitle: function (opts) {
|
|
1456
|
-
WebFrameEventBus.emit('setNavigationBarTitle', opts);
|
|
1457
|
-
return {
|
|
1458
|
-
errMsg: "setNavigationBarTitle:ok"
|
|
1459
|
-
};
|
|
1460
|
-
},
|
|
1461
|
-
setNavigationBarColor: function (opts) {
|
|
1462
|
-
WebFrameEventBus.emit('setNavigationBarColor', opts);
|
|
1463
|
-
return {
|
|
1464
|
-
errMsg: "setNavigationBarColor:ok"
|
|
1465
|
-
};
|
|
1466
|
-
},
|
|
1467
|
-
hideNavigationBarLoading: function () {
|
|
1468
|
-
WebFrameEventBus.emit('hideNavigationBarLoading');
|
|
1469
|
-
return {
|
|
1470
|
-
errMsg: "hideNavigationBarLoading:ok"
|
|
1471
|
-
};
|
|
1472
|
-
},
|
|
1473
|
-
hideHomeButton: function () {
|
|
1474
|
-
}
|
|
1475
|
-
};
|
|
1476
|
-
|
|
1477
|
-
// TODO: 已经加载的子包 不需要加载
|
|
1478
|
-
function ensureBundleLoaded(request, done) {
|
|
1479
|
-
var subPackageInfo = tryFindSubPackageInfo(request);
|
|
1480
|
-
if (subPackageInfo != null && !isLoadedPackage(subPackageInfo.root)) {
|
|
1481
|
-
loadSubPackage(subPackageInfo, done);
|
|
1482
|
-
}
|
|
1483
|
-
else {
|
|
1484
|
-
done();
|
|
1485
|
-
}
|
|
1486
|
-
}
|
|
1487
|
-
function tryFindSubPackageInfo(path) {
|
|
1488
|
-
path = path.replace(/\.html$/, '');
|
|
1489
|
-
var wxConfig = getWxConfig();
|
|
1490
|
-
var subPackages = wxConfig.subpackages;
|
|
1491
|
-
if (Array.isArray(subPackages) && subPackages.length > 0) {
|
|
1492
|
-
return subPackages.find(function (item) {
|
|
1493
|
-
return item.pageFullPath.includes(path);
|
|
1494
|
-
});
|
|
1495
|
-
}
|
|
1496
|
-
return null;
|
|
1497
|
-
}
|
|
1498
|
-
function loadSubPackage(subPackageInfo, done) {
|
|
1499
|
-
var service = getIframeManager(serviceIframeId);
|
|
1500
|
-
service.events.once(ServiceIframeManagerEventNames.onInjectHTMLCallback, done);
|
|
1501
|
-
service.loadSubBundle(subPackageInfo.root, subPackageInfo.packageName + '.js');
|
|
1502
|
-
}
|
|
1503
|
-
function getSlots(wxConfig) {
|
|
1504
|
-
var tabBarConfig = wxConfig.tabBar;
|
|
1505
|
-
if (tabBarConfig == null) {
|
|
1506
|
-
return [wxConfig.root];
|
|
1507
|
-
}
|
|
1508
|
-
else {
|
|
1509
|
-
var tabList = tabBarConfig.list || [];
|
|
1510
|
-
if (tabList.length === 0) {
|
|
1511
|
-
return [wxConfig.root];
|
|
1512
|
-
}
|
|
1513
|
-
return tabBarConfig.list.map(function (item) { return item.pagePath; });
|
|
1514
|
-
}
|
|
1515
|
-
}
|
|
1516
|
-
function initFirstPageByWxConfig(wxConfig) {
|
|
1517
|
-
var slots = getSlots(wxConfig);
|
|
1518
|
-
router.initFirstPage(slots, wxConfig.root);
|
|
1519
|
-
}
|
|
1520
|
-
|
|
1521
|
-
var routeApis = {
|
|
1522
|
-
navigateTo: function (_a, callbackId) {
|
|
1523
|
-
var url = _a.url;
|
|
1524
|
-
if (router.stack.length > 10) {
|
|
1525
|
-
return {
|
|
1526
|
-
errMsg: 'navigateTo:fail 已到达页面栈上限:10。'
|
|
1527
|
-
};
|
|
1528
|
-
}
|
|
1529
|
-
var _b = resolveUrl(url), path = _b.path, query = _b.query;
|
|
1530
|
-
ensureBundleLoaded(path, function () {
|
|
1531
|
-
var nextPage = router.go(path);
|
|
1532
|
-
getServiceIframeManager().events.once(ServiceIframeManagerEventNames.onViewDOMContentLoaded, function () {
|
|
1533
|
-
dispatchServiceEvent('onAppRoute', {
|
|
1534
|
-
path: path,
|
|
1535
|
-
openType: 'navigateTo',
|
|
1536
|
-
options: undefined,
|
|
1537
|
-
pipMode: '',
|
|
1538
|
-
query: query,
|
|
1539
|
-
webviewId: nextPage.webviewId
|
|
1540
|
-
}, nextPage.webviewId);
|
|
1541
|
-
});
|
|
1542
|
-
});
|
|
1543
|
-
return { errMsg: 'navigateTo:ok' };
|
|
1544
|
-
},
|
|
1545
|
-
navigateBack: function (_a) {
|
|
1546
|
-
var delta = _a.delta;
|
|
1547
|
-
try {
|
|
1548
|
-
router.back(delta);
|
|
1549
|
-
}
|
|
1550
|
-
catch (error) {
|
|
1551
|
-
return {
|
|
1552
|
-
errMsg: "navigateBack:fail " + error.message
|
|
1553
|
-
};
|
|
1554
|
-
}
|
|
1555
|
-
var currPage = router.currPage;
|
|
1556
|
-
dispatchServiceEvent('onAppRoute', {
|
|
1557
|
-
path: currPage.pagePath,
|
|
1558
|
-
openType: 'navigateBack',
|
|
1559
|
-
options: { delta: delta },
|
|
1560
|
-
pipMode: '',
|
|
1561
|
-
query: undefined,
|
|
1562
|
-
webviewId: currPage.webviewId
|
|
1563
|
-
}, currPage.webviewId);
|
|
1564
|
-
// 不是异步 可以直接返回结果
|
|
1565
|
-
return { errMsg: 'navigateBack:ok' };
|
|
1566
|
-
},
|
|
1567
|
-
reLaunch: function (_a, cbId) {
|
|
1568
|
-
var url = _a.url;
|
|
1569
|
-
var _b = resolveUrl(url), path = _b.path, query = _b.query;
|
|
1570
|
-
ensureBundleLoaded(path, function () {
|
|
1571
|
-
router.reLaunch(url);
|
|
1572
|
-
var currPage = router.currPage;
|
|
1573
|
-
getServiceIframeManager().events.once(ServiceIframeManagerEventNames.onViewDOMContentLoaded, function () {
|
|
1574
|
-
dispatchServiceEvent('onAppRoute', {
|
|
1575
|
-
path: path,
|
|
1576
|
-
openType: 'reLaunch',
|
|
1577
|
-
options: undefined,
|
|
1578
|
-
pipMode: '',
|
|
1579
|
-
query: query,
|
|
1580
|
-
webviewId: currPage.webviewId
|
|
1581
|
-
}, currPage.webviewId);
|
|
1582
|
-
invokeServiceCallbackHandler(cbId, {
|
|
1583
|
-
errMsg: 'reLaunch:ok'
|
|
1584
|
-
});
|
|
1585
|
-
});
|
|
1586
|
-
});
|
|
1587
|
-
},
|
|
1588
|
-
redirectTo: function (_a, callbackId) {
|
|
1589
|
-
var url = _a.url;
|
|
1590
|
-
// 不允许跳转到 tabbar 页面
|
|
1591
|
-
var _b = resolveUrl(url), path = _b.path, query = _b.query;
|
|
1592
|
-
ensureBundleLoaded(path, function () {
|
|
1593
|
-
try {
|
|
1594
|
-
router.redirectTo(path);
|
|
1595
|
-
}
|
|
1596
|
-
catch (error) {
|
|
1597
|
-
invokeServiceCallbackHandler(callbackId, {
|
|
1598
|
-
errMsg: "redirectTo:fail " + error.message
|
|
1599
|
-
});
|
|
1600
|
-
return;
|
|
1601
|
-
}
|
|
1602
|
-
var currPage = router.currPage;
|
|
1603
|
-
getServiceIframeManager().events.once(ServiceIframeManagerEventNames.onViewDOMContentLoaded, function () {
|
|
1604
|
-
dispatchServiceEvent('onAppRoute', {
|
|
1605
|
-
path: path,
|
|
1606
|
-
openType: 'redirectTo',
|
|
1607
|
-
options: undefined,
|
|
1608
|
-
pipMode: '',
|
|
1609
|
-
query: query,
|
|
1610
|
-
webviewId: currPage.webviewId
|
|
1611
|
-
}, currPage.webviewId);
|
|
1612
|
-
invokeServiceCallbackHandler(callbackId, {
|
|
1613
|
-
errMsg: 'redirectTo:ok'
|
|
1614
|
-
});
|
|
1615
|
-
});
|
|
1616
|
-
});
|
|
1617
|
-
},
|
|
1618
|
-
switchTab: function (_a, callbackId) {
|
|
1619
|
-
var url = _a.url;
|
|
1620
|
-
var _b = resolveUrl(url), path = _b.path, query = _b.query;
|
|
1621
|
-
ensureBundleLoaded(path, function () {
|
|
1622
|
-
try {
|
|
1623
|
-
router.switch(path);
|
|
1624
|
-
}
|
|
1625
|
-
catch (error) {
|
|
1626
|
-
invokeServiceCallbackHandler(callbackId, {
|
|
1627
|
-
errMsg: "switchTab:fail " + error.message
|
|
1628
|
-
});
|
|
1629
|
-
return;
|
|
1630
|
-
}
|
|
1631
|
-
var currPage = router.currPage;
|
|
1632
|
-
if (currPage.isReady) {
|
|
1633
|
-
dispatchServiceEvent('onAppRoute', {
|
|
1634
|
-
path: path,
|
|
1635
|
-
openType: 'switchTab',
|
|
1636
|
-
options: undefined,
|
|
1637
|
-
pipMode: '',
|
|
1638
|
-
query: query,
|
|
1639
|
-
webviewId: currPage.webviewId
|
|
1640
|
-
}, currPage.webviewId);
|
|
1641
|
-
invokeServiceCallbackHandler(callbackId, {
|
|
1642
|
-
errMsg: 'switchTab:ok'
|
|
1643
|
-
});
|
|
1644
|
-
}
|
|
1645
|
-
else {
|
|
1646
|
-
getServiceIframeManager().events.once(ServiceIframeManagerEventNames.onViewDOMContentLoaded, function () {
|
|
1647
|
-
dispatchServiceEvent('onAppRoute', {
|
|
1648
|
-
path: path,
|
|
1649
|
-
openType: 'switchTab',
|
|
1650
|
-
options: undefined,
|
|
1651
|
-
pipMode: '',
|
|
1652
|
-
query: query,
|
|
1653
|
-
webviewId: currPage.webviewId
|
|
1654
|
-
}, currPage.webviewId);
|
|
1655
|
-
invokeServiceCallbackHandler(callbackId, {
|
|
1656
|
-
errMsg: 'switchTab:ok'
|
|
1657
|
-
});
|
|
1658
|
-
});
|
|
1659
|
-
}
|
|
1660
|
-
});
|
|
1661
|
-
}
|
|
1662
|
-
};
|
|
1663
|
-
|
|
1664
|
-
var localStorageApis = {
|
|
1665
|
-
getStorageSync: function (opts) {
|
|
1666
|
-
var res = localStorage.getItem(opts.key);
|
|
1667
|
-
try {
|
|
1668
|
-
// @ts-expect-error
|
|
1669
|
-
return JSON.parse(res);
|
|
1670
|
-
}
|
|
1671
|
-
catch (error) {
|
|
1672
|
-
return res;
|
|
1673
|
-
}
|
|
1674
|
-
},
|
|
1675
|
-
setStorageSync: function (opts) {
|
|
1676
|
-
localStorage.setItem(opts.key, opts.data);
|
|
1677
|
-
return { errMsg: 'setStorageSync:ok' };
|
|
1678
|
-
},
|
|
1679
|
-
removeStorageSync: function (opts) {
|
|
1680
|
-
localStorage.removeItem(opts.key);
|
|
1681
|
-
return { errMsg: 'removeStorageSync:ok' };
|
|
1682
|
-
}
|
|
1683
|
-
};
|
|
1684
|
-
|
|
1685
|
-
function getCurrentDeviceOrientation() {
|
|
1686
|
-
var system = getSystem();
|
|
1687
|
-
if (system === 'Android' || system === 'IOS') {
|
|
1688
|
-
return window.matchMedia('(orientation: portrait)').matches
|
|
1689
|
-
? 'portrait'
|
|
1690
|
-
: 'landscape';
|
|
1691
|
-
}
|
|
1692
|
-
// web
|
|
1693
|
-
return 'landscape';
|
|
1694
|
-
}
|
|
1695
|
-
|
|
1696
|
-
var system = {
|
|
1697
|
-
onMemoryWarning: function () {
|
|
1698
|
-
console.error('The onMemoryWarning api is not implement.');
|
|
1699
|
-
},
|
|
1700
|
-
showShareMenu: function () {
|
|
1701
|
-
console.error('The showShareMenu api is not implement.');
|
|
1702
|
-
},
|
|
1703
|
-
getSystemInfoSync: function () {
|
|
1704
|
-
var resolutionRatio = 750; // 这个要通过原生注入
|
|
1705
|
-
var statusBarHeight = 22; // 这个要通过原生注入
|
|
1706
|
-
var pixelRatio = resolutionRatio / window.innerWidth;
|
|
1707
|
-
return {
|
|
1708
|
-
deviceOrientation: getCurrentDeviceOrientation(),
|
|
1709
|
-
devicePixelRatio: pixelRatio,
|
|
1710
|
-
screenWidth: window.innerWidth,
|
|
1711
|
-
screenHeight: window.innerHeight,
|
|
1712
|
-
SDKVersion: '2.26.0',
|
|
1713
|
-
appVersion: '2.37.0',
|
|
1714
|
-
batteryLevel: 98,
|
|
1715
|
-
benchmarkLevel: 1,
|
|
1716
|
-
bluetoothEnabled: false,
|
|
1717
|
-
brand: 'devtools',
|
|
1718
|
-
cameraAuthorized: true,
|
|
1719
|
-
deviceId: '11D22B6D-B5D8-4C24-AF42-8C959C95A2E6',
|
|
1720
|
-
enableDebug: true,
|
|
1721
|
-
errMsg: 'getSystemInfoSync:ok',
|
|
1722
|
-
fontSizeSetting: 15,
|
|
1723
|
-
frameworkVersion: '3.1.7',
|
|
1724
|
-
inFinChat: true,
|
|
1725
|
-
language: 'zh_CN',
|
|
1726
|
-
locationAuthorized: true,
|
|
1727
|
-
locationEnabled: true,
|
|
1728
|
-
microphoneAuthorized: true,
|
|
1729
|
-
mode: 'default',
|
|
1730
|
-
model: 'iPhone 5',
|
|
1731
|
-
notificationAuthorized: true,
|
|
1732
|
-
pixelRatio: pixelRatio,
|
|
1733
|
-
platform: 'devtools',
|
|
1734
|
-
statusBarHeight: statusBarHeight,
|
|
1735
|
-
system: getSystem(),
|
|
1736
|
-
theme: undefined,
|
|
1737
|
-
version: '8.0.28 ',
|
|
1738
|
-
windowHeight: window.innerHeight,
|
|
1739
|
-
windowWidth: window.innerWidth,
|
|
1740
|
-
safeArea: {
|
|
1741
|
-
height: window.innerHeight - statusBarHeight,
|
|
1742
|
-
widows: window.innerWidth,
|
|
1743
|
-
top: statusBarHeight,
|
|
1744
|
-
left: 0,
|
|
1745
|
-
right: 0
|
|
1746
|
-
}
|
|
1747
|
-
};
|
|
1748
|
-
},
|
|
1749
|
-
};
|
|
1750
|
-
|
|
1751
|
-
var injectetSDK = false;
|
|
1752
|
-
function injectSDKScript() {
|
|
1753
|
-
if (injectetSDK)
|
|
1754
|
-
return;
|
|
1755
|
-
var query = resolveUrl(location.search).query;
|
|
1756
|
-
var tempUrl = window.__sdkUrlTemplate;
|
|
1757
|
-
if (tempUrl != null && query.extType != null) {
|
|
1758
|
-
var sdkUrl = tempUrl.replace('$1', query.extType);
|
|
1759
|
-
var script = document.createElement('script');
|
|
1760
|
-
script.setAttribute('charset', 'utf-8');
|
|
1761
|
-
script.src = sdkUrl;
|
|
1762
|
-
document.body.appendChild(script);
|
|
1763
|
-
console.log('inject sdk script:', sdkUrl);
|
|
1764
|
-
injectetSDK = true;
|
|
1765
|
-
}
|
|
1766
|
-
}
|
|
1767
|
-
|
|
1768
|
-
var customEventHanders = {
|
|
1769
|
-
// 通知 native
|
|
1770
|
-
serviceStart: function (e) {
|
|
1771
|
-
setWxConfig(e.params);
|
|
1772
|
-
var params = e.params;
|
|
1773
|
-
initFirstPageByWxConfig(params);
|
|
1774
|
-
initWebFrame(params);
|
|
1775
|
-
},
|
|
1776
|
-
// 通知 native
|
|
1777
|
-
serviceReady: function (e) {
|
|
1778
|
-
injectSDKScript();
|
|
1779
|
-
var params = e.params, webviewIds = e.webviewIds;
|
|
1780
|
-
var manager = getServiceIframeManager();
|
|
1781
|
-
var webviewId = webviewIds[0];
|
|
1782
|
-
if (manager.isReady)
|
|
1783
|
-
return;
|
|
1784
|
-
router.initSlotWebviewId(webviewId);
|
|
1785
|
-
manager.events.once(ServiceIframeManagerEventNames.onViewDOMContentLoaded, function () {
|
|
1786
|
-
dispatchServiceEvent('onAppRoute', {
|
|
1787
|
-
path: params.root,
|
|
1788
|
-
openType: 'appLaunch',
|
|
1789
|
-
options: undefined,
|
|
1790
|
-
pipMode: '',
|
|
1791
|
-
query: undefined,
|
|
1792
|
-
webviewId: webviewId
|
|
1793
|
-
}, webviewId);
|
|
1794
|
-
});
|
|
1795
|
-
dispatchServiceEvent('onServiceReadyDone', __assign(__assign({}, launchOption), { webviewId: webviewId }), webviewId);
|
|
1796
|
-
manager.isReady = true;
|
|
1797
|
-
},
|
|
1798
|
-
// view 事件
|
|
1799
|
-
DOMContentLoaded: function (e) {
|
|
1800
|
-
var params = e.params, from = e.from; e.webviewIds; var event = e.event, webviewId = e.webviewId;
|
|
1801
|
-
var manager = getIframeManager(serviceIframeId);
|
|
1802
|
-
if (from === Terminal.View) {
|
|
1803
|
-
dispatchServiceEvent(event, params, webviewId);
|
|
1804
|
-
manager.events.emit(ServiceIframeManagerEventNames.onViewDOMContentLoaded);
|
|
1805
|
-
}
|
|
1806
|
-
else {
|
|
1807
|
-
console.error('not implement for ' + from);
|
|
1808
|
-
}
|
|
1809
|
-
},
|
|
1810
|
-
// 通知 native
|
|
1811
|
-
onLaunchCalled: function (e) { },
|
|
1812
|
-
// 通知 native
|
|
1813
|
-
viewReady: function () {
|
|
1814
|
-
var page = router.currPage;
|
|
1815
|
-
if (page != null) {
|
|
1816
|
-
page.isReady = true;
|
|
1817
|
-
page.injectScript();
|
|
1818
|
-
page.show();
|
|
1819
|
-
}
|
|
1820
|
-
},
|
|
1821
|
-
// 通知 native
|
|
1822
|
-
DOMReady: function () { },
|
|
1823
|
-
// 通知 service 调 原生方法
|
|
1824
|
-
INVOKE_METHOD: function (e) {
|
|
1825
|
-
var params = e.params, from = e.from; e.webviewIds; var event = e.event, webviewId = e.webviewId;
|
|
1826
|
-
if (from === Terminal.View) {
|
|
1827
|
-
dispatchServiceEvent(event, params, webviewId);
|
|
1828
|
-
}
|
|
1829
|
-
else {
|
|
1830
|
-
console.error('not implement for ' + from);
|
|
1831
|
-
}
|
|
1832
|
-
},
|
|
1833
|
-
// 双向的
|
|
1834
|
-
vdSync: function (e) {
|
|
1835
|
-
var params = e.params, from = e.from, webviewIds = e.webviewIds, event = e.event, webviewId = e.webviewId;
|
|
1836
|
-
if (from === Terminal.View) {
|
|
1837
|
-
dispatchServiceEvent(event, params, webviewId);
|
|
1838
|
-
}
|
|
1839
|
-
else {
|
|
1840
|
-
dispatchViewEvent(event, params, webviewIds);
|
|
1841
|
-
}
|
|
1842
|
-
},
|
|
1843
|
-
// 双向的(待定)
|
|
1844
|
-
vdSyncBatch: function (e) {
|
|
1845
|
-
var params = e.params, from = e.from, webviewIds = e.webviewIds, event = e.event, webviewId = e.webviewId;
|
|
1846
|
-
if (from === Terminal.View) {
|
|
1847
|
-
dispatchServiceEvent(event, params, webviewId);
|
|
1848
|
-
}
|
|
1849
|
-
else {
|
|
1850
|
-
dispatchViewEvent(event, params, webviewIds);
|
|
1851
|
-
}
|
|
1852
|
-
},
|
|
1853
|
-
// 进入页面
|
|
1854
|
-
appDataChange: function (e) {
|
|
1855
|
-
var params = e.params, from = e.from, webviewIds = e.webviewIds, event = e.event; e.webviewId;
|
|
1856
|
-
if (from === Terminal.View) {
|
|
1857
|
-
console.error('not implement for ' + from);
|
|
1858
|
-
}
|
|
1859
|
-
else {
|
|
1860
|
-
emitAppDataChangeEvent(params);
|
|
1861
|
-
dispatchViewEvent(event, params, webviewIds);
|
|
1862
|
-
}
|
|
1863
|
-
},
|
|
1864
|
-
// 退出页面
|
|
1865
|
-
__updateAppData: function (e) {
|
|
1866
|
-
emitUpdateAppDataEvent();
|
|
1867
|
-
},
|
|
1868
|
-
pageonshow: function (e) {
|
|
1869
|
-
var params = e.params, from = e.from, webviewIds = e.webviewIds, event = e.event; e.webviewId;
|
|
1870
|
-
if (from === Terminal.View) {
|
|
1871
|
-
console.error('not implement for ' + from);
|
|
1872
|
-
}
|
|
1873
|
-
else {
|
|
1874
|
-
dispatchViewEvent(event, params, webviewIds);
|
|
1875
|
-
}
|
|
1876
|
-
},
|
|
1877
|
-
requestLoadFontFace: function (e) {
|
|
1878
|
-
var params = e.params, from = e.from, webviewIds = e.webviewIds, event = e.event; e.webviewId;
|
|
1879
|
-
if (from === Terminal.View) {
|
|
1880
|
-
console.error('not implement for ' + from);
|
|
1881
|
-
}
|
|
1882
|
-
else {
|
|
1883
|
-
dispatchViewEvent(event, params, webviewIds);
|
|
1884
|
-
}
|
|
1885
|
-
},
|
|
1886
|
-
requestLoadGlobalFontFaces: function (e) {
|
|
1887
|
-
var params = e.params, from = e.from; e.webviewIds; var event = e.event, webviewId = e.webviewId;
|
|
1888
|
-
if (from === Terminal.View) {
|
|
1889
|
-
dispatchServiceEvent(event, params, webviewId);
|
|
1890
|
-
}
|
|
1891
|
-
else {
|
|
1892
|
-
console.error('not implement for ' + from);
|
|
1893
|
-
}
|
|
1894
|
-
},
|
|
1895
|
-
responseLoadGlobalFontFaces: function (e) {
|
|
1896
|
-
var params = e.params, from = e.from, webviewIds = e.webviewIds, event = e.event; e.webviewId;
|
|
1897
|
-
if (from === Terminal.View) {
|
|
1898
|
-
console.error('not implement for ' + from);
|
|
1899
|
-
}
|
|
1900
|
-
else {
|
|
1901
|
-
dispatchViewEvent(event, params, webviewIds);
|
|
1902
|
-
}
|
|
1903
|
-
},
|
|
1904
|
-
PAGE_EVENT: function (e) {
|
|
1905
|
-
var params = e.params, from = e.from; e.webviewIds; var event = e.event, webviewId = e.webviewId;
|
|
1906
|
-
if (from === Terminal.View) {
|
|
1907
|
-
dispatchServiceEvent(event, params, webviewId);
|
|
1908
|
-
}
|
|
1909
|
-
else {
|
|
1910
|
-
console.error('not implement for ' + from);
|
|
1911
|
-
}
|
|
1912
|
-
},
|
|
1913
|
-
setKeyboardValue: function (e) {
|
|
1914
|
-
var params = e.params, from = e.from, webviewIds = e.webviewIds, event = e.event; e.webviewId;
|
|
1915
|
-
if (from === Terminal.View) {
|
|
1916
|
-
console.error('not implement for ' + from);
|
|
1917
|
-
}
|
|
1918
|
-
else {
|
|
1919
|
-
dispatchViewEvent(event, params, webviewIds);
|
|
1920
|
-
}
|
|
1921
|
-
},
|
|
1922
|
-
SPECIAL_PAGE_EVENT: function (e) {
|
|
1923
|
-
var params = e.params, from = e.from; e.webviewIds; var event = e.event, webviewId = e.webviewId;
|
|
1924
|
-
if (from === Terminal.View) {
|
|
1925
|
-
dispatchServiceEvent(event, params, webviewId);
|
|
1926
|
-
}
|
|
1927
|
-
else {
|
|
1928
|
-
console.error('not implement for ' + from);
|
|
1929
|
-
}
|
|
1930
|
-
},
|
|
1931
|
-
gameServiceReady: function () {
|
|
1932
|
-
injectSDKScript();
|
|
1933
|
-
},
|
|
1934
|
-
gameConfigUpdate: function (config) {
|
|
1935
|
-
var _a;
|
|
1936
|
-
var currentDeviceOrientation = getCurrentDeviceOrientation();
|
|
1937
|
-
if (config.deviceOrientation !== currentDeviceOrientation) {
|
|
1938
|
-
// 切换到游戏配置的设备方向
|
|
1939
|
-
(_a = getTarget()) === null || _a === void 0 ? void 0 : _a.invokeHandler('setDeviceOrientation', {
|
|
1940
|
-
value: config.deviceOrientation
|
|
1941
|
-
}, -1);
|
|
1942
|
-
}
|
|
1943
|
-
}
|
|
1944
|
-
};
|
|
1945
|
-
|
|
1946
|
-
var customEventPreifx = 'custom_event_';
|
|
1947
|
-
var APIS = __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({}, globalApis), fsUtilApis), loadSubpackageApis), routeApis), interactionApis), localStorageApis), system), navApis);
|
|
1948
|
-
var FinChatJSCore = {
|
|
1949
|
-
invokeHandler: function (data) {
|
|
1950
|
-
debug && console.log('invokeHander', data);
|
|
1951
|
-
var C = data.C, paramsString = data.paramsString; data.type; var from = data.from, callbackId = data.callbackId;
|
|
1952
|
-
var params = JSON.parse(paramsString);
|
|
1953
|
-
// @ts-expect-error
|
|
1954
|
-
var api = APIS[C];
|
|
1955
|
-
if (api != null) {
|
|
1956
|
-
var res = api(params, callbackId, from);
|
|
1957
|
-
return res;
|
|
1958
|
-
}
|
|
1959
|
-
else {
|
|
1960
|
-
var adapter = getTarget();
|
|
1961
|
-
if (adapter != null) {
|
|
1962
|
-
return adapter.invokeHandler(C, params, callbackId);
|
|
1963
|
-
}
|
|
1964
|
-
}
|
|
1965
|
-
},
|
|
1966
|
-
publishHandler: function (data) {
|
|
1967
|
-
debug && console.log('publishHandler', data);
|
|
1968
|
-
var event = data.event, from = data.from, paramsString = data.paramsString, webviewId = data.webviewId, webviewIds = data.webviewIds;
|
|
1969
|
-
var eventWithoutPrefix = event.replace(customEventPreifx, '');
|
|
1970
|
-
var params = JSON.parse(paramsString);
|
|
1971
|
-
var handler = customEventHanders[eventWithoutPrefix];
|
|
1972
|
-
if (handler != null) {
|
|
1973
|
-
// @ts-ignore
|
|
1974
|
-
handler({
|
|
1975
|
-
event: event,
|
|
1976
|
-
params: params,
|
|
1977
|
-
from: from,
|
|
1978
|
-
webviewId: webviewId,
|
|
1979
|
-
webviewIds: Terminal.Service === from && webviewIds ? JSON.parse(webviewIds) : undefined // 来自 service 事件存在
|
|
1980
|
-
});
|
|
1981
|
-
}
|
|
1982
|
-
else {
|
|
1983
|
-
var adapter = getTarget();
|
|
1984
|
-
if (adapter != null) {
|
|
1985
|
-
adapter.publishHandler(eventWithoutPrefix, params, from);
|
|
1986
|
-
}
|
|
1987
|
-
}
|
|
1988
|
-
},
|
|
1989
|
-
webInvokeHandler: function (data) {
|
|
1990
|
-
debug && console.log('webInvokeHander', data);
|
|
1991
|
-
},
|
|
1992
|
-
webPublishHandler: function (data) {
|
|
1993
|
-
debug && console.log('webPublishHandler', data);
|
|
1994
|
-
}
|
|
1995
|
-
};
|
|
1996
|
-
// @ts-ignore
|
|
1997
|
-
window.FinChatJSCore = FinChatJSCore;
|
|
1998
|
-
|
|
1999
|
-
}));
|
|
6
|
+
!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function n(e,n,t){return e(t={path:n,exports:{},require:function(e,n){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==n&&t.path)}},t.exports),t.exports}var t=n((function(e){var n=Object.prototype.hasOwnProperty,t="~";function o(){}function r(e,n,t){this.fn=e,this.context=n,this.once=t||!1}function i(e,n,o,i,a){if("function"!=typeof o)throw new TypeError("The listener must be a function");var s=new r(o,i||e,a),u=t?t+n:n;return e._events[u]?e._events[u].fn?e._events[u]=[e._events[u],s]:e._events[u].push(s):(e._events[u]=s,e._eventsCount++),e}function a(e,n){0==--e._eventsCount?e._events=new o:delete e._events[n]}function s(){this._events=new o,this._eventsCount=0}Object.create&&(o.prototype=Object.create(null),(new o).__proto__||(t=!1)),s.prototype.eventNames=function(){var e,o,r=[];if(0===this._eventsCount)return r;for(o in e=this._events)n.call(e,o)&&r.push(t?o.slice(1):o);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(e)):r},s.prototype.listeners=function(e){var n=t?t+e:e,o=this._events[n];if(!o)return[];if(o.fn)return[o.fn];for(var r=0,i=o.length,a=new Array(i);r<i;r++)a[r]=o[r].fn;return a},s.prototype.listenerCount=function(e){var n=t?t+e:e,o=this._events[n];return o?o.fn?1:o.length:0},s.prototype.emit=function(e,n,o,r,i,a){var s=t?t+e:e;if(!this._events[s])return!1;var u,d,c=this._events[s],l=arguments.length;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),l){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,n),!0;case 3:return c.fn.call(c.context,n,o),!0;case 4:return c.fn.call(c.context,n,o,r),!0;case 5:return c.fn.call(c.context,n,o,r,i),!0;case 6:return c.fn.call(c.context,n,o,r,i,a),!0}for(d=1,u=new Array(l-1);d<l;d++)u[d-1]=arguments[d];c.fn.apply(c.context,u)}else{var p,f=c.length;for(d=0;d<f;d++)switch(c[d].once&&this.removeListener(e,c[d].fn,void 0,!0),l){case 1:c[d].fn.call(c[d].context);break;case 2:c[d].fn.call(c[d].context,n);break;case 3:c[d].fn.call(c[d].context,n,o);break;case 4:c[d].fn.call(c[d].context,n,o,r);break;default:if(!u)for(p=1,u=new Array(l-1);p<l;p++)u[p-1]=arguments[p];c[d].fn.apply(c[d].context,u)}}return!0},s.prototype.on=function(e,n,t){return i(this,e,n,t,!1)},s.prototype.once=function(e,n,t){return i(this,e,n,t,!0)},s.prototype.removeListener=function(e,n,o,r){var i=t?t+e:e;if(!this._events[i])return this;if(!n)return a(this,i),this;var s=this._events[i];if(s.fn)s.fn!==n||r&&!s.once||o&&s.context!==o||a(this,i);else{for(var u=0,d=[],c=s.length;u<c;u++)(s[u].fn!==n||r&&!s[u].once||o&&s[u].context!==o)&&d.push(s[u]);d.length?this._events[i]=1===d.length?d[0]:d:a(this,i)}return this},s.prototype.removeAllListeners=function(e){var n;return e?(n=t?t+e:e,this._events[n]&&a(this,n)):(this._events=new o,this._eventsCount=0),this},s.prototype.off=s.prototype.removeListener,s.prototype.addListener=s.prototype.on,s.prefixed=t,s.EventEmitter=s,e.exports=s})),o=function(e,n){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])},o(e,n)};
|
|
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
|
+
***************************************************************************** */function r(e,n){function t(){this.constructor=e}o(e,n),e.prototype=null===n?Object.create(n):(t.prototype=n.prototype,new t)}var i=function(){return i=Object.assign||function(e){for(var n,t=1,o=arguments.length;t<o;t++)for(var r in n=arguments[t])Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r]);return e},i.apply(this,arguments)};function a(e,n,t,o){return new(t||(t=Promise))((function(r,i){function a(e){try{u(o.next(e))}catch(e){i(e)}}function s(e){try{u(o.throw(e))}catch(e){i(e)}}function u(e){var n;e.done?r(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(a,s)}u((o=o.apply(e,n||[])).next())}))}function s(e,n){var t,o,r,i,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(t)throw new TypeError("Generator is already executing.");for(;a;)try{if(t=1,o&&(r=2&i[0]?o.return:i[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,i[1])).done)return r;switch(o=0,r&&(i=[2&i[0],r.value]),i[0]){case 0:case 1:r=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,o=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&i[1]<r[3])){a.label=i[1];break}if(6===i[0]&&a.label<r[1]){a.label=r[1],r=i;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(i);break}r[2]&&a.ops.pop(),a.trys.pop();continue}i=n.call(e,a)}catch(e){i=[6,e],o=0}finally{t=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}function u(){for(var e=0,n=0,t=arguments.length;n<t;n++)e+=arguments[n].length;var o=Array(e),r=0;for(n=0;n<t;n++)for(var i=arguments[n],a=0,s=i.length;a<s;a++,r++)o[r]=i[a];return o}function d(){var e=window.navigator.userAgent.toLowerCase();return/(iphone|ipad)/.test(e)?"IOS":/android/.test(e)?"Android":"Windows For HUYA"}function c(){var e=d();return"IOS"===e||"Android"===e}function l(e){var n=e.split("?"),t=n[0],o=n[1],r={};return null!=o&&""!==o&&o.split("&").reduce((function(e,n){var t=n.split("=");return e[t[0]]=decodeURIComponent(t[1]),e}),r),{path:t,query:r}}function p(e){for(var n="",t=new Uint8Array(e),o=t.byteLength,r=0;r<o;r++)n+=String.fromCharCode(t[r]);return window.btoa(n)}function f(e){return new Promise((function(n){setTimeout(n,e)}))}var _=function(e,n,t){var o,r=new Promise((function(n,r){o=setTimeout((function(){t&&t(e),r(new Error("Timed out in "+e+"ms."))}),e)}));return new Promise((function(e,t){Promise.race([n,r]).then((function(n){clearTimeout(o),e(n)})).catch(t)}))};var v=function(e){return 1===String(e).length?"0"+e:e},h=location.pathname.split("/"),m=h.slice(1,h.length-1),w=location.protocol+"//"+location.host+"/"+m.join("/")+"/",g=w+"view.html",y=null==window.__debug||window.__debug,b="service",A="view",T=window.__packageExtConfig,I={path:T?T.entryPagePath:"index",query:{},referrerInfo:{},scene:1001},k="onTaskProgressUpdate",x="onTaskHeadersReceived",S="miniGame",P="hyfile://";function M(e,n,t){var o=new XMLHttpRequest,r=!0;if(null!=n.sync&&(r=!n.sync),null!=n.responseType&&(o.responseType=n.responseType),o.open("GET",e,r),null!=n.header)for(var i in n.header)o.setRequestHeader(i,n.header[i]);o.onload=function(e){t(null,o.response,{e:e,xhr:o})},o.onerror=function(e){t(new Error("request settings failed!"),null,{e:e,xhr:o})},o.send(null)}var C={};var B=function(){function e(e){this.sync=!1,this.events=new t,this.el=e,this.isReady=!1}return e.prototype.getWindow=function(){return this.el.contentWindow},e.prototype.getBridge=function(){},e.prototype.emitSync=function(e){for(var n,t=[],o=1;o<arguments.length;o++)t[o-1]=arguments[o];this.sync=!0,(n=this.events).emit.apply(n,u([e],t)),this.sync=!1},e}(),E={onViewDOMContentLoaded:"onViewDOMContentLoaded",onInjectHTMLCallback:"onInjectHTMLCallback"},L={};var O=function(e){function n(n){return e.call(this,n)||this}return r(n,e),n.prototype.sendToSerivce=function(e,n,t){y&&console.log("%c "+e,"color: blue;",n,t),this.getBridge().subscribeHandler(e,n,t)},n.prototype.loadSubBundle=function(e,n){if(!0!==L[e]){var t=this.getWindow();null!=t&&(t.injectHtml(t.document.body,{content:'<script charset="utf-8" src="'+n+'"><\/script>'}),L[e]=!0)}},n.prototype.invokeCallbackHandler=function(e,n,t){y&&console.log("%c "+(t||"API")+" call callback","color: blue;",e,n),this.getBridge().invokeCallbackHandler(e,n)},n.prototype.getBridge=function(){return this.getWindow().ServiceJSBridge},n}(B),H="webview-service",D=new Map;function F(e){var n=D.get(e);if(n)return n;var t=document.getElementById(e);if(null!=t){var o=new(e===H?O:ze)(t);return D.set(e,o),o}throw new Error("获取IframeManager失败, id: "+e)}function V(){return F(H)}function W(e,n,t){Ze.stack.forEach((function(o){null!=o.webviewId&&t.indexOf(o.webviewId)>-1&&(o.isReady?o.sendToView(e,n):console.error("shouldn't exctute"))}))}function N(e,n,t){F(H).sendToSerivce(e,n,t)}function j(e,n){var t,o=null===(t=Ze.currPage)||void 0===t?void 0:t.children;if(Array.isArray(o)&&o.length>0){var r=o[0];r&&r.isWebView&&r.postMessageToWebView({eventName:e,type:"subscribeHandler",params:n})}}var R=null;function G(){if(null==R)throw new Error("AdapterTarget is not set yet.");return R}var q="custom_event_";var U=n((function(n,t){
|
|
21
|
+
/*!
|
|
22
|
+
* howler.js v2.2.4
|
|
23
|
+
* howlerjs.com
|
|
24
|
+
*
|
|
25
|
+
* (c) 2013-2020, James Simpson of GoldFire Studios
|
|
26
|
+
* goldfirestudios.com
|
|
27
|
+
*
|
|
28
|
+
* MIT License
|
|
29
|
+
*/
|
|
30
|
+
!function(){var n=function(){this.init()};n.prototype={init:function(){var e=this||o;return e._counter=1e3,e._html5AudioPool=[],e.html5PoolSize=10,e._codecs={},e._howls=[],e._muted=!1,e._volume=1,e._canPlayEvent="canplaythrough",e._navigator="undefined"!=typeof window&&window.navigator?window.navigator:null,e.masterGain=null,e.noAudio=!1,e.usingWebAudio=!0,e.autoSuspend=!0,e.ctx=null,e.autoUnlock=!0,e._setup(),e},volume:function(e){var n=this||o;if(e=parseFloat(e),n.ctx||l(),void 0!==e&&e>=0&&e<=1){if(n._volume=e,n._muted)return n;n.usingWebAudio&&n.masterGain.gain.setValueAtTime(e,o.ctx.currentTime);for(var t=0;t<n._howls.length;t++)if(!n._howls[t]._webAudio)for(var r=n._howls[t]._getSoundIds(),i=0;i<r.length;i++){var a=n._howls[t]._soundById(r[i]);a&&a._node&&(a._node.volume=a._volume*e)}return n}return n._volume},mute:function(e){var n=this||o;n.ctx||l(),n._muted=e,n.usingWebAudio&&n.masterGain.gain.setValueAtTime(e?0:n._volume,o.ctx.currentTime);for(var t=0;t<n._howls.length;t++)if(!n._howls[t]._webAudio)for(var r=n._howls[t]._getSoundIds(),i=0;i<r.length;i++){var a=n._howls[t]._soundById(r[i]);a&&a._node&&(a._node.muted=!!e||a._muted)}return n},stop:function(){for(var e=this||o,n=0;n<e._howls.length;n++)e._howls[n].stop();return e},unload:function(){for(var e=this||o,n=e._howls.length-1;n>=0;n--)e._howls[n].unload();return e.usingWebAudio&&e.ctx&&void 0!==e.ctx.close&&(e.ctx.close(),e.ctx=null,l()),e},codecs:function(e){return(this||o)._codecs[e.replace(/^x-/,"")]},_setup:function(){var e=this||o;if(e.state=e.ctx&&e.ctx.state||"suspended",e._autoSuspend(),!e.usingWebAudio)if("undefined"!=typeof Audio)try{void 0===(new Audio).oncanplaythrough&&(e._canPlayEvent="canplay")}catch(n){e.noAudio=!0}else e.noAudio=!0;try{(new Audio).muted&&(e.noAudio=!0)}catch(e){}return e.noAudio||e._setupCodecs(),e},_setupCodecs:function(){var e=this||o,n=null;try{n="undefined"!=typeof Audio?new Audio:null}catch(n){return e}if(!n||"function"!=typeof n.canPlayType)return e;var t=n.canPlayType("audio/mpeg;").replace(/^no$/,""),r=e._navigator?e._navigator.userAgent:"",i=r.match(/OPR\/(\d+)/g),a=i&&parseInt(i[0].split("/")[1],10)<33,s=-1!==r.indexOf("Safari")&&-1===r.indexOf("Chrome"),u=r.match(/Version\/(.*?) /),d=s&&u&&parseInt(u[1],10)<15;return e._codecs={mp3:!(a||!t&&!n.canPlayType("audio/mp3;").replace(/^no$/,"")),mpeg:!!t,opus:!!n.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/,""),ogg:!!n.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/,""),oga:!!n.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/,""),wav:!!(n.canPlayType('audio/wav; codecs="1"')||n.canPlayType("audio/wav")).replace(/^no$/,""),aac:!!n.canPlayType("audio/aac;").replace(/^no$/,""),caf:!!n.canPlayType("audio/x-caf;").replace(/^no$/,""),m4a:!!(n.canPlayType("audio/x-m4a;")||n.canPlayType("audio/m4a;")||n.canPlayType("audio/aac;")).replace(/^no$/,""),m4b:!!(n.canPlayType("audio/x-m4b;")||n.canPlayType("audio/m4b;")||n.canPlayType("audio/aac;")).replace(/^no$/,""),mp4:!!(n.canPlayType("audio/x-mp4;")||n.canPlayType("audio/mp4;")||n.canPlayType("audio/aac;")).replace(/^no$/,""),weba:!(d||!n.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/,"")),webm:!(d||!n.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/,"")),dolby:!!n.canPlayType('audio/mp4; codecs="ec-3"').replace(/^no$/,""),flac:!!(n.canPlayType("audio/x-flac;")||n.canPlayType("audio/flac;")).replace(/^no$/,"")},e},_unlockAudio:function(){var e=this||o;if(!e._audioUnlocked&&e.ctx){e._audioUnlocked=!1,e.autoUnlock=!1,e._mobileUnloaded||44100===e.ctx.sampleRate||(e._mobileUnloaded=!0,e.unload()),e._scratchBuffer=e.ctx.createBuffer(1,1,22050);var n=function(t){for(;e._html5AudioPool.length<e.html5PoolSize;)try{var o=new Audio;o._unlocked=!0,e._releaseHtml5Audio(o)}catch(t){e.noAudio=!0;break}for(var r=0;r<e._howls.length;r++)if(!e._howls[r]._webAudio)for(var i=e._howls[r]._getSoundIds(),a=0;a<i.length;a++){var s=e._howls[r]._soundById(i[a]);s&&s._node&&!s._node._unlocked&&(s._node._unlocked=!0,s._node.load())}e._autoResume();var u=e.ctx.createBufferSource();u.buffer=e._scratchBuffer,u.connect(e.ctx.destination),void 0===u.start?u.noteOn(0):u.start(0),"function"==typeof e.ctx.resume&&e.ctx.resume(),u.onended=function(){u.disconnect(0),e._audioUnlocked=!0,document.removeEventListener("touchstart",n,!0),document.removeEventListener("touchend",n,!0),document.removeEventListener("click",n,!0),document.removeEventListener("keydown",n,!0);for(var t=0;t<e._howls.length;t++)e._howls[t]._emit("unlock")}};return document.addEventListener("touchstart",n,!0),document.addEventListener("touchend",n,!0),document.addEventListener("click",n,!0),document.addEventListener("keydown",n,!0),e}},_obtainHtml5Audio:function(){var e=this||o;if(e._html5AudioPool.length)return e._html5AudioPool.pop();var n=(new Audio).play();return n&&"undefined"!=typeof Promise&&(n instanceof Promise||"function"==typeof n.then)&&n.catch((function(){console.warn("HTML5 Audio pool exhausted, returning potentially locked audio object.")})),new Audio},_releaseHtml5Audio:function(e){var n=this||o;return e._unlocked&&n._html5AudioPool.push(e),n},_autoSuspend:function(){var e=this;if(e.autoSuspend&&e.ctx&&void 0!==e.ctx.suspend&&o.usingWebAudio){for(var n=0;n<e._howls.length;n++)if(e._howls[n]._webAudio)for(var t=0;t<e._howls[n]._sounds.length;t++)if(!e._howls[n]._sounds[t]._paused)return e;return e._suspendTimer&&clearTimeout(e._suspendTimer),e._suspendTimer=setTimeout((function(){if(e.autoSuspend){e._suspendTimer=null,e.state="suspending";var n=function(){e.state="suspended",e._resumeAfterSuspend&&(delete e._resumeAfterSuspend,e._autoResume())};e.ctx.suspend().then(n,n)}}),3e4),e}},_autoResume:function(){var e=this;if(e.ctx&&void 0!==e.ctx.resume&&o.usingWebAudio)return"running"===e.state&&"interrupted"!==e.ctx.state&&e._suspendTimer?(clearTimeout(e._suspendTimer),e._suspendTimer=null):"suspended"===e.state||"running"===e.state&&"interrupted"===e.ctx.state?(e.ctx.resume().then((function(){e.state="running";for(var n=0;n<e._howls.length;n++)e._howls[n]._emit("resume")})),e._suspendTimer&&(clearTimeout(e._suspendTimer),e._suspendTimer=null)):"suspending"===e.state&&(e._resumeAfterSuspend=!0),e}};var o=new n,r=function(e){e.src&&0!==e.src.length?this.init(e):console.error("An array of source files must be passed with any new Howl.")};r.prototype={init:function(e){var n=this;return o.ctx||l(),n._autoplay=e.autoplay||!1,n._format="string"!=typeof e.format?e.format:[e.format],n._html5=e.html5||!1,n._muted=e.mute||!1,n._loop=e.loop||!1,n._pool=e.pool||5,n._preload="boolean"!=typeof e.preload&&"metadata"!==e.preload||e.preload,n._rate=e.rate||1,n._sprite=e.sprite||{},n._src="string"!=typeof e.src?e.src:[e.src],n._volume=void 0!==e.volume?e.volume:1,n._xhr={method:e.xhr&&e.xhr.method?e.xhr.method:"GET",headers:e.xhr&&e.xhr.headers?e.xhr.headers:null,withCredentials:!(!e.xhr||!e.xhr.withCredentials)&&e.xhr.withCredentials},n._duration=0,n._state="unloaded",n._sounds=[],n._endTimers={},n._queue=[],n._playLock=!1,n._onend=e.onend?[{fn:e.onend}]:[],n._onfade=e.onfade?[{fn:e.onfade}]:[],n._onload=e.onload?[{fn:e.onload}]:[],n._onloaderror=e.onloaderror?[{fn:e.onloaderror}]:[],n._onplayerror=e.onplayerror?[{fn:e.onplayerror}]:[],n._onpause=e.onpause?[{fn:e.onpause}]:[],n._onplay=e.onplay?[{fn:e.onplay}]:[],n._onstop=e.onstop?[{fn:e.onstop}]:[],n._onmute=e.onmute?[{fn:e.onmute}]:[],n._onvolume=e.onvolume?[{fn:e.onvolume}]:[],n._onrate=e.onrate?[{fn:e.onrate}]:[],n._onseek=e.onseek?[{fn:e.onseek}]:[],n._onunlock=e.onunlock?[{fn:e.onunlock}]:[],n._onresume=[],n._webAudio=o.usingWebAudio&&!n._html5,void 0!==o.ctx&&o.ctx&&o.autoUnlock&&o._unlockAudio(),o._howls.push(n),n._autoplay&&n._queue.push({event:"play",action:function(){n.play()}}),n._preload&&"none"!==n._preload&&n.load(),n},load:function(){var e=this,n=null;if(o.noAudio)e._emit("loaderror",null,"No audio support.");else{"string"==typeof e._src&&(e._src=[e._src]);for(var t=0;t<e._src.length;t++){var r,a;if(e._format&&e._format[t])r=e._format[t];else{if("string"!=typeof(a=e._src[t])){e._emit("loaderror",null,"Non-string found in selected audio sources - ignoring.");continue}(r=/^data:audio\/([^;,]+);/i.exec(a))||(r=/\.([^.]+)$/.exec(a.split("?",1)[0])),r&&(r=r[1].toLowerCase())}if(r||console.warn('No file extension was found. Consider using the "format" property or specify an extension.'),r&&o.codecs(r)){n=e._src[t];break}}if(n)return e._src=n,e._state="loading","https:"===window.location.protocol&&"http:"===n.slice(0,5)&&(e._html5=!0,e._webAudio=!1),new i(e),e._webAudio&&s(e),e;e._emit("loaderror",null,"No codec support for selected audio sources.")}},play:function(e,n){var t=this,r=null;if("number"==typeof e)r=e,e=null;else{if("string"==typeof e&&"loaded"===t._state&&!t._sprite[e])return null;if(void 0===e&&(e="__default",!t._playLock)){for(var i=0,a=0;a<t._sounds.length;a++)t._sounds[a]._paused&&!t._sounds[a]._ended&&(i++,r=t._sounds[a]._id);1===i?e=null:r=null}}var s=r?t._soundById(r):t._inactiveSound();if(!s)return null;if(r&&!e&&(e=s._sprite||"__default"),"loaded"!==t._state){s._sprite=e,s._ended=!1;var u=s._id;return t._queue.push({event:"play",action:function(){t.play(u)}}),u}if(r&&!s._paused)return n||t._loadQueue("play"),s._id;t._webAudio&&o._autoResume();var d=Math.max(0,s._seek>0?s._seek:t._sprite[e][0]/1e3),c=Math.max(0,(t._sprite[e][0]+t._sprite[e][1])/1e3-d),l=1e3*c/Math.abs(s._rate),p=t._sprite[e][0]/1e3,f=(t._sprite[e][0]+t._sprite[e][1])/1e3;s._sprite=e,s._ended=!1;var _=function(){s._paused=!1,s._seek=d,s._start=p,s._stop=f,s._loop=!(!s._loop&&!t._sprite[e][2])};if(!(d>=f)){var v=s._node;if(t._webAudio){var h=function(){t._playLock=!1,_(),t._refreshBuffer(s);var e=s._muted||t._muted?0:s._volume;v.gain.setValueAtTime(e,o.ctx.currentTime),s._playStart=o.ctx.currentTime,void 0===v.bufferSource.start?s._loop?v.bufferSource.noteGrainOn(0,d,86400):v.bufferSource.noteGrainOn(0,d,c):s._loop?v.bufferSource.start(0,d,86400):v.bufferSource.start(0,d,c),l!==1/0&&(t._endTimers[s._id]=setTimeout(t._ended.bind(t,s),l)),n||setTimeout((function(){t._emit("play",s._id),t._loadQueue()}),0)};"running"===o.state&&"interrupted"!==o.ctx.state?h():(t._playLock=!0,t.once("resume",h),t._clearTimer(s._id))}else{var m=function(){v.currentTime=d,v.muted=s._muted||t._muted||o._muted||v.muted,v.volume=s._volume*o.volume(),v.playbackRate=s._rate;try{var r=v.play();if(r&&"undefined"!=typeof Promise&&(r instanceof Promise||"function"==typeof r.then)?(t._playLock=!0,_(),r.then((function(){t._playLock=!1,v._unlocked=!0,n?t._loadQueue():t._emit("play",s._id)})).catch((function(){t._playLock=!1,t._emit("playerror",s._id,"Playback was unable to start. This is most commonly an issue on mobile devices and Chrome where playback was not within a user interaction."),s._ended=!0,s._paused=!0}))):n||(t._playLock=!1,_(),t._emit("play",s._id)),v.playbackRate=s._rate,v.paused)return void t._emit("playerror",s._id,"Playback was unable to start. This is most commonly an issue on mobile devices and Chrome where playback was not within a user interaction.");"__default"!==e||s._loop?t._endTimers[s._id]=setTimeout(t._ended.bind(t,s),l):(t._endTimers[s._id]=function(){t._ended(s),v.removeEventListener("ended",t._endTimers[s._id],!1)},v.addEventListener("ended",t._endTimers[s._id],!1))}catch(e){t._emit("playerror",s._id,e)}};"data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA"===v.src&&(v.src=t._src,v.load());var w=window&&window.ejecta||!v.readyState&&o._navigator.isCocoonJS;if(v.readyState>=3||w)m();else{t._playLock=!0,t._state="loading";var g=function(){t._state="loaded",m(),v.removeEventListener(o._canPlayEvent,g,!1)};v.addEventListener(o._canPlayEvent,g,!1),t._clearTimer(s._id)}}return s._id}t._ended(s)},pause:function(e){var n=this;if("loaded"!==n._state||n._playLock)return n._queue.push({event:"pause",action:function(){n.pause(e)}}),n;for(var t=n._getSoundIds(e),o=0;o<t.length;o++){n._clearTimer(t[o]);var r=n._soundById(t[o]);if(r&&!r._paused&&(r._seek=n.seek(t[o]),r._rateSeek=0,r._paused=!0,n._stopFade(t[o]),r._node))if(n._webAudio){if(!r._node.bufferSource)continue;void 0===r._node.bufferSource.stop?r._node.bufferSource.noteOff(0):r._node.bufferSource.stop(0),n._cleanBuffer(r._node)}else isNaN(r._node.duration)&&r._node.duration!==1/0||r._node.pause();arguments[1]||n._emit("pause",r?r._id:null)}return n},stop:function(e,n){var t=this;if("loaded"!==t._state||t._playLock)return t._queue.push({event:"stop",action:function(){t.stop(e)}}),t;for(var o=t._getSoundIds(e),r=0;r<o.length;r++){t._clearTimer(o[r]);var i=t._soundById(o[r]);i&&(i._seek=i._start||0,i._rateSeek=0,i._paused=!0,i._ended=!0,t._stopFade(o[r]),i._node&&(t._webAudio?i._node.bufferSource&&(void 0===i._node.bufferSource.stop?i._node.bufferSource.noteOff(0):i._node.bufferSource.stop(0),t._cleanBuffer(i._node)):isNaN(i._node.duration)&&i._node.duration!==1/0||(i._node.currentTime=i._start||0,i._node.pause(),i._node.duration===1/0&&t._clearSound(i._node))),n||t._emit("stop",i._id))}return t},mute:function(e,n){var t=this;if("loaded"!==t._state||t._playLock)return t._queue.push({event:"mute",action:function(){t.mute(e,n)}}),t;if(void 0===n){if("boolean"!=typeof e)return t._muted;t._muted=e}for(var r=t._getSoundIds(n),i=0;i<r.length;i++){var a=t._soundById(r[i]);a&&(a._muted=e,a._interval&&t._stopFade(a._id),t._webAudio&&a._node?a._node.gain.setValueAtTime(e?0:a._volume,o.ctx.currentTime):a._node&&(a._node.muted=!!o._muted||e),t._emit("mute",a._id))}return t},volume:function(){var e,n,t,r=this,i=arguments;if(0===i.length)return r._volume;if(1===i.length||2===i.length&&void 0===i[1]?r._getSoundIds().indexOf(i[0])>=0?n=parseInt(i[0],10):e=parseFloat(i[0]):i.length>=2&&(e=parseFloat(i[0]),n=parseInt(i[1],10)),!(void 0!==e&&e>=0&&e<=1))return(t=n?r._soundById(n):r._sounds[0])?t._volume:0;if("loaded"!==r._state||r._playLock)return r._queue.push({event:"volume",action:function(){r.volume.apply(r,i)}}),r;void 0===n&&(r._volume=e),n=r._getSoundIds(n);for(var a=0;a<n.length;a++)(t=r._soundById(n[a]))&&(t._volume=e,i[2]||r._stopFade(n[a]),r._webAudio&&t._node&&!t._muted?t._node.gain.setValueAtTime(e,o.ctx.currentTime):t._node&&!t._muted&&(t._node.volume=e*o.volume()),r._emit("volume",t._id));return r},fade:function(e,n,t,r){var i=this;if("loaded"!==i._state||i._playLock)return i._queue.push({event:"fade",action:function(){i.fade(e,n,t,r)}}),i;e=Math.min(Math.max(0,parseFloat(e)),1),n=Math.min(Math.max(0,parseFloat(n)),1),t=parseFloat(t),i.volume(e,r);for(var a=i._getSoundIds(r),s=0;s<a.length;s++){var u=i._soundById(a[s]);if(u){if(r||i._stopFade(a[s]),i._webAudio&&!u._muted){var d=o.ctx.currentTime,c=d+t/1e3;u._volume=e,u._node.gain.setValueAtTime(e,d),u._node.gain.linearRampToValueAtTime(n,c)}i._startFadeInterval(u,e,n,t,a[s],void 0===r)}}return i},_startFadeInterval:function(e,n,t,o,r,i){var a=this,s=n,u=t-n,d=Math.abs(u/.01),c=Math.max(4,d>0?o/d:o),l=Date.now();e._fadeTo=t,e._interval=setInterval((function(){var r=(Date.now()-l)/o;l=Date.now(),s+=u*r,s=Math.round(100*s)/100,s=u<0?Math.max(t,s):Math.min(t,s),a._webAudio?e._volume=s:a.volume(s,e._id,!0),i&&(a._volume=s),(t<n&&s<=t||t>n&&s>=t)&&(clearInterval(e._interval),e._interval=null,e._fadeTo=null,a.volume(t,e._id),a._emit("fade",e._id))}),c)},_stopFade:function(e){var n=this,t=n._soundById(e);return t&&t._interval&&(n._webAudio&&t._node.gain.cancelScheduledValues(o.ctx.currentTime),clearInterval(t._interval),t._interval=null,n.volume(t._fadeTo,e),t._fadeTo=null,n._emit("fade",e)),n},loop:function(){var e,n,t,o=this,r=arguments;if(0===r.length)return o._loop;if(1===r.length){if("boolean"!=typeof r[0])return!!(t=o._soundById(parseInt(r[0],10)))&&t._loop;e=r[0],o._loop=e}else 2===r.length&&(e=r[0],n=parseInt(r[1],10));for(var i=o._getSoundIds(n),a=0;a<i.length;a++)(t=o._soundById(i[a]))&&(t._loop=e,o._webAudio&&t._node&&t._node.bufferSource&&(t._node.bufferSource.loop=e,e&&(t._node.bufferSource.loopStart=t._start||0,t._node.bufferSource.loopEnd=t._stop,o.playing(i[a])&&(o.pause(i[a],!0),o.play(i[a],!0)))));return o},rate:function(){var e,n,t,r=this,i=arguments;if(0===i.length)n=r._sounds[0]._id;else if(1===i.length){r._getSoundIds().indexOf(i[0])>=0?n=parseInt(i[0],10):e=parseFloat(i[0])}else 2===i.length&&(e=parseFloat(i[0]),n=parseInt(i[1],10));if("number"!=typeof e)return(t=r._soundById(n))?t._rate:r._rate;if("loaded"!==r._state||r._playLock)return r._queue.push({event:"rate",action:function(){r.rate.apply(r,i)}}),r;void 0===n&&(r._rate=e),n=r._getSoundIds(n);for(var a=0;a<n.length;a++)if(t=r._soundById(n[a])){r.playing(n[a])&&(t._rateSeek=r.seek(n[a]),t._playStart=r._webAudio?o.ctx.currentTime:t._playStart),t._rate=e,r._webAudio&&t._node&&t._node.bufferSource?t._node.bufferSource.playbackRate.setValueAtTime(e,o.ctx.currentTime):t._node&&(t._node.playbackRate=e);var s=r.seek(n[a]),u=1e3*((r._sprite[t._sprite][0]+r._sprite[t._sprite][1])/1e3-s)/Math.abs(t._rate);!r._endTimers[n[a]]&&t._paused||(r._clearTimer(n[a]),r._endTimers[n[a]]=setTimeout(r._ended.bind(r,t),u)),r._emit("rate",t._id)}return r},seek:function(){var e,n,t=this,r=arguments;if(0===r.length)t._sounds.length&&(n=t._sounds[0]._id);else if(1===r.length){t._getSoundIds().indexOf(r[0])>=0?n=parseInt(r[0],10):t._sounds.length&&(n=t._sounds[0]._id,e=parseFloat(r[0]))}else 2===r.length&&(e=parseFloat(r[0]),n=parseInt(r[1],10));if(void 0===n)return 0;if("number"==typeof e&&("loaded"!==t._state||t._playLock))return t._queue.push({event:"seek",action:function(){t.seek.apply(t,r)}}),t;var i=t._soundById(n);if(i){if(!("number"==typeof e&&e>=0)){if(t._webAudio){var a=t.playing(n)?o.ctx.currentTime-i._playStart:0,s=i._rateSeek?i._rateSeek-i._seek:0;return i._seek+(s+a*Math.abs(i._rate))}return i._node.currentTime}var u=t.playing(n);u&&t.pause(n,!0),i._seek=e,i._ended=!1,t._clearTimer(n),t._webAudio||!i._node||isNaN(i._node.duration)||(i._node.currentTime=e);var d=function(){u&&t.play(n,!0),t._emit("seek",n)};if(u&&!t._webAudio){var c=function(){t._playLock?setTimeout(c,0):d()};setTimeout(c,0)}else d()}return t},playing:function(e){var n=this;if("number"==typeof e){var t=n._soundById(e);return!!t&&!t._paused}for(var o=0;o<n._sounds.length;o++)if(!n._sounds[o]._paused)return!0;return!1},duration:function(e){var n=this,t=n._duration,o=n._soundById(e);return o&&(t=n._sprite[o._sprite][1]/1e3),t},state:function(){return this._state},unload:function(){for(var e=this,n=e._sounds,t=0;t<n.length;t++)n[t]._paused||e.stop(n[t]._id),e._webAudio||(e._clearSound(n[t]._node),n[t]._node.removeEventListener("error",n[t]._errorFn,!1),n[t]._node.removeEventListener(o._canPlayEvent,n[t]._loadFn,!1),n[t]._node.removeEventListener("ended",n[t]._endFn,!1),o._releaseHtml5Audio(n[t]._node)),delete n[t]._node,e._clearTimer(n[t]._id);var r=o._howls.indexOf(e);r>=0&&o._howls.splice(r,1);var i=!0;for(t=0;t<o._howls.length;t++)if(o._howls[t]._src===e._src||e._src.indexOf(o._howls[t]._src)>=0){i=!1;break}return a&&i&&delete a[e._src],o.noAudio=!1,e._state="unloaded",e._sounds=[],e=null,null},on:function(e,n,t,o){var r=this["_on"+e];return"function"==typeof n&&r.push(o?{id:t,fn:n,once:o}:{id:t,fn:n}),this},off:function(e,n,t){var o=this,r=o["_on"+e],i=0;if("number"==typeof n&&(t=n,n=null),n||t)for(i=0;i<r.length;i++){var a=t===r[i].id;if(n===r[i].fn&&a||!n&&a){r.splice(i,1);break}}else if(e)o["_on"+e]=[];else{var s=Object.keys(o);for(i=0;i<s.length;i++)0===s[i].indexOf("_on")&&Array.isArray(o[s[i]])&&(o[s[i]]=[])}return o},once:function(e,n,t){return this.on(e,n,t,1),this},_emit:function(e,n,t){for(var o=this,r=o["_on"+e],i=r.length-1;i>=0;i--)r[i].id&&r[i].id!==n&&"load"!==e||(setTimeout(function(e){e.call(this,n,t)}.bind(o,r[i].fn),0),r[i].once&&o.off(e,r[i].fn,r[i].id));return o._loadQueue(e),o},_loadQueue:function(e){var n=this;if(n._queue.length>0){var t=n._queue[0];t.event===e&&(n._queue.shift(),n._loadQueue()),e||t.action()}return n},_ended:function(e){var n=this,t=e._sprite;if(!n._webAudio&&e._node&&!e._node.paused&&!e._node.ended&&e._node.currentTime<e._stop)return setTimeout(n._ended.bind(n,e),100),n;var r=!(!e._loop&&!n._sprite[t][2]);if(n._emit("end",e._id),!n._webAudio&&r&&n.stop(e._id,!0).play(e._id),n._webAudio&&r){n._emit("play",e._id),e._seek=e._start||0,e._rateSeek=0,e._playStart=o.ctx.currentTime;var i=1e3*(e._stop-e._start)/Math.abs(e._rate);n._endTimers[e._id]=setTimeout(n._ended.bind(n,e),i)}return n._webAudio&&!r&&(e._paused=!0,e._ended=!0,e._seek=e._start||0,e._rateSeek=0,n._clearTimer(e._id),n._cleanBuffer(e._node),o._autoSuspend()),n._webAudio||r||n.stop(e._id,!0),n},_clearTimer:function(e){var n=this;if(n._endTimers[e]){if("function"!=typeof n._endTimers[e])clearTimeout(n._endTimers[e]);else{var t=n._soundById(e);t&&t._node&&t._node.removeEventListener("ended",n._endTimers[e],!1)}delete n._endTimers[e]}return n},_soundById:function(e){for(var n=this,t=0;t<n._sounds.length;t++)if(e===n._sounds[t]._id)return n._sounds[t];return null},_inactiveSound:function(){var e=this;e._drain();for(var n=0;n<e._sounds.length;n++)if(e._sounds[n]._ended)return e._sounds[n].reset();return new i(e)},_drain:function(){var e=this,n=e._pool,t=0,o=0;if(!(e._sounds.length<n)){for(o=0;o<e._sounds.length;o++)e._sounds[o]._ended&&t++;for(o=e._sounds.length-1;o>=0;o--){if(t<=n)return;e._sounds[o]._ended&&(e._webAudio&&e._sounds[o]._node&&e._sounds[o]._node.disconnect(0),e._sounds.splice(o,1),t--)}}},_getSoundIds:function(e){if(void 0===e){for(var n=[],t=0;t<this._sounds.length;t++)n.push(this._sounds[t]._id);return n}return[e]},_refreshBuffer:function(e){return e._node.bufferSource=o.ctx.createBufferSource(),e._node.bufferSource.buffer=a[this._src],e._panner?e._node.bufferSource.connect(e._panner):e._node.bufferSource.connect(e._node),e._node.bufferSource.loop=e._loop,e._loop&&(e._node.bufferSource.loopStart=e._start||0,e._node.bufferSource.loopEnd=e._stop||0),e._node.bufferSource.playbackRate.setValueAtTime(e._rate,o.ctx.currentTime),this},_cleanBuffer:function(e){var n=o._navigator&&o._navigator.vendor.indexOf("Apple")>=0;if(!e.bufferSource)return this;if(o._scratchBuffer&&e.bufferSource&&(e.bufferSource.onended=null,e.bufferSource.disconnect(0),n))try{e.bufferSource.buffer=o._scratchBuffer}catch(e){}return e.bufferSource=null,this},_clearSound:function(e){/MSIE |Trident\//.test(o._navigator&&o._navigator.userAgent)||(e.src="data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA")}};var i=function(e){this._parent=e,this.init()};i.prototype={init:function(){var e=this,n=e._parent;return e._muted=n._muted,e._loop=n._loop,e._volume=n._volume,e._rate=n._rate,e._seek=0,e._paused=!0,e._ended=!0,e._sprite="__default",e._id=++o._counter,n._sounds.push(e),e.create(),e},create:function(){var e=this,n=e._parent,t=o._muted||e._muted||e._parent._muted?0:e._volume;return n._webAudio?(e._node=void 0===o.ctx.createGain?o.ctx.createGainNode():o.ctx.createGain(),e._node.gain.setValueAtTime(t,o.ctx.currentTime),e._node.paused=!0,e._node.connect(o.masterGain)):o.noAudio||(e._node=o._obtainHtml5Audio(),e._errorFn=e._errorListener.bind(e),e._node.addEventListener("error",e._errorFn,!1),e._loadFn=e._loadListener.bind(e),e._node.addEventListener(o._canPlayEvent,e._loadFn,!1),e._endFn=e._endListener.bind(e),e._node.addEventListener("ended",e._endFn,!1),e._node.src=n._src,e._node.preload=!0===n._preload?"auto":n._preload,e._node.volume=t*o.volume(),e._node.load()),e},reset:function(){var e=this,n=e._parent;return e._muted=n._muted,e._loop=n._loop,e._volume=n._volume,e._rate=n._rate,e._seek=0,e._rateSeek=0,e._paused=!0,e._ended=!0,e._sprite="__default",e._id=++o._counter,e},_errorListener:function(){var e=this;e._parent._emit("loaderror",e._id,e._node.error?e._node.error.code:0),e._node.removeEventListener("error",e._errorFn,!1)},_loadListener:function(){var e=this,n=e._parent;n._duration=Math.ceil(10*e._node.duration)/10,0===Object.keys(n._sprite).length&&(n._sprite={__default:[0,1e3*n._duration]}),"loaded"!==n._state&&(n._state="loaded",n._emit("load"),n._loadQueue()),e._node.removeEventListener(o._canPlayEvent,e._loadFn,!1)},_endListener:function(){var e=this,n=e._parent;n._duration===1/0&&(n._duration=Math.ceil(10*e._node.duration)/10,n._sprite.__default[1]===1/0&&(n._sprite.__default[1]=1e3*n._duration),n._ended(e)),e._node.removeEventListener("ended",e._endFn,!1)}};var a={},s=function(e){var n=e._src;if(a[n])return e._duration=a[n].duration,void c(e);if(/^data:[^;]+;base64,/.test(n)){for(var t=atob(n.split(",")[1]),o=new Uint8Array(t.length),r=0;r<t.length;++r)o[r]=t.charCodeAt(r);d(o.buffer,e)}else{var i=new XMLHttpRequest;i.open(e._xhr.method,n,!0),i.withCredentials=e._xhr.withCredentials,i.responseType="arraybuffer",e._xhr.headers&&Object.keys(e._xhr.headers).forEach((function(n){i.setRequestHeader(n,e._xhr.headers[n])})),i.onload=function(){var n=(i.status+"")[0];"0"===n||"2"===n||"3"===n?d(i.response,e):e._emit("loaderror",null,"Failed loading audio file with status: "+i.status+".")},i.onerror=function(){e._webAudio&&(e._html5=!0,e._webAudio=!1,e._sounds=[],delete a[n],e.load())},u(i)}},u=function(e){try{e.send()}catch(n){e.onerror()}},d=function(e,n){var t=function(){n._emit("loaderror",null,"Decoding audio data failed.")},r=function(e){e&&n._sounds.length>0?(a[n._src]=e,c(n,e)):t()};"undefined"!=typeof Promise&&1===o.ctx.decodeAudioData.length?o.ctx.decodeAudioData(e).then(r).catch(t):o.ctx.decodeAudioData(e,r,t)},c=function(e,n){n&&!e._duration&&(e._duration=n.duration),0===Object.keys(e._sprite).length&&(e._sprite={__default:[0,1e3*e._duration]}),"loaded"!==e._state&&(e._state="loaded",e._emit("load"),e._loadQueue())},l=function(){if(o.usingWebAudio){try{"undefined"!=typeof AudioContext?o.ctx=new AudioContext:"undefined"!=typeof webkitAudioContext?o.ctx=new webkitAudioContext:o.usingWebAudio=!1}catch(e){o.usingWebAudio=!1}o.ctx||(o.usingWebAudio=!1);var e=/iP(hone|od|ad)/.test(o._navigator&&o._navigator.platform),n=o._navigator&&o._navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/),t=n?parseInt(n[1],10):null;if(e&&t&&t<9){var r=/safari/.test(o._navigator&&o._navigator.userAgent.toLowerCase());o._navigator&&!r&&(o.usingWebAudio=!1)}o.usingWebAudio&&(o.masterGain=void 0===o.ctx.createGain?o.ctx.createGainNode():o.ctx.createGain(),o.masterGain.gain.setValueAtTime(o._muted?0:o._volume,o.ctx.currentTime),o.masterGain.connect(o.ctx.destination)),o._setup()}};t.Howler=o,t.Howl=r,void 0!==e?(e.HowlerGlobal=n,e.Howler=o,e.Howl=r,e.Sound=i):"undefined"!=typeof window&&(window.HowlerGlobal=n,window.Howler=o,window.Howl=r,window.Sound=i)}(),
|
|
31
|
+
/*!
|
|
32
|
+
* Spatial Plugin - Adds support for stereo and 3D audio where Web Audio is supported.
|
|
33
|
+
*
|
|
34
|
+
* howler.js v2.2.4
|
|
35
|
+
* howlerjs.com
|
|
36
|
+
*
|
|
37
|
+
* (c) 2013-2020, James Simpson of GoldFire Studios
|
|
38
|
+
* goldfirestudios.com
|
|
39
|
+
*
|
|
40
|
+
* MIT License
|
|
41
|
+
*/
|
|
42
|
+
function(){var e;HowlerGlobal.prototype._pos=[0,0,0],HowlerGlobal.prototype._orientation=[0,0,-1,0,1,0],HowlerGlobal.prototype.stereo=function(e){var n=this;if(!n.ctx||!n.ctx.listener)return n;for(var t=n._howls.length-1;t>=0;t--)n._howls[t].stereo(e);return n},HowlerGlobal.prototype.pos=function(e,n,t){var o=this;return o.ctx&&o.ctx.listener?(n="number"!=typeof n?o._pos[1]:n,t="number"!=typeof t?o._pos[2]:t,"number"!=typeof e?o._pos:(o._pos=[e,n,t],void 0!==o.ctx.listener.positionX?(o.ctx.listener.positionX.setTargetAtTime(o._pos[0],Howler.ctx.currentTime,.1),o.ctx.listener.positionY.setTargetAtTime(o._pos[1],Howler.ctx.currentTime,.1),o.ctx.listener.positionZ.setTargetAtTime(o._pos[2],Howler.ctx.currentTime,.1)):o.ctx.listener.setPosition(o._pos[0],o._pos[1],o._pos[2]),o)):o},HowlerGlobal.prototype.orientation=function(e,n,t,o,r,i){var a=this;if(!a.ctx||!a.ctx.listener)return a;var s=a._orientation;return n="number"!=typeof n?s[1]:n,t="number"!=typeof t?s[2]:t,o="number"!=typeof o?s[3]:o,r="number"!=typeof r?s[4]:r,i="number"!=typeof i?s[5]:i,"number"!=typeof e?s:(a._orientation=[e,n,t,o,r,i],void 0!==a.ctx.listener.forwardX?(a.ctx.listener.forwardX.setTargetAtTime(e,Howler.ctx.currentTime,.1),a.ctx.listener.forwardY.setTargetAtTime(n,Howler.ctx.currentTime,.1),a.ctx.listener.forwardZ.setTargetAtTime(t,Howler.ctx.currentTime,.1),a.ctx.listener.upX.setTargetAtTime(o,Howler.ctx.currentTime,.1),a.ctx.listener.upY.setTargetAtTime(r,Howler.ctx.currentTime,.1),a.ctx.listener.upZ.setTargetAtTime(i,Howler.ctx.currentTime,.1)):a.ctx.listener.setOrientation(e,n,t,o,r,i),a)},Howl.prototype.init=(e=Howl.prototype.init,function(n){var t=this;return t._orientation=n.orientation||[1,0,0],t._stereo=n.stereo||null,t._pos=n.pos||null,t._pannerAttr={coneInnerAngle:void 0!==n.coneInnerAngle?n.coneInnerAngle:360,coneOuterAngle:void 0!==n.coneOuterAngle?n.coneOuterAngle:360,coneOuterGain:void 0!==n.coneOuterGain?n.coneOuterGain:0,distanceModel:void 0!==n.distanceModel?n.distanceModel:"inverse",maxDistance:void 0!==n.maxDistance?n.maxDistance:1e4,panningModel:void 0!==n.panningModel?n.panningModel:"HRTF",refDistance:void 0!==n.refDistance?n.refDistance:1,rolloffFactor:void 0!==n.rolloffFactor?n.rolloffFactor:1},t._onstereo=n.onstereo?[{fn:n.onstereo}]:[],t._onpos=n.onpos?[{fn:n.onpos}]:[],t._onorientation=n.onorientation?[{fn:n.onorientation}]:[],e.call(this,n)}),Howl.prototype.stereo=function(e,t){var o=this;if(!o._webAudio)return o;if("loaded"!==o._state)return o._queue.push({event:"stereo",action:function(){o.stereo(e,t)}}),o;var r=void 0===Howler.ctx.createStereoPanner?"spatial":"stereo";if(void 0===t){if("number"!=typeof e)return o._stereo;o._stereo=e,o._pos=[e,0,0]}for(var i=o._getSoundIds(t),a=0;a<i.length;a++){var s=o._soundById(i[a]);if(s){if("number"!=typeof e)return s._stereo;s._stereo=e,s._pos=[e,0,0],s._node&&(s._pannerAttr.panningModel="equalpower",s._panner&&s._panner.pan||n(s,r),"spatial"===r?void 0!==s._panner.positionX?(s._panner.positionX.setValueAtTime(e,Howler.ctx.currentTime),s._panner.positionY.setValueAtTime(0,Howler.ctx.currentTime),s._panner.positionZ.setValueAtTime(0,Howler.ctx.currentTime)):s._panner.setPosition(e,0,0):s._panner.pan.setValueAtTime(e,Howler.ctx.currentTime)),o._emit("stereo",s._id)}}return o},Howl.prototype.pos=function(e,t,o,r){var i=this;if(!i._webAudio)return i;if("loaded"!==i._state)return i._queue.push({event:"pos",action:function(){i.pos(e,t,o,r)}}),i;if(t="number"!=typeof t?0:t,o="number"!=typeof o?-.5:o,void 0===r){if("number"!=typeof e)return i._pos;i._pos=[e,t,o]}for(var a=i._getSoundIds(r),s=0;s<a.length;s++){var u=i._soundById(a[s]);if(u){if("number"!=typeof e)return u._pos;u._pos=[e,t,o],u._node&&(u._panner&&!u._panner.pan||n(u,"spatial"),void 0!==u._panner.positionX?(u._panner.positionX.setValueAtTime(e,Howler.ctx.currentTime),u._panner.positionY.setValueAtTime(t,Howler.ctx.currentTime),u._panner.positionZ.setValueAtTime(o,Howler.ctx.currentTime)):u._panner.setPosition(e,t,o)),i._emit("pos",u._id)}}return i},Howl.prototype.orientation=function(e,t,o,r){var i=this;if(!i._webAudio)return i;if("loaded"!==i._state)return i._queue.push({event:"orientation",action:function(){i.orientation(e,t,o,r)}}),i;if(t="number"!=typeof t?i._orientation[1]:t,o="number"!=typeof o?i._orientation[2]:o,void 0===r){if("number"!=typeof e)return i._orientation;i._orientation=[e,t,o]}for(var a=i._getSoundIds(r),s=0;s<a.length;s++){var u=i._soundById(a[s]);if(u){if("number"!=typeof e)return u._orientation;u._orientation=[e,t,o],u._node&&(u._panner||(u._pos||(u._pos=i._pos||[0,0,-.5]),n(u,"spatial")),void 0!==u._panner.orientationX?(u._panner.orientationX.setValueAtTime(e,Howler.ctx.currentTime),u._panner.orientationY.setValueAtTime(t,Howler.ctx.currentTime),u._panner.orientationZ.setValueAtTime(o,Howler.ctx.currentTime)):u._panner.setOrientation(e,t,o)),i._emit("orientation",u._id)}}return i},Howl.prototype.pannerAttr=function(){var e,t,o,r=this,i=arguments;if(!r._webAudio)return r;if(0===i.length)return r._pannerAttr;if(1===i.length){if("object"!=typeof i[0])return(o=r._soundById(parseInt(i[0],10)))?o._pannerAttr:r._pannerAttr;e=i[0],void 0===t&&(e.pannerAttr||(e.pannerAttr={coneInnerAngle:e.coneInnerAngle,coneOuterAngle:e.coneOuterAngle,coneOuterGain:e.coneOuterGain,distanceModel:e.distanceModel,maxDistance:e.maxDistance,refDistance:e.refDistance,rolloffFactor:e.rolloffFactor,panningModel:e.panningModel}),r._pannerAttr={coneInnerAngle:void 0!==e.pannerAttr.coneInnerAngle?e.pannerAttr.coneInnerAngle:r._coneInnerAngle,coneOuterAngle:void 0!==e.pannerAttr.coneOuterAngle?e.pannerAttr.coneOuterAngle:r._coneOuterAngle,coneOuterGain:void 0!==e.pannerAttr.coneOuterGain?e.pannerAttr.coneOuterGain:r._coneOuterGain,distanceModel:void 0!==e.pannerAttr.distanceModel?e.pannerAttr.distanceModel:r._distanceModel,maxDistance:void 0!==e.pannerAttr.maxDistance?e.pannerAttr.maxDistance:r._maxDistance,refDistance:void 0!==e.pannerAttr.refDistance?e.pannerAttr.refDistance:r._refDistance,rolloffFactor:void 0!==e.pannerAttr.rolloffFactor?e.pannerAttr.rolloffFactor:r._rolloffFactor,panningModel:void 0!==e.pannerAttr.panningModel?e.pannerAttr.panningModel:r._panningModel})}else 2===i.length&&(e=i[0],t=parseInt(i[1],10));for(var a=r._getSoundIds(t),s=0;s<a.length;s++)if(o=r._soundById(a[s])){var u=o._pannerAttr;u={coneInnerAngle:void 0!==e.coneInnerAngle?e.coneInnerAngle:u.coneInnerAngle,coneOuterAngle:void 0!==e.coneOuterAngle?e.coneOuterAngle:u.coneOuterAngle,coneOuterGain:void 0!==e.coneOuterGain?e.coneOuterGain:u.coneOuterGain,distanceModel:void 0!==e.distanceModel?e.distanceModel:u.distanceModel,maxDistance:void 0!==e.maxDistance?e.maxDistance:u.maxDistance,refDistance:void 0!==e.refDistance?e.refDistance:u.refDistance,rolloffFactor:void 0!==e.rolloffFactor?e.rolloffFactor:u.rolloffFactor,panningModel:void 0!==e.panningModel?e.panningModel:u.panningModel};var d=o._panner;d||(o._pos||(o._pos=r._pos||[0,0,-.5]),n(o,"spatial"),d=o._panner),d.coneInnerAngle=u.coneInnerAngle,d.coneOuterAngle=u.coneOuterAngle,d.coneOuterGain=u.coneOuterGain,d.distanceModel=u.distanceModel,d.maxDistance=u.maxDistance,d.refDistance=u.refDistance,d.rolloffFactor=u.rolloffFactor,d.panningModel=u.panningModel}return r},Sound.prototype.init=function(e){return function(){var n=this,t=n._parent;n._orientation=t._orientation,n._stereo=t._stereo,n._pos=t._pos,n._pannerAttr=t._pannerAttr,e.call(this),n._stereo?t.stereo(n._stereo):n._pos&&t.pos(n._pos[0],n._pos[1],n._pos[2],n._id)}}(Sound.prototype.init),Sound.prototype.reset=function(e){return function(){var n=this,t=n._parent;return n._orientation=t._orientation,n._stereo=t._stereo,n._pos=t._pos,n._pannerAttr=t._pannerAttr,n._stereo?t.stereo(n._stereo):n._pos?t.pos(n._pos[0],n._pos[1],n._pos[2],n._id):n._panner&&(n._panner.disconnect(0),n._panner=void 0,t._refreshBuffer(n)),e.call(this)}}(Sound.prototype.reset);var n=function(e,n){"spatial"===(n=n||"spatial")?(e._panner=Howler.ctx.createPanner(),e._panner.coneInnerAngle=e._pannerAttr.coneInnerAngle,e._panner.coneOuterAngle=e._pannerAttr.coneOuterAngle,e._panner.coneOuterGain=e._pannerAttr.coneOuterGain,e._panner.distanceModel=e._pannerAttr.distanceModel,e._panner.maxDistance=e._pannerAttr.maxDistance,e._panner.refDistance=e._pannerAttr.refDistance,e._panner.rolloffFactor=e._pannerAttr.rolloffFactor,e._panner.panningModel=e._pannerAttr.panningModel,void 0!==e._panner.positionX?(e._panner.positionX.setValueAtTime(e._pos[0],Howler.ctx.currentTime),e._panner.positionY.setValueAtTime(e._pos[1],Howler.ctx.currentTime),e._panner.positionZ.setValueAtTime(e._pos[2],Howler.ctx.currentTime)):e._panner.setPosition(e._pos[0],e._pos[1],e._pos[2]),void 0!==e._panner.orientationX?(e._panner.orientationX.setValueAtTime(e._orientation[0],Howler.ctx.currentTime),e._panner.orientationY.setValueAtTime(e._orientation[1],Howler.ctx.currentTime),e._panner.orientationZ.setValueAtTime(e._orientation[2],Howler.ctx.currentTime)):e._panner.setOrientation(e._orientation[0],e._orientation[1],e._orientation[2])):(e._panner=Howler.ctx.createStereoPanner(),e._panner.pan.setValueAtTime(e._stereo,Howler.ctx.currentTime)),e._panner.connect(e._node),e._paused||e._parent.pause(e._id,!0).play(e._id,!0)}}()}));function $(e,n,t){F(H).invokeCallbackHandler(e,n,t)}function X(e,n,t){var o,r=null===(o=Ze.currPage)||void 0===o?void 0:o.children;if(Array.isArray(r)&&r.length>0){var i=r[0];i&&i.isWebView&&i.postMessageToWebView({callbackId:e,type:"webInvokeCallbackHandler",params:n})}}var Y={},z={};function J(e,n){var t=Y[e],o=z[e];return null!=t?""!=n.src&&o!=n.src?(t.unload(),delete Y[e],delete z[e],J(e,n)):t:(z[e]=n.src,Y[e]=function(e,n){var t=new U.Howl({autoplay:e.autoplay,loop:e.loop,src:e.src,rate:e.playbackRate,onend:function(){N(K,{innerAudioContextId:n,method:Z.onEnded,data:{}})},onplay:function(){N(K,{innerAudioContextId:n,method:Z.onPlay,data:{buffered:0,currentTime:0,duration:0}})},onpause:function(e){N(K,{innerAudioContextId:e,method:Z.onPause,data:{}})},onstop:function(){N(K,{innerAudioContextId:n,method:Z.onStop,data:{}})},onseek:function(){N(K,{innerAudioContextId:n,method:Z.onSeeked,data:{}})},onplayerror:function(e,n){N(K,{innerAudioContextId:e,method:Z.onError,data:{errMsg:"播放失败 :"+n,errCode:-1}})},onloaderror:function(e,n){N(K,{innerAudioContextId:e,method:Z.onError,data:{errMsg:"播放失败 :"+n,errCode:10002}})}});return t}(n,e))}function Q(e,n,t){var o=Y[n];if(null==o){var r=e+":fail 无法找到innerAudioContextId:"+n+"对应的audio实例";throw $(t,{errMsg:r}),new Error(r)}return o}U.Howler.autoSuspend=!1;var Z={onCanplay:"onCanplay",onEnded:"onEnded",onError:"onError",onPause:"onPause",onPlay:"onPlay",onSeeked:"onSeeked",onSeeking:"onSeeking",onStop:"onStop",onTimeUpdate:"onTimeUpdate",onWaiting:"onWaiting"},K="onInnerAudio";var ee={innerAudio:function(e,n){var t,o=e.method,r=e.data,i=e.innerAudioContextId;switch(o){case"create":break;case"play":(t=J(i,r)).loop(r.loop),t.volume(r.volume),r.isPlayMethod&&t.play();break;case"stop":Q(o,i,n).stop();break;case"seek":(t=Q(o,i,n)).seek(r.position);break;case"pause":Q(o,i,n).pause();break;case"destroy":Q(o,i,n).unload();break;default:throw new Error("无法处理音频method:"+o)}return{errMsg:"innerAudio:ok"}}};function ne(e){return/^http(s?)\:\/\//.test(e)}var te={readFileSync:function(e){var n,t=e.filePath;if(t.startsWith(P))return{data:null,errMsg:"readFileSync:fail not support local file."};t=ne(t=(n=t).endsWith(".wasm")?n+".txt":n)?t:w+t;var o=null,r=null;return M(t,{sync:!0},(function(e,n){o=n,r=e})),null!=o?{data:o,errMsg:"readFileSync:ok"}:null!=r?{data:null,errMsg:"readFileSync:fail "+r.message}:{data:null,errMsg:"readFileSync:fail"}},readFile:function(e,n){var t=e.filePath,o="base64"===e.encoding,r=ne(t)?t:w+t;t.startsWith(P)?$(n,{errMsg:"readFile:fail not support local file: "+t}):M(r,{responseType:o?"arraybuffer":""},(function(e,t){$(n,null==e?{data:o?p(t):t,errMsg:"readFile:ok"}:{errMsg:"readFile:fail "+e.message})}))},access:function(){return{errMsg:"access:ok"}},mkdirSync:function(){return{errMsg:"mkdirSync:ok"}},writeFile:function(){return{errMsg:"writeFile:ok"}},writeFileSync:function(e){return e.filePath,e.data,{errMsg:"writeFileSync:ok"}},unlink:function(e,n){return e.filePath,{errMsg:"unlink:ok"}},downloadFile:function(e,n){var t=e.url,o=e.timeout,r=void 0===o?6e3:o;e.taskId,e.header,e.filePath,_(r,function(e){var n=e.url,t=e.callbackId;return e.filePath,e.header,a(this,void 0,void 0,(function(){return s(this,(function(e){return N(k,{cookies:[],progress:100,totalBytesExpectedToWrite:100,totalBytesWritten:100}),N(x,{cookies:[],header:{}}),$(t,{filePath:n,tempFilePath:n,profile:[],statusCode:200,errMsg:"downloadFile:ok"}),[2]}))}))}({url:t,callbackId:n}),(function(e){$(n,{errMsg:"downloadFile:fail timeout in "+e+"ms."})}))},copyFile:function(e,n){return e.srcPath,e.destPath,$(n,{errMsg:"copyFile:ok fake subpport."},"copyFile")}};var oe=new(function(){function e(){this.reportedEventType=new Set(["ErrorType"])}return Object.defineProperty(e.prototype,"sentry",{get:function(){return window.Sentry},enumerable:!1,configurable:!0}),e.prototype.captureException=function(e,n){var t=this.sentry;null!=t?t.captureException(e,{extra:n,level:"error"}):console.log("Sentry is not ready yet.")},e}()),re=null;function ie(){if(null==re)throw new Error("WxConfig is not ready.");return re}var ae=new t;function se(){ae.on("NavigatorBarTools:onMore",(function(){Ge.showToast({title:"暂未实现该功能"})})),ae.on("NavigatorBarTools:onClose",(function(){var e=G();null!=e&&e.invokeHandler({callbackId:-1,apiName:"exitMiniProgram",params:{},from:"service"})})),ae.on("NavigatorBar:onBack",(function(){we.navigateBack({delta:1}),console.log("onBack")})),ae.on("TabBar:change",(function(e){var n,t,o,r;N("onTabItemTap",{index:e.index,pagePath:e.item.pagePath,text:e.item.text}),we.switchTab({url:e.item.pagePath},-1),n=e.item.pagePath,t={},o=n,null!=(r=ie().windows.pages)&&r[o]&&(t.windowConfig=r[o]),ae.emit("tabItemChanged",t)})),ae.on("invokeCallbackHandler",(function(e){$(e.callbackId,e.data)}))}function ue(e){void 0!==window.__initWebFrame&&window.__initWebFrame(e,ae)}var de={getGlobalVariables:function(e){return"_launchOption"===e.variable?{_launchOption:I}:null},reportApmMonitor:function(e){var n=e.eventName,t=e.payload,o=e.eventType;oe.reportedEventType.has(o)&&oe.captureException(n,t)},addPerformance:function(){},initReady:function(){},updateAppData:function(){},injectHtmlCallback:function(e,n,t){"service"===t&&V().events.emit(E.onInjectHTMLCallback)},pageScrollTo:function(e,n){var t=e.scrollTop;e.duration;var o=Ze.currPage.getWindow();return null==o||o.scrollTo({top:t,behavior:"smooth"}),{errMsg:"pageScrollTo:ok"}},getMenuButtonBoundingClientRect:function(e,n){ae.emit("getMenuButtonBoundingClientRect",e,n)},getAccountInfoSync:function(){var e=window.__extInfo;return{data:{miniProgram:{appId:null==e?void 0:e.extUuid,envVersion:null==e?void 0:e.envVersion,version:""},plugin:{appId:"",version:""}}}},jssdkConfig:function(e,n){var t=e.jsApiList,o=[];if((void 0===t?[]:t).forEach((function(e){null==Ge[e]&&o.push(e)})),!(o.length>0))return X(n,{errMsg:"jssdkConfig:ok"});X(n,{errMsg:"jssdkConfig:fail "+o.join(",")+" 未实现."})}},ce={hideToast:function(e){return ae.emit("hideToast",e),{errMsg:"hideToast:ok"}},showToast:function(e){return ae.emit("showToast",e),{errMsg:"showToast:ok"}},showLoading:function(e){return ae.emit("showLoading",e),{errMsg:"showLoading:ok"}},hideLoading:function(e){return ae.emit("hideLoading",e),{errMsg:"hideLoading:ok"}},showModal:function(e,n){ae.emit("showModal",e,n)},showActionSheet:function(e,n){ae.emit("showActionSheet",e,n)}};function le(e,n){if(e===S)return'<script charset="utf-8" src="'+n.moduleName+'game.js"><\/script>';if("miniProgram"===e)return n.content;throw Error("unsupported projectType: "+e)}var pe=function(e){function n(n){return e.call(this,i(i({},n),{projectType:S}))||this}return r(n,e),n.prototype.injectScript=function(){var e=F(H).getWindow();e.injectHtml(e.document.body,{content:le(this.projectType,{moduleName:this.moduleName})})},n.prototype.getEntry=function(){return e=this.projectType,n={moduleName:this.moduleName},e===S?n.moduleName+"game.js":"";var e,n},n}(function(){function e(e){this.taskId=e.taskId,this.moduleName=e.moduleName,this.projectType=e.projectType,this.status="none"}return e.prototype.notifyProgressUpdate=function(e,n){N("onLoadSubPackageTaskStateChange",i({moduleName:this.moduleName,state:e,taskId:this.taskId},n))},e.prototype.injectScript=function(){},e.prototype.getEntry=function(){},e.prototype.load=function(){return a(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return this.notifyProgressUpdate("progressUpdate",{progress:0}),[4,f(15)];case 1:return e.sent(),this.notifyProgressUpdate("progressUpdate",{progress:50}),[4,f(30)];case 2:return e.sent(),this.injectScript(),this.notifyProgressUpdate("progressUpdate",{progress:100}),[4,f(15)];case 3:return e.sent(),this.status="success",this.notifyProgressUpdate("success",{entryPath:this.getEntry()}),[2]}}))}))},e}()),fe=0,_e={},ve={createLoadSubPackageTask:function(e){var n=e.moduleName,t=_e[n];if(t&&"success"===t.status)return{errMsg:"createLoadSubPackageTask:fail sub package already loaded."};++fe;var o=String(fe);return t=new pe({taskId:o,moduleName:n}),_e[n]=t,t.load(),{errMsg:"createLoadSubPackageTask:ok",loadTaskId:o}}},he={showNavigationBarLoading:function(){return ae.emit("showNavigationBarLoading"),{errMsg:"showNavigationBarLoading:ok"}},setNavigationBarTitle:function(e){return ae.emit("setNavigationBarTitle",e),{errMsg:"setNavigationBarTitle:ok"}},setNavigationBarColor:function(e){return ae.emit("setNavigationBarColor",e),{errMsg:"setNavigationBarColor:ok"}},hideNavigationBarLoading:function(){return ae.emit("hideNavigationBarLoading"),{errMsg:"hideNavigationBarLoading:ok"}},hideHomeButton:function(){}};function me(e,n){var t,o=function(e){e=e.replace(/\.html$/,"");var n=ie(),t=n.subpackages;if(Array.isArray(t)&&t.length>0)return t.find((function(n){return n.pageFullPath.includes(e)}));return null}(e);null==o||(t=o.root,L[t])?n():function(e,n){var t=F(H);t.events.once(E.onInjectHTMLCallback,n),t.loadSubBundle(e.root,e.packageName+".js")}(o,n)}var we={navigateTo:function(e,n){var t=e.url;if(Ze.stack.length>10)return{errMsg:"navigateTo:fail 已到达页面栈上限:10。"};var o=l(t),r=o.path,i=o.query;return me(r,(function(){var e=Ze.go(r);V().events.once(E.onViewDOMContentLoaded,(function(){N("onAppRoute",{path:r,openType:"navigateTo",options:void 0,pipMode:"",query:i,webviewId:e.webviewId},e.webviewId)}))})),{errMsg:"navigateTo:ok"}},navigateBack:function(e){var n=e.delta;try{Ze.back(n)}catch(e){return{errMsg:"navigateBack:fail "+e.message}}var t=Ze.currPage;return N("onAppRoute",{path:t.pagePath,openType:"navigateBack",options:{delta:n},pipMode:"",query:void 0,webviewId:t.webviewId},t.webviewId),{errMsg:"navigateBack:ok"}},reLaunch:function(e,n){var t=e.url,o=l(t),r=o.path,i=o.query;me(r,(function(){Ze.reLaunch(t);var e=Ze.currPage;V().events.once(E.onViewDOMContentLoaded,(function(){N("onAppRoute",{path:r,openType:"reLaunch",options:void 0,pipMode:"",query:i,webviewId:e.webviewId},e.webviewId),$(n,{errMsg:"reLaunch:ok"})}))}))},redirectTo:function(e,n){var t=l(e.url),o=t.path,r=t.query;me(o,(function(){try{Ze.redirectTo(o)}catch(e){return void $(n,{errMsg:"redirectTo:fail "+e.message})}var e=Ze.currPage;V().events.once(E.onViewDOMContentLoaded,(function(){N("onAppRoute",{path:o,openType:"redirectTo",options:void 0,pipMode:"",query:r,webviewId:e.webviewId},e.webviewId),$(n,{errMsg:"redirectTo:ok"})}))}))},switchTab:function(e,n){var t=l(e.url),o=t.path,r=t.query;me(o,(function(){try{Ze.switch(o)}catch(e){return void $(n,{errMsg:"switchTab:fail "+e.message})}var e=Ze.currPage;e.isReady?(N("onAppRoute",{path:o,openType:"switchTab",options:void 0,pipMode:"",query:r,webviewId:e.webviewId},e.webviewId),$(n,{errMsg:"switchTab:ok"})):V().events.once(E.onViewDOMContentLoaded,(function(){N("onAppRoute",{path:o,openType:"switchTab",options:void 0,pipMode:"",query:r,webviewId:e.webviewId},e.webviewId),$(n,{errMsg:"switchTab:ok"})}))}))}};function ge(e){setTimeout(e,17)}function ye(e){return Number((e/1024).toFixed(2))}var be={getStorageSync:function(e){var n=localStorage.getItem(e.key);try{return JSON.parse(n)}catch(e){return n}},getStorage:function(e,n){ge((function(){$(n,{data:be.getStorageSync(e)})}))},setStorageSync:function(e){return localStorage.setItem(e.key,e.data),{errMsg:"setStorageSync:ok"}},setStorage:function(e,n){ge((function(){localStorage.setItem(e.key,e.data),$(n,{errMsg:"setStorage:ok"})}))},removeStorageSync:function(e){return localStorage.removeItem(e.key),{errMsg:"removeStorageSync:ok"}},removeStorage:function(e,n){ge((function(){localStorage.removeItem(e.key),$(n,{errMsg:"removeStorage:ok"})}))},clearStorageSync:function(){return localStorage.clear(),{errMsg:"clearStorageSync:ok"}},clearStorage:function(e,n){ge((function(){localStorage.clear(),$(n,{errMsg:"clearStorage:ok"})}))},getStorageInfoSync:function(){var e=function(){var e=0,n=[];for(var t in localStorage)Object.prototype.hasOwnProperty.call(localStorage,t)&&(e+=localStorage[t].length,n.push(t));return{size:e,keys:n}}(),n=e.size;return{keys:e.keys,currentSize:ye(n),limitSize:ye(10485760)}},getStorageInfo:function(e,n){ge((function(){$(n,i(i({},be.getStorageInfoSync()),{errMsg:"getStorageInfo:ok"}))}))}};function Ae(e){return G().invokeHandler({callbackId:-1,apiName:e.apiName,params:e.params,from:"service"})}function Te(){return window.__extInfo||{}}var Ie=Date.now();var ke=function(e){var n=e.onBefore,t=e.onAfter,o=e.prefix,r=e.logColor,i=e.enableLog,a=void 0===i||i,s=Object.assign({info:"blue",warn:"orange",error:"red",log:"green"},r);function u(){for(var e=[],o=0;o<arguments.length;o++)e[o]=arguments[o];var r=e[0],i=e[1],s=e[2],u=d(),c={prefix:u,msg:i,data:s,desc:u+i};n&&n(c),("function"==typeof a?a(c):a)&&console.log("%c "+c.desc,"color: "+r+";",c.data),t&&t(c)}function d(){return"function"==typeof o?o():o||""}return{log:function(e,n){u(s.log,e,n,"log")},info:function(e,n){u(s.info,e,n,"info")},warn:function(e,n){u(s.warn,e,n,"warn")},error:function(e,n){u(s.error,e,n,"error")}}}({onAfter:function(e){null!=window.hyExt&&window.hyExt.logger.info(e.desc+" "+function(e){try{return JSON.stringify(e)}catch(e){return"stringify error"}}(e.data))},prefix:function(){return"web-sdk-core * date:"+(void 0===e&&(e=new Date),v(e.getHours())+":"+v(e.getMinutes())+":"+v(e.getSeconds())+" extUuid:")+Te().extUuid+" sessionId:"+Ie+" -";var e},enableLog:function(){return"develop"===Te().envVersion}});function xe(){var e=d();return("Android"===e||"IOS"===e)&&window.matchMedia("(orientation: portrait)").matches?"portrait":"landscape"}function Se(){var e,n,t,o=null===(e=Ze.currPage)||void 0===e?void 0:e.getWindow();if(null!=o){var r=o.document;return(null===(n=r.documentElement)||void 0===n?void 0:n.scrollTop)||(null===(t=r.body)||void 0===t?void 0:t.scrollTop)||0}return 0}function Pe(){return i(i({patch:!0},(e=window.innerWidth||390,n=window.innerHeight||844,t=d().toLocaleLowerCase().includes("window")?0:50,{screenWidth:e,screenHeight:n,statusBarHeight:t,devicePixelRatio:o=750/e,pixelRatio:o,windowHeight:n,windowWidth:e,safeArea:{height:n-t,widows:e,top:t,left:0,right:0}})),{scrollY:Se()});var e,n,t,o}var Me={onMemoryWarning:function(){console.error("The onMemoryWarning api is not implement.")},showShareMenu:function(){console.error("The showShareMenu api is not implement.")},getSystemInfoSync:function(){var e=Ce(),n=xe(),t=d();return ke.log("getSystemInfoSync",{windowInfo:e,deviceOrientation:n,system:t}),i({deviceOrientation:n,SDKVersion:"2.26.0",appVersion:"2.37.0",batteryLevel:98,benchmarkLevel:1,bluetoothEnabled:!1,brand:"huya",cameraAuthorized:!0,deviceId:"none",enableDebug:!0,fontSizeSetting:15,frameworkVersion:"0.0.1",inHUYA:!0,language:"zh_CN",locationAuthorized:!0,locationEnabled:!0,microphoneAuthorized:!0,mode:"default",model:"none",notificationAuthorized:!0,platform:"huya",system:t,theme:void 0,version:"8.0.28 "},e)},getWindowInfo:function(){return Ce()}};function Ce(){return c()?Ae({apiName:"getWindowInfo",params:{}}):Pe()}var Be={showTabBar:function(e){return ae.emit("showTabBar",e),{errMsg:"showTabBar:ok"}},hideTabBar:function(e){return ae.emit("hideTabBar",e),{errMsg:"hideTabBar:ok"}},setTabBarStyle:function(e){return ae.emit("setTabBarStyle",e),{errMsg:"setTabBarStyle:ok"}},setTabBarItem:function(e){return ae.emit("setTabBarItem",e),{errMsg:"setTabBarItem:ok"}},setTabBarBadge:function(e){return ae.emit("setTabBarBadge",e),{errMsg:"setTabBarBadge:ok"}},removeTabBarBadge:function(e){return ae.emit("removeTabBarBadge",e),{errMsg:"removeTabBarBadge:ok"}},hideTabBarRedDot:function(e){return ae.emit("hideTabBarRedDot",e),{errMsg:"hideTabBarRedDot:ok"}},showTabBarRedDot:function(e){return ae.emit("showTabBarRedDot",e),{errMsg:"showTabBarRedDot:ok"}}},Ee="insertHTMLWebView",Le="onWebviewLoad",Oe={insertHTMLWebView:function(e,n,t,o){Ze.initNextWebView(Ze.currPage,e.src,e.src).el.addEventListener("load",(function(){N(Le,{webviewId:o},o),j(q+"pageonshow",{})})),N(Ee,e,o)},invokeMiniProgramAPI:function(e,n){console.log(e,n);var t=e.name,o=e.arg,r=Ge[t];null!=r&&r(o,n)},postMessage:function(e,n){N("onBindMessage",e,Ze.currPage.webviewId),X(n,{errMsg:"postMessage:ok"})}},He={appDataChange:function(e){var n=e.params,t=e.from,o=e.webviewIds,r=e.event;e.webviewId,t===A?console.error("not implement for "+t):(!function(e){var n=i({},e.data),t=ie(),o=n.options.path,r=t.windows.pages;null!=r&&r[o]&&(n.windowConfig=r[o]),n.pages=Ze.allPages,ae.emit("appDataChange",n)}(n),W(r,n,o))},__updateAppData:function(e){!function(){var e={},n=ie(),t=Ze.currPage.pagePath.replace(/\.html$/,""),o=n.windows.pages;null!=o&&o[t]&&(e.windowConfig=o[t]),e.pages=Ze.allPages,e.currPage=t,ae.emit("updateAppData",e)}()}};var De={canvasInsert:function(e){var n=e.params,t=e.from;e.webviewIds;var o=e.event,r=e.webviewId;t===A?N(o,n,r):console.error("not implement for "+t)},canvasRemove:function(e){var n=e.params,t=e.from;e.webviewIds;var o=e.event,r=e.webviewId;t===A?N(o,n,r):console.error("not implement for "+t)},CANVAS_EVENT_V2:function(e){var n=e.params,t=e.from;e.webviewIds;var o=e.event,r=e.webviewId;t===A?N(o,n,r):console.error("not implement for "+t)},onCanvasPreloadImage:function(e){var n=e.params,t=e.from;e.webviewIds;var o=e.event,r=e.webviewId;t===A?N(o,n,r):console.error("not implement for "+t)},onCanvasGetImageData:function(e){var n=e.params,t=e.from;e.webviewIds;var o=e.event,r=e.webviewId;t===A?N(o,n,r):console.error("not implement for "+t)},onCanvasPutImageData:function(e){var n=e.params,t=e.from;e.webviewIds;var o=e.event,r=e.webviewId;t===A?N(o,n,r):console.error("not implement for "+t)},canvasActionsChanged:function(e){var n=e.params,t=e.from,o=e.webviewIds,r=e.event;e.webviewId,t===A?console.error("not implement for "+t):W(r,n,o)},invokeCanvasToDataUrl:function(e){var n=e.params,t=e.from,o=e.webviewIds,r=e.event;e.webviewId,t===A?console.error("not implement for "+t):W(r,n,o)},invokeCanvasPutImageData:function(e){var n=e.params,t=e.from,o=e.webviewIds,r=e.event;e.webviewId,t===A?console.error("not implement for "+t):W(r,n,o)},invokeCanvasGetImageData:function(e){var n=e.params,t=e.from,o=e.webviewIds,r=e.event;e.webviewId,t===A?console.error("not implement for "+t):W(r,n,o)},getImageBase64:function(e){var n=e.params;e.from,e.webviewIds;var t,o=e.event,r=e.webviewId,i=n.src;M(/^https?:\/\//.test(t=i)||/^hyfile:\/\//.test(t)?t:w+t,{responseType:"arraybuffer"},(function(e,n){if(null!=e)return"";var t=p(n),a=function(e){var n,t=e.split("/"),o=null===(n=t[t.length-1])||void 0===n?void 0:n.split("."),r=o[0],i=o[1];if(null==i||""==i)throw new Error("url:"+e+"格式错误,无法获取文件信息");return{filename:r,ext:i}}(i);W(o,{src:i,data:"data:image/"+a.ext+";base64,"+t},[r])}))}};var Fe={serviceStart:function(e){var n;n=e.params,re=n;var t=e.params;!function(e){var n=function(e){var n=e.tabBar;return null==n||0===(n.list||[]).length?[e.root]:n.list.map((function(e){return e.pagePath}))}(e);Ze.initFirstPage(n,e.root)}(t),ae.emit("serviceStart",t),ue({wxConfig:t,windowInfo:Ge.getWindowInfo()})},onLaunchCalled:function(e){},serviceReady:function(e){var n=e.params,t=e.webviewIds,o=V(),r=t[0];o.isReady||(Ze.initSlotWebviewId(r),o.events.once(E.onViewDOMContentLoaded,(function(){N("onAppRoute",{path:n.root,openType:"appLaunch",options:void 0,pipMode:"",query:void 0,webviewId:r},r)})),N("onServiceReadyDone",i(i({},I),{webviewId:r}),r),o.isReady=!0)},DOMContentLoaded:function(e){e.params;var n=e.from;e.webviewIds,e.event,e.webviewId;var t=F(H);n===A?(N("DOMContentLoaded",{},Ze.currPage.webviewId),t.events.emit(E.onViewDOMContentLoaded)):console.error("not implement for "+n),ae.emit("closeLaunchMask")},viewReady:function(){var e=Ze.currPage;null!=e&&(e.isReady=!0,e.injectScript(),e.show())},DOMReady:function(){}},Ve={info:function(e){var n=e.params,t=e.from,o=e.webviewIds,r=e.event;e.webviewId,t===A?console.error("not implement for "+t):W(r,n,o)},log:function(e){var n=e.params,t=e.from,o=e.webviewIds,r=e.event;e.webviewId,t===A?console.error("not implement for "+t):W(r,n,o)},initLogs:function(e){var n=e.params,t=e.from,o=e.webviewIds,r=e.event;e.webviewId,t===A?console.error("not implement for "+t):W(r,n,o)},clearLogs:function(e){var n=e.params,t=e.from,o=e.webviewIds,r=e.event;e.webviewId,t===A?console.error("not implement for "+t):W(r,n,o)},onViewLogEvent:function(e){var n=e.params,t=e.from;e.webviewIds;var o=e.event,r=e.webviewId;t===A?N(o,n,r):console.error("not implement for "+t)}},We={INVOKE_METHOD:function(e){var n=e.params,t=e.from;e.webviewIds;var o=e.event,r=e.webviewId;t===A?N(o,n,r):console.error("not implement for "+t)},pageonshow:function(e){var n=e.params,t=e.from,o=e.webviewIds,r=e.event;e.webviewId,t===A?console.error("not implement for "+t):W(r,n,o)},pageonhide:function(e){var n=e.params,t=e.from,o=e.webviewIds,r=e.event;e.webviewId,t===A?console.error("not implement for "+t):(W(r,n,o),j(r,n))},requestLoadFontFace:function(e){var n=e.params,t=e.from,o=e.webviewIds,r=e.event;e.webviewId,t===A?console.error("not implement for "+t):W(r,n,o)},requestLoadGlobalFontFaces:function(e){var n=e.params,t=e.from;e.webviewIds;var o=e.event,r=e.webviewId;t===A?N(o,n,r):console.error("not implement for "+t)},responseLoadGlobalFontFaces:function(e){var n=e.params,t=e.from,o=e.webviewIds,r=e.event;e.webviewId,t===A?console.error("not implement for "+t):W(r,n,o)}},Ne={SPECIAL_PAGE_EVENT:function(e){var n=e.params,t=e.from;e.webviewIds;var o=e.event,r=e.webviewId;t===A?N(o,n,r):console.error("not implement for "+t)},setKeyboardValue:function(e){var n=e.params,t=e.from,o=e.webviewIds,r=e.event;e.webviewId,t===A?console.error("not implement for "+t):W(r,n,o)},PAGE_EVENT:function(e){var n=e.params,t=e.from;e.webviewIds;var o=e.event,r=e.webviewId;t===A?N(o,n,r):console.error("not implement for "+t)},vdSync:function(e){var n=e.params,t=e.from,o=e.webviewIds,r=e.event,i=e.webviewId;t===A?N(r,n,i):W(r,n,o)},vdSyncBatch:function(e){var n=e.params,t=e.from,o=e.webviewIds,r=e.event,i=e.webviewId;t===A?N(r,n,i):W(r,n,o)}},je={videoPlayerInsertFinish:function(e){var n=e.params,t=e.from;e.webviewIds;var o=e.event,r=e.webviewId;t===A?N(o,n,r):console.error("not implement for "+t)},videoActionChanged:function(e){var n=e.params,t=e.from,o=e.webviewIds,r=e.event;e.webviewId,t===A?console.error("not implement for "+t):W(r,n,o)}},Re=i(i(i(i(i(i(i(i({},{gameServiceReady:function(){!function(e){a(this,void 0,void 0,(function(){var n,t,o,r;return s(this,(function(i){switch(i.label){case 0:if(n=window.__deviceOrientation,t=xe(),o="string"==typeof n&&n.includes("landscape"),"landscape"===t||!o||!c())return[3,5];i.label=1;case 1:return i.trys.push([1,3,,4]),[4,_(5e3,new Promise((function(e){var n=G();Ae({apiName:"setDeviceOrientation",params:{value:"landscape"}}),n.$events.once("onDeviceOrientationChange",(function(n){"landscape"===n.value&&e(!0)}))})))];case 2:return i.sent(),e(),[3,4];case 3:return r=i.sent(),e(r),[3,4];case 4:return[3,6];case 5:e(),i.label=6;case 6:return[2]}}))}))}((function(e){if(null!=e)return ae.emit("closeLaunchMask"),void Ge.showToast({title:"游戏加载超时"});ge((function(){console.log("load game script game.js"),V().loadSubBundle("","game.js")}))}))},gameConfigUpdate:function(e){var n=e.params;ue({windowInfo:Ge.getWindowInfo(),wxConfig:n}),ae.emit("closeLaunchMask")}}),Fe),De),He),Ve),We),Ne),je),Ge=i(i(i(i(i(i(i(i(i(i(i({},de),te),ve),we),ce),be),Me),he),Be),Oe),ee);function qe(e){var n,t=e.replace(q,""),o=Re[t];if(null==o){var r=/^video_(.*)_actionChanged$/.test(n=t)?"videoActionChanged":/^canvas(.*)actionsChanged$/.test(n)?"canvasActionsChanged":/^invokeCanvasToDataUrl_(.*)$/.test(n)?"invokeCanvasToDataUrl":/^onCanvasToDataUrl_(.*)$/.test(n)?"onCanvasToDataUrl":/^invokeCanvasPutImageData_(.*)$/.test(n)?"invokeCanvasPutImageData":/^onCanvasPutImageData_(.*)$/.test(n)?"onCanvasPutImageData":/^invokeCanvasGetImageData_(.*)$/.test(n)?"invokeCanvasGetImageData":/^onCanvasGetImageData_(.*)$/.test(n)?"onCanvasGetImageData":n;return{handler:Re[r]||null,formatedEvent:r}}return{handler:o,formatedEvent:t}}var Ue={invokeHandler:function(e){y&&console.log("invokeHander",e);var n=e.C,t=e.paramsString;e.type;var o=e.from,r=e.callbackId,i=e.webviewId,a=JSON.parse(t),s=Ge[n];if(null!=s)return s(a,r,o,i);var u=G();return null!=u?u.invokeHandler({apiName:n,params:a,callbackId:r,from:o}):void 0},publishHandler:function(e){y&&console.log("publishHandler",e);var n=e.event,t=e.from,o=e.paramsString,r=e.webviewId,i=e.webviewIds,a=qe(n),s=a.handler,u=a.formatedEvent,d=JSON.parse(o);if(null!=s)s({event:n,params:d,from:t,webviewId:r,webviewIds:b===t&&i?JSON.parse(i):void 0});else{var c=G();null!=c&&c.publishHandler({formatedEvent:u,event:n,params:d,from:t})}},webInvokeHandler:function(e){y&&console.log("webInvokeHander",e),X(e.callbackId,JSON.parse(e.paramsString))},webPublishHandler:function(e){y&&console.log("webPublishHandler",e),j(e.event,JSON.parse(e.paramsString))}};var $e=[],Xe=function(e){$e.push(e.el.src)},Ye=function(e){$e.pop()},ze=function(e){function n(n){var t=e.call(this,n)||this;return t.webviewId=null,t.pagePath="",t.wrapper=null,t.isDestoryed=!1,t.active=!1,t.__isWebView=!1,t}return r(n,e),Object.defineProperty(n.prototype,"isWebView",{get:function(){return this.__isWebView},set:function(e){this.__isWebView=e,e?Xe(this):Ye(this)},enumerable:!1,configurable:!0}),n.prototype.appendContainer=function(){var e=this.el;e.className="webview",e.setAttribute("frameborder","0"),this.hide();var n=document.getElementById("webview-container");this.wrapper=n,null!=n&&n.appendChild(e)},n.prototype.show=function(){var e=this.el;e.style.zIndex="2",e.style.opacity="1",this.active=!0,Je(this,"show")},n.prototype.hide=function(){var e=this.el;e.style.zIndex="1",e.style.opacity="0",this.active=!1,Je(this,"hide")},n.prototype.updateWebviewId=function(e){this.webviewId=e,this.updateId()},n.prototype.updateId=function(){this.el.id="webview-"+this.webviewId},n.prototype.updateSrc=function(e,n){void 0===n&&(n=g),this.el.src=n,this.pagePath=e},n.prototype.injectScript=function(){var e=this,n=this.getWindow();if(null!=n&&""!=this.pagePath){var t=this.pagePath.endsWith(".html")?this.pagePath:this.pagePath+".html",o=w+t;!function(e,n,t){if(null!=C[e])return C[e];M(e,n,(function(n,o,r){null!==n&&(C[e]=o),t(n,o,r)}))}(o,{sync:!0},(function(t,r){null!=t?console.error("init page fail in "+e.pagePath+", req: "+o+" \n "+t):n.injectHtml(n.document.body,{content:r})}))}},n.prototype.getBridge=function(){return this.getWindow().FinChatJSBridge},n.prototype.sendToView=function(e,n){var t=this;this.sync?(y&&console.log("%c "+e,"color: green;",n,this.webviewId),this.getBridge().subscribeHandler(e,n,this.webviewId)):setTimeout((function(){y&&console.log("%c "+e,"color: green;",n,t.webviewId),t.getBridge().subscribeHandler(e,n,t.webviewId)}))},n.prototype.postMessageToWebView=function(e){var n;y&&console.log("%c postMessageToWebView","color: orange;",e),null===(n=this.el.contentWindow)||void 0===n||n.postMessage(e,"*")},n.prototype.destory=function(){null!==this.wrapper&&this.wrapper.removeChild(this.el),this.el=null,this.wrapper=null,this.isDestoryed=!0,this.active=!1,this.isWebView=!1,Je(this,"destory")},n}(B);function Je(e,n){e.isVHost&&e.children&&e.children.length>0&&e.children.forEach((function(e){e[n]()}))}function Qe(e,n){return e._slots.findIndex((function(e){return e===n.replace(/\.html$/,"")}))}var Ze=new(function(){function e(){this._slotStack=[],this._extraStack=[],this._slots=[],this._webviewId=0,this.rootIndex=0}return Object.defineProperty(e.prototype,"pagePath",{get:function(){var e;return(null===(e=this.currPage)||void 0===e?void 0:e.pagePath)||null},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"currPage",{get:function(){return this.stack[this.stack.length-2]||null},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"top",{get:function(){return this.stack[this.stack.length-1]},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"stack",{get:function(){var e=this._slotStack[this.rootIndex];return null==e?[]:u([e],this._extraStack)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"allPages",{get:function(){var e=this._slotStack[this.rootIndex];return null==e?[]:u([e],this._extraStack.slice(0,this._extraStack.length-1))},enumerable:!1,configurable:!0}),e.prototype.popExtraStack=function(){var e=this._extraStack,n=e.pop(),t=e.pop();return n&&e.push(n),t},e.prototype.resetExtraStack=function(){if(0!==this._extraStack.length){var e=this.top;this._extraStack.slice(0,this._extraStack.length-1).forEach((function(e){e.destory()})),this._extraStack=[e]}},e.prototype.initFirstPage=function(e,n){if(!Array.isArray(e)||0===e.length)throw new Error("slots must exist.");var t=Qe(this,n);this._slots=e;for(var o=0;o<e.length;o++){var r=document.createElement("iframe"),i=new ze(r);i.appendContainer(),this._slotStack.push(i)}t>-1&&(this.rootIndex=t),this._slotStack[this.rootIndex].updateSrc(n),this.initEmptyPage()},e.prototype.initEmptyPage=function(){var e=document.createElement("iframe"),n=new ze(e);n.appendContainer(),this._extraStack.push(n)},e.prototype.initNextPage=function(e,n){var t=this.currPage,o=this.top;return t.hide(),o.updateSrc(e,n),o.updateWebviewId(this._webviewId++),this.initEmptyPage(),o},e.prototype.initNextWebView=function(e,n,t){var o=this.initNextPage(n,t),r=this._extraStack.findIndex((function(e){return e.pagePath===n}));return r>-1&&this._extraStack.splice(r,1),e.children=[o],e.isVHost=!0,o.el.setAttribute("sandbox","allow-same-origin allow-scripts"),o.isWebView=!0,o.show(),o},e.prototype.initSlotWebviewId=function(e){this._webviewId=e,this._slotStack[this.rootIndex].updateWebviewId(this._webviewId++)},e.prototype.reinitPages=function(e){var n=this._slotStack,t=this._extraStack;n.forEach((function(e){e.destory()})),t.forEach((function(e){e.destory()})),this._slotStack=[],this._extraStack=[],this.initFirstPage(this._slots,e),this.currPage.updateWebviewId(this._webviewId++)},e.prototype.reLaunch=function(e){this.reinitPages(e)},e.prototype.redirectTo=function(e){if(Qe(this,e)>-1)throw new Error("不允许跳转到 tabbar 页面:"+e);var n=this._extraStack;if(n.length>1){var t=n.pop();n.pop().destory(),t.updateSrc(e),t.updateWebviewId(this._webviewId++),n.push(t),this.initEmptyPage()}else{null==(t=n.pop())||t.destory(),this._slotStack.forEach((function(e){e.destory()})),this.reinitPages(e)}},e.prototype.switch=function(e,n){n=null!=n?n:Qe(this,e);var t=this._slotStack,o=t[n];if(null==o)throw new Error("switchTab url is invalid: "+e);return this.resetExtraStack(),t.forEach((function(e){e.isReady&&e.hide()})),this.rootIndex=n,o.isReady?o.show():(o.updateWebviewId(this._webviewId++),o.updateSrc(e)),o},e.prototype.go=function(e){var n=Qe(this,e);return n>-1?this.switch(e,n):this.initNextPage(e)},e.prototype.back=function(e){var n,t=this._extraStack.slice(),o=t.pop(),r=t.length;if(e<=0)throw new Error("delta 不能 <= 0");if(r<e)throw new Error("delta 不能超过总栈长度:"+(r+1));var i=r-e,a=t.slice(0,i);(t.slice(i,r).forEach((function(e){e.destory()})),a.length>0)?a[a.length-1].show():null===(n=this._slotStack[this.rootIndex])||void 0===n||n.show();o&&a.push(o),this._extraStack=a},e}()),Ke=function(){function e(){this._invokeServiceCallbackHandler=$,this._dispatchViewEvent=W,this._dispatchServiceEvent=N,this.$events=new t,this._getCurrentPage=function(){return Ze.currPage},this._getAllPages=function(){return Ze.allPages}}return e.prototype.init=function(){R=this},e}();if(window.addEventListener("message",(function(e){var n=e.data;if("object"==typeof n&&null!==n)switch(n.type){case"publish":N(n.event,JSON.parse(n.paramsString));break;case"invoke":return Ue.invokeHandler(n)}})),window.FinChatJSCore=Ue,void 0===window.__initAdapter)throw new Error("Adapter is not ready yet.");window.__initAdapter(Ke),window.addEventListener("DOMContentLoaded",(function(){var e;e={windowInfo:Ge.getWindowInfo(),extInfo:Te()},void 0!==window.__initWebFrameOnContentLoad&&(se(),window.__initWebFrameOnContentLoad(e,ae),G().$events.on("onDeviceOrientationChange",(function(e){ae.emit("onDeviceOrientationChange",e)})))}))}));
|