@dcloudio/uni-mp-toutiao 3.0.0-alpha-3070720230314001 → 3.0.0-alpha-3071220230324001

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.
@@ -3,1162 +3,1162 @@ import { normalizeLocale, LOCALE_EN } from '@dcloudio/uni-i18n';
3
3
  import { LINEFEED, Emitter, onCreateVueApp, invokeCreateVueAppHook } from '@dcloudio/uni-shared';
4
4
 
5
5
  function getBaseSystemInfo() {
6
- return tt.getSystemInfoSync()
6
+ return tt.getSystemInfoSync();
7
7
  }
8
8
 
9
- function validateProtocolFail(name, msg) {
10
- console.warn(`${name}: ${msg}`);
11
- }
12
- function validateProtocol(name, data, protocol, onFail) {
13
- if (!onFail) {
14
- onFail = validateProtocolFail;
15
- }
16
- for (const key in protocol) {
17
- const errMsg = validateProp(key, data[key], protocol[key], !hasOwn(data, key));
18
- if (isString(errMsg)) {
19
- onFail(name, errMsg);
20
- }
21
- }
22
- }
23
- function validateProtocols(name, args, protocol, onFail) {
24
- if (!protocol) {
25
- return;
26
- }
27
- if (!isArray(protocol)) {
28
- return validateProtocol(name, args[0] || Object.create(null), protocol, onFail);
29
- }
30
- const len = protocol.length;
31
- const argsLen = args.length;
32
- for (let i = 0; i < len; i++) {
33
- const opts = protocol[i];
34
- const data = Object.create(null);
35
- if (argsLen > i) {
36
- data[opts.name] = args[i];
37
- }
38
- validateProtocol(name, data, { [opts.name]: opts }, onFail);
39
- }
40
- }
41
- function validateProp(name, value, prop, isAbsent) {
42
- if (!isPlainObject(prop)) {
43
- prop = { type: prop };
44
- }
45
- const { type, required, validator } = prop;
46
- // required!
47
- if (required && isAbsent) {
48
- return 'Missing required args: "' + name + '"';
49
- }
50
- // missing but optional
51
- if (value == null && !required) {
52
- return;
53
- }
54
- // type check
55
- if (type != null) {
56
- let isValid = false;
57
- const types = isArray(type) ? type : [type];
58
- const expectedTypes = [];
59
- // value is valid as long as one of the specified types match
60
- for (let i = 0; i < types.length && !isValid; i++) {
61
- const { valid, expectedType } = assertType(value, types[i]);
62
- expectedTypes.push(expectedType || '');
63
- isValid = valid;
64
- }
65
- if (!isValid) {
66
- return getInvalidTypeMessage(name, value, expectedTypes);
67
- }
68
- }
69
- // custom validator
70
- if (validator) {
71
- return validator(value);
72
- }
73
- }
74
- const isSimpleType = /*#__PURE__*/ makeMap('String,Number,Boolean,Function,Symbol');
75
- function assertType(value, type) {
76
- let valid;
77
- const expectedType = getType(type);
78
- if (isSimpleType(expectedType)) {
79
- const t = typeof value;
80
- valid = t === expectedType.toLowerCase();
81
- // for primitive wrapper objects
82
- if (!valid && t === 'object') {
83
- valid = value instanceof type;
84
- }
85
- }
86
- else if (expectedType === 'Object') {
87
- valid = isObject(value);
88
- }
89
- else if (expectedType === 'Array') {
90
- valid = isArray(value);
91
- }
92
- else {
93
- {
94
- valid = value instanceof type;
95
- }
96
- }
97
- return {
98
- valid,
99
- expectedType,
100
- };
101
- }
102
- function getInvalidTypeMessage(name, value, expectedTypes) {
103
- let message = `Invalid args: type check failed for args "${name}".` +
104
- ` Expected ${expectedTypes.map(capitalize).join(', ')}`;
105
- const expectedType = expectedTypes[0];
106
- const receivedType = toRawType(value);
107
- const expectedValue = styleValue(value, expectedType);
108
- const receivedValue = styleValue(value, receivedType);
109
- // check if we need to specify expected value
110
- if (expectedTypes.length === 1 &&
111
- isExplicable(expectedType) &&
112
- !isBoolean(expectedType, receivedType)) {
113
- message += ` with value ${expectedValue}`;
114
- }
115
- message += `, got ${receivedType} `;
116
- // check if we need to specify received value
117
- if (isExplicable(receivedType)) {
118
- message += `with value ${receivedValue}.`;
119
- }
120
- return message;
121
- }
122
- function getType(ctor) {
123
- const match = ctor && ctor.toString().match(/^\s*function (\w+)/);
124
- return match ? match[1] : '';
125
- }
126
- function styleValue(value, type) {
127
- if (type === 'String') {
128
- return `"${value}"`;
129
- }
130
- else if (type === 'Number') {
131
- return `${Number(value)}`;
132
- }
133
- else {
134
- return `${value}`;
135
- }
136
- }
137
- function isExplicable(type) {
138
- const explicitTypes = ['string', 'number', 'boolean'];
139
- return explicitTypes.some((elem) => type.toLowerCase() === elem);
140
- }
141
- function isBoolean(...args) {
142
- return args.some((elem) => elem.toLowerCase() === 'boolean');
9
+ function validateProtocolFail(name, msg) {
10
+ console.warn(`${name}: ${msg}`);
11
+ }
12
+ function validateProtocol(name, data, protocol, onFail) {
13
+ if (!onFail) {
14
+ onFail = validateProtocolFail;
15
+ }
16
+ for (const key in protocol) {
17
+ const errMsg = validateProp(key, data[key], protocol[key], !hasOwn(data, key));
18
+ if (isString(errMsg)) {
19
+ onFail(name, errMsg);
20
+ }
21
+ }
22
+ }
23
+ function validateProtocols(name, args, protocol, onFail) {
24
+ if (!protocol) {
25
+ return;
26
+ }
27
+ if (!isArray(protocol)) {
28
+ return validateProtocol(name, args[0] || Object.create(null), protocol, onFail);
29
+ }
30
+ const len = protocol.length;
31
+ const argsLen = args.length;
32
+ for (let i = 0; i < len; i++) {
33
+ const opts = protocol[i];
34
+ const data = Object.create(null);
35
+ if (argsLen > i) {
36
+ data[opts.name] = args[i];
37
+ }
38
+ validateProtocol(name, data, { [opts.name]: opts }, onFail);
39
+ }
40
+ }
41
+ function validateProp(name, value, prop, isAbsent) {
42
+ if (!isPlainObject(prop)) {
43
+ prop = { type: prop };
44
+ }
45
+ const { type, required, validator } = prop;
46
+ // required!
47
+ if (required && isAbsent) {
48
+ return 'Missing required args: "' + name + '"';
49
+ }
50
+ // missing but optional
51
+ if (value == null && !required) {
52
+ return;
53
+ }
54
+ // type check
55
+ if (type != null) {
56
+ let isValid = false;
57
+ const types = isArray(type) ? type : [type];
58
+ const expectedTypes = [];
59
+ // value is valid as long as one of the specified types match
60
+ for (let i = 0; i < types.length && !isValid; i++) {
61
+ const { valid, expectedType } = assertType(value, types[i]);
62
+ expectedTypes.push(expectedType || '');
63
+ isValid = valid;
64
+ }
65
+ if (!isValid) {
66
+ return getInvalidTypeMessage(name, value, expectedTypes);
67
+ }
68
+ }
69
+ // custom validator
70
+ if (validator) {
71
+ return validator(value);
72
+ }
73
+ }
74
+ const isSimpleType = /*#__PURE__*/ makeMap('String,Number,Boolean,Function,Symbol');
75
+ function assertType(value, type) {
76
+ let valid;
77
+ const expectedType = getType(type);
78
+ if (isSimpleType(expectedType)) {
79
+ const t = typeof value;
80
+ valid = t === expectedType.toLowerCase();
81
+ // for primitive wrapper objects
82
+ if (!valid && t === 'object') {
83
+ valid = value instanceof type;
84
+ }
85
+ }
86
+ else if (expectedType === 'Object') {
87
+ valid = isObject(value);
88
+ }
89
+ else if (expectedType === 'Array') {
90
+ valid = isArray(value);
91
+ }
92
+ else {
93
+ {
94
+ valid = value instanceof type;
95
+ }
96
+ }
97
+ return {
98
+ valid,
99
+ expectedType,
100
+ };
101
+ }
102
+ function getInvalidTypeMessage(name, value, expectedTypes) {
103
+ let message = `Invalid args: type check failed for args "${name}".` +
104
+ ` Expected ${expectedTypes.map(capitalize).join(', ')}`;
105
+ const expectedType = expectedTypes[0];
106
+ const receivedType = toRawType(value);
107
+ const expectedValue = styleValue(value, expectedType);
108
+ const receivedValue = styleValue(value, receivedType);
109
+ // check if we need to specify expected value
110
+ if (expectedTypes.length === 1 &&
111
+ isExplicable(expectedType) &&
112
+ !isBoolean(expectedType, receivedType)) {
113
+ message += ` with value ${expectedValue}`;
114
+ }
115
+ message += `, got ${receivedType} `;
116
+ // check if we need to specify received value
117
+ if (isExplicable(receivedType)) {
118
+ message += `with value ${receivedValue}.`;
119
+ }
120
+ return message;
121
+ }
122
+ function getType(ctor) {
123
+ const match = ctor && ctor.toString().match(/^\s*function (\w+)/);
124
+ return match ? match[1] : '';
125
+ }
126
+ function styleValue(value, type) {
127
+ if (type === 'String') {
128
+ return `"${value}"`;
129
+ }
130
+ else if (type === 'Number') {
131
+ return `${Number(value)}`;
132
+ }
133
+ else {
134
+ return `${value}`;
135
+ }
136
+ }
137
+ function isExplicable(type) {
138
+ const explicitTypes = ['string', 'number', 'boolean'];
139
+ return explicitTypes.some((elem) => type.toLowerCase() === elem);
140
+ }
141
+ function isBoolean(...args) {
142
+ return args.some((elem) => elem.toLowerCase() === 'boolean');
143
143
  }
144
144
 
145
- function tryCatch(fn) {
146
- return function () {
147
- try {
148
- return fn.apply(fn, arguments);
149
- }
150
- catch (e) {
151
- // TODO
152
- console.error(e);
153
- }
154
- };
145
+ function tryCatch(fn) {
146
+ return function () {
147
+ try {
148
+ return fn.apply(fn, arguments);
149
+ }
150
+ catch (e) {
151
+ // TODO
152
+ console.error(e);
153
+ }
154
+ };
155
155
  }
156
156
 
157
- let invokeCallbackId = 1;
158
- const invokeCallbacks = {};
159
- function addInvokeCallback(id, name, callback, keepAlive = false) {
160
- invokeCallbacks[id] = {
161
- name,
162
- keepAlive,
163
- callback,
164
- };
165
- return id;
166
- }
167
- // onNativeEventReceive((event,data)=>{}) 需要两个参数,目前写死最多两个参数
168
- function invokeCallback(id, res, extras) {
169
- if (typeof id === 'number') {
170
- const opts = invokeCallbacks[id];
171
- if (opts) {
172
- if (!opts.keepAlive) {
173
- delete invokeCallbacks[id];
174
- }
175
- return opts.callback(res, extras);
176
- }
177
- }
178
- return res;
179
- }
180
- const API_SUCCESS = 'success';
181
- const API_FAIL = 'fail';
182
- const API_COMPLETE = 'complete';
183
- function getApiCallbacks(args) {
184
- const apiCallbacks = {};
185
- for (const name in args) {
186
- const fn = args[name];
187
- if (isFunction(fn)) {
188
- apiCallbacks[name] = tryCatch(fn);
189
- delete args[name];
190
- }
191
- }
192
- return apiCallbacks;
193
- }
194
- function normalizeErrMsg$1(errMsg, name) {
195
- if (!errMsg || errMsg.indexOf(':fail') === -1) {
196
- return name + ':ok';
197
- }
198
- return name + errMsg.substring(errMsg.indexOf(':fail'));
199
- }
200
- function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } = {}) {
201
- if (!isPlainObject(args)) {
202
- args = {};
203
- }
204
- const { success, fail, complete } = getApiCallbacks(args);
205
- const hasSuccess = isFunction(success);
206
- const hasFail = isFunction(fail);
207
- const hasComplete = isFunction(complete);
208
- const callbackId = invokeCallbackId++;
209
- addInvokeCallback(callbackId, name, (res) => {
210
- res = res || {};
211
- res.errMsg = normalizeErrMsg$1(res.errMsg, name);
212
- isFunction(beforeAll) && beforeAll(res);
213
- if (res.errMsg === name + ':ok') {
214
- isFunction(beforeSuccess) && beforeSuccess(res, args);
215
- hasSuccess && success(res);
216
- }
217
- else {
218
- hasFail && fail(res);
219
- }
220
- hasComplete && complete(res);
221
- });
222
- return callbackId;
157
+ let invokeCallbackId = 1;
158
+ const invokeCallbacks = {};
159
+ function addInvokeCallback(id, name, callback, keepAlive = false) {
160
+ invokeCallbacks[id] = {
161
+ name,
162
+ keepAlive,
163
+ callback,
164
+ };
165
+ return id;
166
+ }
167
+ // onNativeEventReceive((event,data)=>{}) 需要两个参数,目前写死最多两个参数
168
+ function invokeCallback(id, res, extras) {
169
+ if (typeof id === 'number') {
170
+ const opts = invokeCallbacks[id];
171
+ if (opts) {
172
+ if (!opts.keepAlive) {
173
+ delete invokeCallbacks[id];
174
+ }
175
+ return opts.callback(res, extras);
176
+ }
177
+ }
178
+ return res;
179
+ }
180
+ const API_SUCCESS = 'success';
181
+ const API_FAIL = 'fail';
182
+ const API_COMPLETE = 'complete';
183
+ function getApiCallbacks(args) {
184
+ const apiCallbacks = {};
185
+ for (const name in args) {
186
+ const fn = args[name];
187
+ if (isFunction(fn)) {
188
+ apiCallbacks[name] = tryCatch(fn);
189
+ delete args[name];
190
+ }
191
+ }
192
+ return apiCallbacks;
193
+ }
194
+ function normalizeErrMsg$1(errMsg, name) {
195
+ if (!errMsg || errMsg.indexOf(':fail') === -1) {
196
+ return name + ':ok';
197
+ }
198
+ return name + errMsg.substring(errMsg.indexOf(':fail'));
199
+ }
200
+ function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } = {}) {
201
+ if (!isPlainObject(args)) {
202
+ args = {};
203
+ }
204
+ const { success, fail, complete } = getApiCallbacks(args);
205
+ const hasSuccess = isFunction(success);
206
+ const hasFail = isFunction(fail);
207
+ const hasComplete = isFunction(complete);
208
+ const callbackId = invokeCallbackId++;
209
+ addInvokeCallback(callbackId, name, (res) => {
210
+ res = res || {};
211
+ res.errMsg = normalizeErrMsg$1(res.errMsg, name);
212
+ isFunction(beforeAll) && beforeAll(res);
213
+ if (res.errMsg === name + ':ok') {
214
+ isFunction(beforeSuccess) && beforeSuccess(res, args);
215
+ hasSuccess && success(res);
216
+ }
217
+ else {
218
+ hasFail && fail(res);
219
+ }
220
+ hasComplete && complete(res);
221
+ });
222
+ return callbackId;
223
223
  }
224
224
 
225
- const HOOK_SUCCESS = 'success';
226
- const HOOK_FAIL = 'fail';
227
- const HOOK_COMPLETE = 'complete';
228
- const globalInterceptors = {};
229
- const scopedInterceptors = {};
230
- function wrapperHook(hook, params) {
231
- return function (data) {
232
- return hook(data, params) || data;
233
- };
234
- }
235
- function queue(hooks, data, params) {
236
- let promise = false;
237
- for (let i = 0; i < hooks.length; i++) {
238
- const hook = hooks[i];
239
- if (promise) {
240
- promise = Promise.resolve(wrapperHook(hook, params));
241
- }
242
- else {
243
- const res = hook(data, params);
244
- if (isPromise(res)) {
245
- promise = Promise.resolve(res);
246
- }
247
- if (res === false) {
248
- return {
249
- then() { },
250
- catch() { },
251
- };
252
- }
253
- }
254
- }
255
- return (promise || {
256
- then(callback) {
257
- return callback(data);
258
- },
259
- catch() { },
260
- });
261
- }
262
- function wrapperOptions(interceptors, options = {}) {
263
- [HOOK_SUCCESS, HOOK_FAIL, HOOK_COMPLETE].forEach((name) => {
264
- const hooks = interceptors[name];
265
- if (!isArray(hooks)) {
266
- return;
267
- }
268
- const oldCallback = options[name];
269
- options[name] = function callbackInterceptor(res) {
270
- queue(hooks, res, options).then((res) => {
271
- return (isFunction(oldCallback) && oldCallback(res)) || res;
272
- });
273
- };
274
- });
275
- return options;
276
- }
277
- function wrapperReturnValue(method, returnValue) {
278
- const returnValueHooks = [];
279
- if (isArray(globalInterceptors.returnValue)) {
280
- returnValueHooks.push(...globalInterceptors.returnValue);
281
- }
282
- const interceptor = scopedInterceptors[method];
283
- if (interceptor && isArray(interceptor.returnValue)) {
284
- returnValueHooks.push(...interceptor.returnValue);
285
- }
286
- returnValueHooks.forEach((hook) => {
287
- returnValue = hook(returnValue) || returnValue;
288
- });
289
- return returnValue;
290
- }
291
- function getApiInterceptorHooks(method) {
292
- const interceptor = Object.create(null);
293
- Object.keys(globalInterceptors).forEach((hook) => {
294
- if (hook !== 'returnValue') {
295
- interceptor[hook] = globalInterceptors[hook].slice();
296
- }
297
- });
298
- const scopedInterceptor = scopedInterceptors[method];
299
- if (scopedInterceptor) {
300
- Object.keys(scopedInterceptor).forEach((hook) => {
301
- if (hook !== 'returnValue') {
302
- interceptor[hook] = (interceptor[hook] || []).concat(scopedInterceptor[hook]);
303
- }
304
- });
305
- }
306
- return interceptor;
307
- }
308
- function invokeApi(method, api, options, params) {
309
- const interceptor = getApiInterceptorHooks(method);
310
- if (interceptor && Object.keys(interceptor).length) {
311
- if (isArray(interceptor.invoke)) {
312
- const res = queue(interceptor.invoke, options);
313
- return res.then((options) => {
314
- // 重新访问 getApiInterceptorHooks, 允许 invoke 中再次调用 addInterceptor,removeInterceptor
315
- return api(wrapperOptions(getApiInterceptorHooks(method), options), ...params);
316
- });
317
- }
318
- else {
319
- return api(wrapperOptions(interceptor, options), ...params);
320
- }
321
- }
322
- return api(options, ...params);
225
+ const HOOK_SUCCESS = 'success';
226
+ const HOOK_FAIL = 'fail';
227
+ const HOOK_COMPLETE = 'complete';
228
+ const globalInterceptors = {};
229
+ const scopedInterceptors = {};
230
+ function wrapperHook(hook, params) {
231
+ return function (data) {
232
+ return hook(data, params) || data;
233
+ };
234
+ }
235
+ function queue(hooks, data, params) {
236
+ let promise = false;
237
+ for (let i = 0; i < hooks.length; i++) {
238
+ const hook = hooks[i];
239
+ if (promise) {
240
+ promise = Promise.resolve(wrapperHook(hook, params));
241
+ }
242
+ else {
243
+ const res = hook(data, params);
244
+ if (isPromise(res)) {
245
+ promise = Promise.resolve(res);
246
+ }
247
+ if (res === false) {
248
+ return {
249
+ then() { },
250
+ catch() { },
251
+ };
252
+ }
253
+ }
254
+ }
255
+ return (promise || {
256
+ then(callback) {
257
+ return callback(data);
258
+ },
259
+ catch() { },
260
+ });
261
+ }
262
+ function wrapperOptions(interceptors, options = {}) {
263
+ [HOOK_SUCCESS, HOOK_FAIL, HOOK_COMPLETE].forEach((name) => {
264
+ const hooks = interceptors[name];
265
+ if (!isArray(hooks)) {
266
+ return;
267
+ }
268
+ const oldCallback = options[name];
269
+ options[name] = function callbackInterceptor(res) {
270
+ queue(hooks, res, options).then((res) => {
271
+ return (isFunction(oldCallback) && oldCallback(res)) || res;
272
+ });
273
+ };
274
+ });
275
+ return options;
276
+ }
277
+ function wrapperReturnValue(method, returnValue) {
278
+ const returnValueHooks = [];
279
+ if (isArray(globalInterceptors.returnValue)) {
280
+ returnValueHooks.push(...globalInterceptors.returnValue);
281
+ }
282
+ const interceptor = scopedInterceptors[method];
283
+ if (interceptor && isArray(interceptor.returnValue)) {
284
+ returnValueHooks.push(...interceptor.returnValue);
285
+ }
286
+ returnValueHooks.forEach((hook) => {
287
+ returnValue = hook(returnValue) || returnValue;
288
+ });
289
+ return returnValue;
290
+ }
291
+ function getApiInterceptorHooks(method) {
292
+ const interceptor = Object.create(null);
293
+ Object.keys(globalInterceptors).forEach((hook) => {
294
+ if (hook !== 'returnValue') {
295
+ interceptor[hook] = globalInterceptors[hook].slice();
296
+ }
297
+ });
298
+ const scopedInterceptor = scopedInterceptors[method];
299
+ if (scopedInterceptor) {
300
+ Object.keys(scopedInterceptor).forEach((hook) => {
301
+ if (hook !== 'returnValue') {
302
+ interceptor[hook] = (interceptor[hook] || []).concat(scopedInterceptor[hook]);
303
+ }
304
+ });
305
+ }
306
+ return interceptor;
307
+ }
308
+ function invokeApi(method, api, options, params) {
309
+ const interceptor = getApiInterceptorHooks(method);
310
+ if (interceptor && Object.keys(interceptor).length) {
311
+ if (isArray(interceptor.invoke)) {
312
+ const res = queue(interceptor.invoke, options);
313
+ return res.then((options) => {
314
+ // 重新访问 getApiInterceptorHooks, 允许 invoke 中再次调用 addInterceptor,removeInterceptor
315
+ return api(wrapperOptions(getApiInterceptorHooks(method), options), ...params);
316
+ });
317
+ }
318
+ else {
319
+ return api(wrapperOptions(interceptor, options), ...params);
320
+ }
321
+ }
322
+ return api(options, ...params);
323
323
  }
324
324
 
325
- function hasCallback(args) {
326
- if (isPlainObject(args) &&
327
- [API_SUCCESS, API_FAIL, API_COMPLETE].find((cb) => isFunction(args[cb]))) {
328
- return true;
329
- }
330
- return false;
331
- }
332
- function handlePromise(promise) {
333
- // if (__UNI_FEATURE_PROMISE__) {
334
- // return promise
335
- // .then((data) => {
336
- // return [null, data]
337
- // })
338
- // .catch((err) => [err])
339
- // }
340
- return promise;
341
- }
342
- function promisify$1(name, fn) {
343
- return (args = {}, ...rest) => {
344
- if (hasCallback(args)) {
345
- return wrapperReturnValue(name, invokeApi(name, fn, args, rest));
346
- }
347
- return wrapperReturnValue(name, handlePromise(new Promise((resolve, reject) => {
348
- invokeApi(name, fn, extend(args, { success: resolve, fail: reject }), rest);
349
- })));
350
- };
325
+ function hasCallback(args) {
326
+ if (isPlainObject(args) &&
327
+ [API_SUCCESS, API_FAIL, API_COMPLETE].find((cb) => isFunction(args[cb]))) {
328
+ return true;
329
+ }
330
+ return false;
331
+ }
332
+ function handlePromise(promise) {
333
+ // if (__UNI_FEATURE_PROMISE__) {
334
+ // return promise
335
+ // .then((data) => {
336
+ // return [null, data]
337
+ // })
338
+ // .catch((err) => [err])
339
+ // }
340
+ return promise;
341
+ }
342
+ function promisify$1(name, fn) {
343
+ return (args = {}, ...rest) => {
344
+ if (hasCallback(args)) {
345
+ return wrapperReturnValue(name, invokeApi(name, fn, args, rest));
346
+ }
347
+ return wrapperReturnValue(name, handlePromise(new Promise((resolve, reject) => {
348
+ invokeApi(name, fn, extend(args, { success: resolve, fail: reject }), rest);
349
+ })));
350
+ };
351
351
  }
352
352
 
353
- function formatApiArgs(args, options) {
354
- const params = args[0];
355
- if (!options ||
356
- (!isPlainObject(options.formatArgs) && isPlainObject(params))) {
357
- return;
358
- }
359
- const formatArgs = options.formatArgs;
360
- const keys = Object.keys(formatArgs);
361
- for (let i = 0; i < keys.length; i++) {
362
- const name = keys[i];
363
- const formatterOrDefaultValue = formatArgs[name];
364
- if (isFunction(formatterOrDefaultValue)) {
365
- const errMsg = formatterOrDefaultValue(args[0][name], params);
366
- if (isString(errMsg)) {
367
- return errMsg;
368
- }
369
- }
370
- else {
371
- // defaultValue
372
- if (!hasOwn(params, name)) {
373
- params[name] = formatterOrDefaultValue;
374
- }
375
- }
376
- }
377
- }
378
- function invokeSuccess(id, name, res) {
379
- return invokeCallback(id, extend((res || {}), { errMsg: name + ':ok' }));
380
- }
381
- function invokeFail(id, name, errMsg, errRes) {
382
- return invokeCallback(id, extend({ errMsg: name + ':fail' + (errMsg ? ' ' + errMsg : '') }, errRes));
383
- }
384
- function beforeInvokeApi(name, args, protocol, options) {
385
- if ((process.env.NODE_ENV !== 'production')) {
386
- validateProtocols(name, args, protocol);
387
- }
388
- if (options && options.beforeInvoke) {
389
- const errMsg = options.beforeInvoke(args);
390
- if (isString(errMsg)) {
391
- return errMsg;
392
- }
393
- }
394
- const errMsg = formatApiArgs(args, options);
395
- if (errMsg) {
396
- return errMsg;
397
- }
398
- }
399
- function normalizeErrMsg(errMsg) {
400
- if (!errMsg || isString(errMsg)) {
401
- return errMsg;
402
- }
403
- if (errMsg.stack) {
404
- console.error(errMsg.message + LINEFEED + errMsg.stack);
405
- return errMsg.message;
406
- }
407
- return errMsg;
408
- }
409
- function wrapperTaskApi(name, fn, protocol, options) {
410
- return (args) => {
411
- const id = createAsyncApiCallback(name, args, options);
412
- const errMsg = beforeInvokeApi(name, [args], protocol, options);
413
- if (errMsg) {
414
- return invokeFail(id, name, errMsg);
415
- }
416
- return fn(args, {
417
- resolve: (res) => invokeSuccess(id, name, res),
418
- reject: (errMsg, errRes) => invokeFail(id, name, normalizeErrMsg(errMsg), errRes),
419
- });
420
- };
421
- }
422
- function wrapperSyncApi(name, fn, protocol, options) {
423
- return (...args) => {
424
- const errMsg = beforeInvokeApi(name, args, protocol, options);
425
- if (errMsg) {
426
- throw new Error(errMsg);
427
- }
428
- return fn.apply(null, args);
429
- };
430
- }
431
- function wrapperAsyncApi(name, fn, protocol, options) {
432
- return wrapperTaskApi(name, fn, protocol, options);
433
- }
434
- function defineSyncApi(name, fn, protocol, options) {
435
- return wrapperSyncApi(name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options);
436
- }
437
- function defineAsyncApi(name, fn, protocol, options) {
438
- return promisify$1(name, wrapperAsyncApi(name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options));
353
+ function formatApiArgs(args, options) {
354
+ const params = args[0];
355
+ if (!options ||
356
+ (!isPlainObject(options.formatArgs) && isPlainObject(params))) {
357
+ return;
358
+ }
359
+ const formatArgs = options.formatArgs;
360
+ const keys = Object.keys(formatArgs);
361
+ for (let i = 0; i < keys.length; i++) {
362
+ const name = keys[i];
363
+ const formatterOrDefaultValue = formatArgs[name];
364
+ if (isFunction(formatterOrDefaultValue)) {
365
+ const errMsg = formatterOrDefaultValue(args[0][name], params);
366
+ if (isString(errMsg)) {
367
+ return errMsg;
368
+ }
369
+ }
370
+ else {
371
+ // defaultValue
372
+ if (!hasOwn(params, name)) {
373
+ params[name] = formatterOrDefaultValue;
374
+ }
375
+ }
376
+ }
377
+ }
378
+ function invokeSuccess(id, name, res) {
379
+ return invokeCallback(id, extend((res || {}), { errMsg: name + ':ok' }));
380
+ }
381
+ function invokeFail(id, name, errMsg, errRes) {
382
+ return invokeCallback(id, extend({ errMsg: name + ':fail' + (errMsg ? ' ' + errMsg : '') }, errRes));
383
+ }
384
+ function beforeInvokeApi(name, args, protocol, options) {
385
+ if ((process.env.NODE_ENV !== 'production')) {
386
+ validateProtocols(name, args, protocol);
387
+ }
388
+ if (options && options.beforeInvoke) {
389
+ const errMsg = options.beforeInvoke(args);
390
+ if (isString(errMsg)) {
391
+ return errMsg;
392
+ }
393
+ }
394
+ const errMsg = formatApiArgs(args, options);
395
+ if (errMsg) {
396
+ return errMsg;
397
+ }
398
+ }
399
+ function normalizeErrMsg(errMsg) {
400
+ if (!errMsg || isString(errMsg)) {
401
+ return errMsg;
402
+ }
403
+ if (errMsg.stack) {
404
+ console.error(errMsg.message + LINEFEED + errMsg.stack);
405
+ return errMsg.message;
406
+ }
407
+ return errMsg;
408
+ }
409
+ function wrapperTaskApi(name, fn, protocol, options) {
410
+ return (args) => {
411
+ const id = createAsyncApiCallback(name, args, options);
412
+ const errMsg = beforeInvokeApi(name, [args], protocol, options);
413
+ if (errMsg) {
414
+ return invokeFail(id, name, errMsg);
415
+ }
416
+ return fn(args, {
417
+ resolve: (res) => invokeSuccess(id, name, res),
418
+ reject: (errMsg, errRes) => invokeFail(id, name, normalizeErrMsg(errMsg), errRes),
419
+ });
420
+ };
421
+ }
422
+ function wrapperSyncApi(name, fn, protocol, options) {
423
+ return (...args) => {
424
+ const errMsg = beforeInvokeApi(name, args, protocol, options);
425
+ if (errMsg) {
426
+ throw new Error(errMsg);
427
+ }
428
+ return fn.apply(null, args);
429
+ };
430
+ }
431
+ function wrapperAsyncApi(name, fn, protocol, options) {
432
+ return wrapperTaskApi(name, fn, protocol, options);
433
+ }
434
+ function defineSyncApi(name, fn, protocol, options) {
435
+ return wrapperSyncApi(name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options);
436
+ }
437
+ function defineAsyncApi(name, fn, protocol, options) {
438
+ return promisify$1(name, wrapperAsyncApi(name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options));
439
439
  }
440
440
 
441
- const API_UPX2PX = 'upx2px';
442
- const Upx2pxProtocol = [
443
- {
444
- name: 'upx',
445
- type: [Number, String],
446
- required: true,
447
- },
441
+ const API_UPX2PX = 'upx2px';
442
+ const Upx2pxProtocol = [
443
+ {
444
+ name: 'upx',
445
+ type: [Number, String],
446
+ required: true,
447
+ },
448
448
  ];
449
449
 
450
- const EPS = 1e-4;
451
- const BASE_DEVICE_WIDTH = 750;
452
- let isIOS = false;
453
- let deviceWidth = 0;
454
- let deviceDPR = 0;
455
- function checkDeviceWidth() {
456
- const { platform, pixelRatio, windowWidth } = getBaseSystemInfo();
457
- deviceWidth = windowWidth;
458
- deviceDPR = pixelRatio;
459
- isIOS = platform === 'ios';
460
- }
461
- const upx2px = defineSyncApi(API_UPX2PX, (number, newDeviceWidth) => {
462
- if (deviceWidth === 0) {
463
- checkDeviceWidth();
464
- }
465
- number = Number(number);
466
- if (number === 0) {
467
- return 0;
468
- }
469
- let width = newDeviceWidth || deviceWidth;
470
- let result = (number / BASE_DEVICE_WIDTH) * width;
471
- if (result < 0) {
472
- result = -result;
473
- }
474
- result = Math.floor(result + EPS);
475
- if (result === 0) {
476
- if (deviceDPR === 1 || !isIOS) {
477
- result = 1;
478
- }
479
- else {
480
- result = 0.5;
481
- }
482
- }
483
- return number < 0 ? -result : result;
450
+ const EPS = 1e-4;
451
+ const BASE_DEVICE_WIDTH = 750;
452
+ let isIOS = false;
453
+ let deviceWidth = 0;
454
+ let deviceDPR = 0;
455
+ function checkDeviceWidth() {
456
+ const { platform, pixelRatio, windowWidth } = getBaseSystemInfo();
457
+ deviceWidth = windowWidth;
458
+ deviceDPR = pixelRatio;
459
+ isIOS = platform === 'ios';
460
+ }
461
+ const upx2px = defineSyncApi(API_UPX2PX, (number, newDeviceWidth) => {
462
+ if (deviceWidth === 0) {
463
+ checkDeviceWidth();
464
+ }
465
+ number = Number(number);
466
+ if (number === 0) {
467
+ return 0;
468
+ }
469
+ let width = newDeviceWidth || deviceWidth;
470
+ let result = (number / BASE_DEVICE_WIDTH) * width;
471
+ if (result < 0) {
472
+ result = -result;
473
+ }
474
+ result = Math.floor(result + EPS);
475
+ if (result === 0) {
476
+ if (deviceDPR === 1 || !isIOS) {
477
+ result = 1;
478
+ }
479
+ else {
480
+ result = 0.5;
481
+ }
482
+ }
483
+ return number < 0 ? -result : result;
484
484
  }, Upx2pxProtocol);
485
485
 
486
- const API_ADD_INTERCEPTOR = 'addInterceptor';
487
- const API_REMOVE_INTERCEPTOR = 'removeInterceptor';
488
- const AddInterceptorProtocol = [
489
- {
490
- name: 'method',
491
- type: [String, Object],
492
- required: true,
493
- },
494
- ];
486
+ const API_ADD_INTERCEPTOR = 'addInterceptor';
487
+ const API_REMOVE_INTERCEPTOR = 'removeInterceptor';
488
+ const AddInterceptorProtocol = [
489
+ {
490
+ name: 'method',
491
+ type: [String, Object],
492
+ required: true,
493
+ },
494
+ ];
495
495
  const RemoveInterceptorProtocol = AddInterceptorProtocol;
496
496
 
497
- function mergeInterceptorHook(interceptors, interceptor) {
498
- Object.keys(interceptor).forEach((hook) => {
499
- if (isFunction(interceptor[hook])) {
500
- interceptors[hook] = mergeHook(interceptors[hook], interceptor[hook]);
501
- }
502
- });
503
- }
504
- function removeInterceptorHook(interceptors, interceptor) {
505
- if (!interceptors || !interceptor) {
506
- return;
507
- }
508
- Object.keys(interceptor).forEach((name) => {
509
- const hooks = interceptors[name];
510
- const hook = interceptor[name];
511
- if (isArray(hooks) && isFunction(hook)) {
512
- remove(hooks, hook);
513
- }
514
- });
515
- }
516
- function mergeHook(parentVal, childVal) {
517
- const res = childVal
518
- ? parentVal
519
- ? parentVal.concat(childVal)
520
- : isArray(childVal)
521
- ? childVal
522
- : [childVal]
523
- : parentVal;
524
- return res ? dedupeHooks(res) : res;
525
- }
526
- function dedupeHooks(hooks) {
527
- const res = [];
528
- for (let i = 0; i < hooks.length; i++) {
529
- if (res.indexOf(hooks[i]) === -1) {
530
- res.push(hooks[i]);
531
- }
532
- }
533
- return res;
534
- }
535
- const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
536
- if (isString(method) && isPlainObject(interceptor)) {
537
- mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
538
- }
539
- else if (isPlainObject(method)) {
540
- mergeInterceptorHook(globalInterceptors, method);
541
- }
542
- }, AddInterceptorProtocol);
543
- const removeInterceptor = defineSyncApi(API_REMOVE_INTERCEPTOR, (method, interceptor) => {
544
- if (isString(method)) {
545
- if (isPlainObject(interceptor)) {
546
- removeInterceptorHook(scopedInterceptors[method], interceptor);
547
- }
548
- else {
549
- delete scopedInterceptors[method];
550
- }
551
- }
552
- else if (isPlainObject(method)) {
553
- removeInterceptorHook(globalInterceptors, method);
554
- }
555
- }, RemoveInterceptorProtocol);
497
+ function mergeInterceptorHook(interceptors, interceptor) {
498
+ Object.keys(interceptor).forEach((hook) => {
499
+ if (isFunction(interceptor[hook])) {
500
+ interceptors[hook] = mergeHook(interceptors[hook], interceptor[hook]);
501
+ }
502
+ });
503
+ }
504
+ function removeInterceptorHook(interceptors, interceptor) {
505
+ if (!interceptors || !interceptor) {
506
+ return;
507
+ }
508
+ Object.keys(interceptor).forEach((name) => {
509
+ const hooks = interceptors[name];
510
+ const hook = interceptor[name];
511
+ if (isArray(hooks) && isFunction(hook)) {
512
+ remove(hooks, hook);
513
+ }
514
+ });
515
+ }
516
+ function mergeHook(parentVal, childVal) {
517
+ const res = childVal
518
+ ? parentVal
519
+ ? parentVal.concat(childVal)
520
+ : isArray(childVal)
521
+ ? childVal
522
+ : [childVal]
523
+ : parentVal;
524
+ return res ? dedupeHooks(res) : res;
525
+ }
526
+ function dedupeHooks(hooks) {
527
+ const res = [];
528
+ for (let i = 0; i < hooks.length; i++) {
529
+ if (res.indexOf(hooks[i]) === -1) {
530
+ res.push(hooks[i]);
531
+ }
532
+ }
533
+ return res;
534
+ }
535
+ const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
536
+ if (isString(method) && isPlainObject(interceptor)) {
537
+ mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
538
+ }
539
+ else if (isPlainObject(method)) {
540
+ mergeInterceptorHook(globalInterceptors, method);
541
+ }
542
+ }, AddInterceptorProtocol);
543
+ const removeInterceptor = defineSyncApi(API_REMOVE_INTERCEPTOR, (method, interceptor) => {
544
+ if (isString(method)) {
545
+ if (isPlainObject(interceptor)) {
546
+ removeInterceptorHook(scopedInterceptors[method], interceptor);
547
+ }
548
+ else {
549
+ delete scopedInterceptors[method];
550
+ }
551
+ }
552
+ else if (isPlainObject(method)) {
553
+ removeInterceptorHook(globalInterceptors, method);
554
+ }
555
+ }, RemoveInterceptorProtocol);
556
556
  const interceptors = {};
557
557
 
558
- const API_ON = '$on';
559
- const OnProtocol = [
560
- {
561
- name: 'event',
562
- type: String,
563
- required: true,
564
- },
565
- {
566
- name: 'callback',
567
- type: Function,
568
- required: true,
569
- },
570
- ];
571
- const API_ONCE = '$once';
572
- const OnceProtocol = OnProtocol;
573
- const API_OFF = '$off';
574
- const OffProtocol = [
575
- {
576
- name: 'event',
577
- type: [String, Array],
578
- },
579
- {
580
- name: 'callback',
581
- type: Function,
582
- },
583
- ];
584
- const API_EMIT = '$emit';
585
- const EmitProtocol = [
586
- {
587
- name: 'event',
588
- type: String,
589
- required: true,
590
- },
558
+ const API_ON = '$on';
559
+ const OnProtocol = [
560
+ {
561
+ name: 'event',
562
+ type: String,
563
+ required: true,
564
+ },
565
+ {
566
+ name: 'callback',
567
+ type: Function,
568
+ required: true,
569
+ },
570
+ ];
571
+ const API_ONCE = '$once';
572
+ const OnceProtocol = OnProtocol;
573
+ const API_OFF = '$off';
574
+ const OffProtocol = [
575
+ {
576
+ name: 'event',
577
+ type: [String, Array],
578
+ },
579
+ {
580
+ name: 'callback',
581
+ type: Function,
582
+ },
583
+ ];
584
+ const API_EMIT = '$emit';
585
+ const EmitProtocol = [
586
+ {
587
+ name: 'event',
588
+ type: String,
589
+ required: true,
590
+ },
591
591
  ];
592
592
 
593
- const emitter = new Emitter();
594
- const $on = defineSyncApi(API_ON, (name, callback) => {
595
- emitter.on(name, callback);
596
- return () => emitter.off(name, callback);
597
- }, OnProtocol);
598
- const $once = defineSyncApi(API_ONCE, (name, callback) => {
599
- emitter.once(name, callback);
600
- return () => emitter.off(name, callback);
601
- }, OnceProtocol);
602
- const $off = defineSyncApi(API_OFF, (name, callback) => {
603
- if (!name) {
604
- emitter.e = {};
605
- return;
606
- }
607
- if (!isArray(name))
608
- name = [name];
609
- name.forEach((n) => emitter.off(n, callback));
610
- }, OffProtocol);
611
- const $emit = defineSyncApi(API_EMIT, (name, ...args) => {
612
- emitter.emit(name, ...args);
593
+ const emitter = new Emitter();
594
+ const $on = defineSyncApi(API_ON, (name, callback) => {
595
+ emitter.on(name, callback);
596
+ return () => emitter.off(name, callback);
597
+ }, OnProtocol);
598
+ const $once = defineSyncApi(API_ONCE, (name, callback) => {
599
+ emitter.once(name, callback);
600
+ return () => emitter.off(name, callback);
601
+ }, OnceProtocol);
602
+ const $off = defineSyncApi(API_OFF, (name, callback) => {
603
+ if (!name) {
604
+ emitter.e = {};
605
+ return;
606
+ }
607
+ if (!isArray(name))
608
+ name = [name];
609
+ name.forEach((n) => emitter.off(n, callback));
610
+ }, OffProtocol);
611
+ const $emit = defineSyncApi(API_EMIT, (name, ...args) => {
612
+ emitter.emit(name, ...args);
613
613
  }, EmitProtocol);
614
614
 
615
- let cid;
616
- let cidErrMsg;
617
- let enabled;
618
- function normalizePushMessage(message) {
619
- try {
620
- return JSON.parse(message);
621
- }
622
- catch (e) { }
623
- return message;
624
- }
625
- /**
626
- * @private
627
- * @param args
628
- */
629
- function invokePushCallback(args) {
630
- if (args.type === 'enabled') {
631
- enabled = true;
632
- }
633
- else if (args.type === 'clientId') {
634
- cid = args.cid;
635
- cidErrMsg = args.errMsg;
636
- invokeGetPushCidCallbacks(cid, args.errMsg);
637
- }
638
- else if (args.type === 'pushMsg') {
639
- const message = {
640
- type: 'receive',
641
- data: normalizePushMessage(args.message),
642
- };
643
- for (let i = 0; i < onPushMessageCallbacks.length; i++) {
644
- const callback = onPushMessageCallbacks[i];
645
- callback(message);
646
- // 该消息已被阻止
647
- if (message.stopped) {
648
- break;
649
- }
650
- }
651
- }
652
- else if (args.type === 'click') {
653
- onPushMessageCallbacks.forEach((callback) => {
654
- callback({
655
- type: 'click',
656
- data: normalizePushMessage(args.message),
657
- });
658
- });
659
- }
660
- }
661
- const getPushCidCallbacks = [];
662
- function invokeGetPushCidCallbacks(cid, errMsg) {
663
- getPushCidCallbacks.forEach((callback) => {
664
- callback(cid, errMsg);
665
- });
666
- getPushCidCallbacks.length = 0;
667
- }
668
- const API_GET_PUSH_CLIENT_ID = 'getPushClientId';
669
- const getPushClientId = defineAsyncApi(API_GET_PUSH_CLIENT_ID, (_, { resolve, reject }) => {
670
- Promise.resolve().then(() => {
671
- if (typeof enabled === 'undefined') {
672
- enabled = false;
673
- cid = '';
674
- cidErrMsg = 'uniPush is not enabled';
675
- }
676
- getPushCidCallbacks.push((cid, errMsg) => {
677
- if (cid) {
678
- resolve({ cid });
679
- }
680
- else {
681
- reject(errMsg);
682
- }
683
- });
684
- if (typeof cid !== 'undefined') {
685
- invokeGetPushCidCallbacks(cid, cidErrMsg);
686
- }
687
- });
688
- });
689
- const onPushMessageCallbacks = [];
690
- // 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
691
- const onPushMessage = (fn) => {
692
- if (onPushMessageCallbacks.indexOf(fn) === -1) {
693
- onPushMessageCallbacks.push(fn);
694
- }
695
- };
696
- const offPushMessage = (fn) => {
697
- if (!fn) {
698
- onPushMessageCallbacks.length = 0;
699
- }
700
- else {
701
- const index = onPushMessageCallbacks.indexOf(fn);
702
- if (index > -1) {
703
- onPushMessageCallbacks.splice(index, 1);
704
- }
705
- }
615
+ let cid;
616
+ let cidErrMsg;
617
+ let enabled;
618
+ function normalizePushMessage(message) {
619
+ try {
620
+ return JSON.parse(message);
621
+ }
622
+ catch (e) { }
623
+ return message;
624
+ }
625
+ /**
626
+ * @private
627
+ * @param args
628
+ */
629
+ function invokePushCallback(args) {
630
+ if (args.type === 'enabled') {
631
+ enabled = true;
632
+ }
633
+ else if (args.type === 'clientId') {
634
+ cid = args.cid;
635
+ cidErrMsg = args.errMsg;
636
+ invokeGetPushCidCallbacks(cid, args.errMsg);
637
+ }
638
+ else if (args.type === 'pushMsg') {
639
+ const message = {
640
+ type: 'receive',
641
+ data: normalizePushMessage(args.message),
642
+ };
643
+ for (let i = 0; i < onPushMessageCallbacks.length; i++) {
644
+ const callback = onPushMessageCallbacks[i];
645
+ callback(message);
646
+ // 该消息已被阻止
647
+ if (message.stopped) {
648
+ break;
649
+ }
650
+ }
651
+ }
652
+ else if (args.type === 'click') {
653
+ onPushMessageCallbacks.forEach((callback) => {
654
+ callback({
655
+ type: 'click',
656
+ data: normalizePushMessage(args.message),
657
+ });
658
+ });
659
+ }
660
+ }
661
+ const getPushCidCallbacks = [];
662
+ function invokeGetPushCidCallbacks(cid, errMsg) {
663
+ getPushCidCallbacks.forEach((callback) => {
664
+ callback(cid, errMsg);
665
+ });
666
+ getPushCidCallbacks.length = 0;
667
+ }
668
+ const API_GET_PUSH_CLIENT_ID = 'getPushClientId';
669
+ const getPushClientId = defineAsyncApi(API_GET_PUSH_CLIENT_ID, (_, { resolve, reject }) => {
670
+ Promise.resolve().then(() => {
671
+ if (typeof enabled === 'undefined') {
672
+ enabled = false;
673
+ cid = '';
674
+ cidErrMsg = 'uniPush is not enabled';
675
+ }
676
+ getPushCidCallbacks.push((cid, errMsg) => {
677
+ if (cid) {
678
+ resolve({ cid });
679
+ }
680
+ else {
681
+ reject(errMsg);
682
+ }
683
+ });
684
+ if (typeof cid !== 'undefined') {
685
+ invokeGetPushCidCallbacks(cid, cidErrMsg);
686
+ }
687
+ });
688
+ });
689
+ const onPushMessageCallbacks = [];
690
+ // 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
691
+ const onPushMessage = (fn) => {
692
+ if (onPushMessageCallbacks.indexOf(fn) === -1) {
693
+ onPushMessageCallbacks.push(fn);
694
+ }
695
+ };
696
+ const offPushMessage = (fn) => {
697
+ if (!fn) {
698
+ onPushMessageCallbacks.length = 0;
699
+ }
700
+ else {
701
+ const index = onPushMessageCallbacks.indexOf(fn);
702
+ if (index > -1) {
703
+ onPushMessageCallbacks.splice(index, 1);
704
+ }
705
+ }
706
706
  };
707
707
 
708
- const SYNC_API_RE = /^\$|getLocale|setLocale|sendNativeEvent|restoreGlobal|requireGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getDeviceInfo|getAppBaseInfo|getWindowInfo|getSystemSetting|getAppAuthorizeSetting/;
709
- const CONTEXT_API_RE = /^create|Manager$/;
710
- // Context例外情况
711
- const CONTEXT_API_RE_EXC = ['createBLEConnection'];
712
- // 同步例外情况
713
- const ASYNC_API = ['createBLEConnection'];
714
- const CALLBACK_API_RE = /^on|^off/;
715
- function isContextApi(name) {
716
- return CONTEXT_API_RE.test(name) && CONTEXT_API_RE_EXC.indexOf(name) === -1;
717
- }
718
- function isSyncApi(name) {
719
- return SYNC_API_RE.test(name) && ASYNC_API.indexOf(name) === -1;
720
- }
721
- function isCallbackApi(name) {
722
- return CALLBACK_API_RE.test(name) && name !== 'onPush';
723
- }
724
- function shouldPromise(name) {
725
- if (isContextApi(name) || isSyncApi(name) || isCallbackApi(name)) {
726
- return false;
727
- }
728
- return true;
729
- }
730
- /* eslint-disable no-extend-native */
731
- if (!Promise.prototype.finally) {
732
- Promise.prototype.finally = function (onfinally) {
733
- const promise = this.constructor;
734
- return this.then((value) => promise.resolve(onfinally && onfinally()).then(() => value), (reason) => promise.resolve(onfinally && onfinally()).then(() => {
735
- throw reason;
736
- }));
737
- };
738
- }
739
- function promisify(name, api) {
740
- if (!shouldPromise(name)) {
741
- return api;
742
- }
743
- if (!isFunction(api)) {
744
- return api;
745
- }
746
- return function promiseApi(options = {}, ...rest) {
747
- if (isFunction(options.success) ||
748
- isFunction(options.fail) ||
749
- isFunction(options.complete)) {
750
- return wrapperReturnValue(name, invokeApi(name, api, options, rest));
751
- }
752
- return wrapperReturnValue(name, handlePromise(new Promise((resolve, reject) => {
753
- invokeApi(name, api, extend({}, options, {
754
- success: resolve,
755
- fail: reject,
756
- }), rest);
757
- })));
758
- };
708
+ const SYNC_API_RE = /^\$|getLocale|setLocale|sendNativeEvent|restoreGlobal|requireGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getDeviceInfo|getAppBaseInfo|getWindowInfo|getSystemSetting|getAppAuthorizeSetting/;
709
+ const CONTEXT_API_RE = /^create|Manager$/;
710
+ // Context例外情况
711
+ const CONTEXT_API_RE_EXC = ['createBLEConnection'];
712
+ // 同步例外情况
713
+ const ASYNC_API = ['createBLEConnection'];
714
+ const CALLBACK_API_RE = /^on|^off/;
715
+ function isContextApi(name) {
716
+ return CONTEXT_API_RE.test(name) && CONTEXT_API_RE_EXC.indexOf(name) === -1;
717
+ }
718
+ function isSyncApi(name) {
719
+ return SYNC_API_RE.test(name) && ASYNC_API.indexOf(name) === -1;
720
+ }
721
+ function isCallbackApi(name) {
722
+ return CALLBACK_API_RE.test(name) && name !== 'onPush';
723
+ }
724
+ function shouldPromise(name) {
725
+ if (isContextApi(name) || isSyncApi(name) || isCallbackApi(name)) {
726
+ return false;
727
+ }
728
+ return true;
729
+ }
730
+ /* eslint-disable no-extend-native */
731
+ if (!Promise.prototype.finally) {
732
+ Promise.prototype.finally = function (onfinally) {
733
+ const promise = this.constructor;
734
+ return this.then((value) => promise.resolve(onfinally && onfinally()).then(() => value), (reason) => promise.resolve(onfinally && onfinally()).then(() => {
735
+ throw reason;
736
+ }));
737
+ };
738
+ }
739
+ function promisify(name, api) {
740
+ if (!shouldPromise(name)) {
741
+ return api;
742
+ }
743
+ if (!isFunction(api)) {
744
+ return api;
745
+ }
746
+ return function promiseApi(options = {}, ...rest) {
747
+ if (isFunction(options.success) ||
748
+ isFunction(options.fail) ||
749
+ isFunction(options.complete)) {
750
+ return wrapperReturnValue(name, invokeApi(name, api, options, rest));
751
+ }
752
+ return wrapperReturnValue(name, handlePromise(new Promise((resolve, reject) => {
753
+ invokeApi(name, api, extend({}, options, {
754
+ success: resolve,
755
+ fail: reject,
756
+ }), rest);
757
+ })));
758
+ };
759
759
  }
760
760
 
761
- const CALLBACKS = ['success', 'fail', 'cancel', 'complete'];
762
- function initWrapper(protocols) {
763
- function processCallback(methodName, method, returnValue) {
764
- return function (res) {
765
- return method(processReturnValue(methodName, res, returnValue));
766
- };
767
- }
768
- function processArgs(methodName, fromArgs, argsOption = {}, returnValue = {}, keepFromArgs = false) {
769
- if (isPlainObject(fromArgs)) {
770
- // 一般 api 的参数解析
771
- const toArgs = (keepFromArgs === true ? fromArgs : {}); // returnValue 为 false 时,说明是格式化返回值,直接在返回值对象上修改赋值
772
- if (isFunction(argsOption)) {
773
- argsOption = argsOption(fromArgs, toArgs) || {};
774
- }
775
- for (const key in fromArgs) {
776
- if (hasOwn(argsOption, key)) {
777
- let keyOption = argsOption[key];
778
- if (isFunction(keyOption)) {
779
- keyOption = keyOption(fromArgs[key], fromArgs, toArgs);
780
- }
781
- if (!keyOption) {
782
- // 不支持的参数
783
- console.warn(`字节跳动小程序 ${methodName} 暂不支持 ${key}`);
784
- }
785
- else if (isString(keyOption)) {
786
- // 重写参数 key
787
- toArgs[keyOption] = fromArgs[key];
788
- }
789
- else if (isPlainObject(keyOption)) {
790
- // {name:newName,value:value}可重新指定参数 key:value
791
- toArgs[keyOption.name ? keyOption.name : key] = keyOption.value;
792
- }
793
- }
794
- else if (CALLBACKS.indexOf(key) !== -1) {
795
- const callback = fromArgs[key];
796
- if (isFunction(callback)) {
797
- toArgs[key] = processCallback(methodName, callback, returnValue);
798
- }
799
- }
800
- else {
801
- if (!keepFromArgs && !hasOwn(toArgs, key)) {
802
- toArgs[key] = fromArgs[key];
803
- }
804
- }
805
- }
806
- return toArgs;
807
- }
808
- else if (isFunction(fromArgs)) {
809
- fromArgs = processCallback(methodName, fromArgs, returnValue);
810
- }
811
- return fromArgs;
812
- }
813
- function processReturnValue(methodName, res, returnValue, keepReturnValue = false) {
814
- if (isFunction(protocols.returnValue)) {
815
- // 处理通用 returnValue
816
- res = protocols.returnValue(methodName, res);
817
- }
818
- return processArgs(methodName, res, returnValue, {}, keepReturnValue);
819
- }
820
- return function wrapper(methodName, method) {
821
- if (!hasOwn(protocols, methodName)) {
822
- return method;
823
- }
824
- const protocol = protocols[methodName];
825
- if (!protocol) {
826
- // 暂不支持的 api
827
- return function () {
828
- console.error(`字节跳动小程序 暂不支持${methodName}`);
829
- };
830
- }
831
- return function (arg1, arg2) {
832
- // 目前 api 最多两个参数
833
- let options = protocol;
834
- if (isFunction(protocol)) {
835
- options = protocol(arg1);
836
- }
837
- arg1 = processArgs(methodName, arg1, options.args, options.returnValue);
838
- const args = [arg1];
839
- if (typeof arg2 !== 'undefined') {
840
- args.push(arg2);
841
- }
842
- const returnValue = tt[options.name || methodName].apply(tt, args);
843
- if (isSyncApi(methodName)) {
844
- // 同步 api
845
- return processReturnValue(methodName, returnValue, options.returnValue, isContextApi(methodName));
846
- }
847
- return returnValue;
848
- };
849
- };
761
+ const CALLBACKS = ['success', 'fail', 'cancel', 'complete'];
762
+ function initWrapper(protocols) {
763
+ function processCallback(methodName, method, returnValue) {
764
+ return function (res) {
765
+ return method(processReturnValue(methodName, res, returnValue));
766
+ };
767
+ }
768
+ function processArgs(methodName, fromArgs, argsOption = {}, returnValue = {}, keepFromArgs = false) {
769
+ if (isPlainObject(fromArgs)) {
770
+ // 一般 api 的参数解析
771
+ const toArgs = (keepFromArgs === true ? fromArgs : {}); // returnValue 为 false 时,说明是格式化返回值,直接在返回值对象上修改赋值
772
+ if (isFunction(argsOption)) {
773
+ argsOption = argsOption(fromArgs, toArgs) || {};
774
+ }
775
+ for (const key in fromArgs) {
776
+ if (hasOwn(argsOption, key)) {
777
+ let keyOption = argsOption[key];
778
+ if (isFunction(keyOption)) {
779
+ keyOption = keyOption(fromArgs[key], fromArgs, toArgs);
780
+ }
781
+ if (!keyOption) {
782
+ // 不支持的参数
783
+ console.warn(`字节跳动小程序 ${methodName} 暂不支持 ${key}`);
784
+ }
785
+ else if (isString(keyOption)) {
786
+ // 重写参数 key
787
+ toArgs[keyOption] = fromArgs[key];
788
+ }
789
+ else if (isPlainObject(keyOption)) {
790
+ // {name:newName,value:value}可重新指定参数 key:value
791
+ toArgs[keyOption.name ? keyOption.name : key] = keyOption.value;
792
+ }
793
+ }
794
+ else if (CALLBACKS.indexOf(key) !== -1) {
795
+ const callback = fromArgs[key];
796
+ if (isFunction(callback)) {
797
+ toArgs[key] = processCallback(methodName, callback, returnValue);
798
+ }
799
+ }
800
+ else {
801
+ if (!keepFromArgs && !hasOwn(toArgs, key)) {
802
+ toArgs[key] = fromArgs[key];
803
+ }
804
+ }
805
+ }
806
+ return toArgs;
807
+ }
808
+ else if (isFunction(fromArgs)) {
809
+ fromArgs = processCallback(methodName, fromArgs, returnValue);
810
+ }
811
+ return fromArgs;
812
+ }
813
+ function processReturnValue(methodName, res, returnValue, keepReturnValue = false) {
814
+ if (isFunction(protocols.returnValue)) {
815
+ // 处理通用 returnValue
816
+ res = protocols.returnValue(methodName, res);
817
+ }
818
+ return processArgs(methodName, res, returnValue, {}, keepReturnValue);
819
+ }
820
+ return function wrapper(methodName, method) {
821
+ if (!hasOwn(protocols, methodName)) {
822
+ return method;
823
+ }
824
+ const protocol = protocols[methodName];
825
+ if (!protocol) {
826
+ // 暂不支持的 api
827
+ return function () {
828
+ console.error(`字节跳动小程序 暂不支持${methodName}`);
829
+ };
830
+ }
831
+ return function (arg1, arg2) {
832
+ // 目前 api 最多两个参数
833
+ let options = protocol;
834
+ if (isFunction(protocol)) {
835
+ options = protocol(arg1);
836
+ }
837
+ arg1 = processArgs(methodName, arg1, options.args, options.returnValue);
838
+ const args = [arg1];
839
+ if (typeof arg2 !== 'undefined') {
840
+ args.push(arg2);
841
+ }
842
+ const returnValue = tt[options.name || methodName].apply(tt, args);
843
+ if (isSyncApi(methodName)) {
844
+ // 同步 api
845
+ return processReturnValue(methodName, returnValue, options.returnValue, isContextApi(methodName));
846
+ }
847
+ return returnValue;
848
+ };
849
+ };
850
850
  }
851
851
 
852
- const getLocale = () => {
853
- // 优先使用 $locale
854
- const app = isFunction(getApp) && getApp({ allowDefault: true });
855
- if (app && app.$vm) {
856
- return app.$vm.$locale;
857
- }
858
- return normalizeLocale(tt.getSystemInfoSync().language) || LOCALE_EN;
859
- };
860
- const setLocale = (locale) => {
861
- const app = isFunction(getApp) && getApp();
862
- if (!app) {
863
- return false;
864
- }
865
- const oldLocale = app.$vm.$locale;
866
- if (oldLocale !== locale) {
867
- app.$vm.$locale = locale;
868
- onLocaleChangeCallbacks.forEach((fn) => fn({ locale }));
869
- return true;
870
- }
871
- return false;
872
- };
873
- const onLocaleChangeCallbacks = [];
874
- const onLocaleChange = (fn) => {
875
- if (onLocaleChangeCallbacks.indexOf(fn) === -1) {
876
- onLocaleChangeCallbacks.push(fn);
877
- }
878
- };
879
- if (typeof global !== 'undefined') {
880
- global.getLocale = getLocale;
852
+ const getLocale = () => {
853
+ // 优先使用 $locale
854
+ const app = isFunction(getApp) && getApp({ allowDefault: true });
855
+ if (app && app.$vm) {
856
+ return app.$vm.$locale;
857
+ }
858
+ return normalizeLocale(tt.getSystemInfoSync().language) || LOCALE_EN;
859
+ };
860
+ const setLocale = (locale) => {
861
+ const app = isFunction(getApp) && getApp();
862
+ if (!app) {
863
+ return false;
864
+ }
865
+ const oldLocale = app.$vm.$locale;
866
+ if (oldLocale !== locale) {
867
+ app.$vm.$locale = locale;
868
+ onLocaleChangeCallbacks.forEach((fn) => fn({ locale }));
869
+ return true;
870
+ }
871
+ return false;
872
+ };
873
+ const onLocaleChangeCallbacks = [];
874
+ const onLocaleChange = (fn) => {
875
+ if (onLocaleChangeCallbacks.indexOf(fn) === -1) {
876
+ onLocaleChangeCallbacks.push(fn);
877
+ }
878
+ };
879
+ if (typeof global !== 'undefined') {
880
+ global.getLocale = getLocale;
881
881
  }
882
882
 
883
- const UUID_KEY = '__DC_STAT_UUID';
884
- let deviceId;
885
- function useDeviceId(global = tt) {
886
- return function addDeviceId(_, toRes) {
887
- deviceId = deviceId || global.getStorageSync(UUID_KEY);
888
- if (!deviceId) {
889
- deviceId = Date.now() + '' + Math.floor(Math.random() * 1e7);
890
- tt.setStorage({
891
- key: UUID_KEY,
892
- data: deviceId,
893
- });
894
- }
895
- toRes.deviceId = deviceId;
896
- };
897
- }
898
- function addSafeAreaInsets(fromRes, toRes) {
899
- if (fromRes.safeArea) {
900
- const safeArea = fromRes.safeArea;
901
- toRes.safeAreaInsets = {
902
- top: safeArea.top,
903
- left: safeArea.left,
904
- right: fromRes.windowWidth - safeArea.right,
905
- bottom: fromRes.screenHeight - safeArea.bottom,
906
- };
907
- }
908
- }
909
- function populateParameters(fromRes, toRes) {
910
- const { brand = '', model = '', system = '', language = '', theme, version, platform, fontSizeSetting, SDKVersion, pixelRatio, deviceOrientation, } = fromRes;
911
- // const isQuickApp = "mp-toutiao".indexOf('quickapp-webview') !== -1
912
- // osName osVersion
913
- let osName = '';
914
- let osVersion = '';
915
- {
916
- osName = system.split(' ')[0] || '';
917
- osVersion = system.split(' ')[1] || '';
918
- }
919
- let hostVersion = version;
920
- // deviceType
921
- let deviceType = getGetDeviceType(fromRes, model);
922
- // deviceModel
923
- let deviceBrand = getDeviceBrand(brand);
924
- // hostName
925
- let _hostName = getHostName(fromRes);
926
- // deviceOrientation
927
- let _deviceOrientation = deviceOrientation; // 仅 微信 百度 支持
928
- // devicePixelRatio
929
- let _devicePixelRatio = pixelRatio;
930
- // SDKVersion
931
- let _SDKVersion = SDKVersion;
932
- // hostLanguage
933
- const hostLanguage = language.replace(/_/g, '-');
934
- // wx.getAccountInfoSync
935
- const parameters = {
936
- appId: process.env.UNI_APP_ID,
937
- appName: process.env.UNI_APP_NAME,
938
- appVersion: process.env.UNI_APP_VERSION_NAME,
939
- appVersionCode: process.env.UNI_APP_VERSION_CODE,
940
- appLanguage: getAppLanguage(hostLanguage),
941
- uniCompileVersion: process.env.UNI_COMPILER_VERSION,
942
- uniRuntimeVersion: process.env.UNI_COMPILER_VERSION,
943
- uniPlatform: process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM,
944
- deviceBrand,
945
- deviceModel: model,
946
- deviceType,
947
- devicePixelRatio: _devicePixelRatio,
948
- deviceOrientation: _deviceOrientation,
949
- osName: osName.toLocaleLowerCase(),
950
- osVersion,
951
- hostTheme: theme,
952
- hostVersion,
953
- hostLanguage,
954
- hostName: _hostName,
955
- hostSDKVersion: _SDKVersion,
956
- hostFontSizeSetting: fontSizeSetting,
957
- windowTop: 0,
958
- windowBottom: 0,
959
- // TODO
960
- osLanguage: undefined,
961
- osTheme: undefined,
962
- ua: undefined,
963
- hostPackageName: undefined,
964
- browserName: undefined,
965
- browserVersion: undefined,
966
- };
967
- extend(toRes, parameters);
968
- }
969
- function getGetDeviceType(fromRes, model) {
970
- // deviceType
971
- let deviceType = fromRes.deviceType || 'phone';
972
- {
973
- const deviceTypeMaps = {
974
- ipad: 'pad',
975
- windows: 'pc',
976
- mac: 'pc',
977
- };
978
- const deviceTypeMapsKeys = Object.keys(deviceTypeMaps);
979
- const _model = model.toLocaleLowerCase();
980
- for (let index = 0; index < deviceTypeMapsKeys.length; index++) {
981
- const _m = deviceTypeMapsKeys[index];
982
- if (_model.indexOf(_m) !== -1) {
983
- deviceType = deviceTypeMaps[_m];
984
- break;
985
- }
986
- }
987
- }
988
- return deviceType;
989
- }
990
- function getDeviceBrand(brand) {
991
- // deviceModel
992
- let deviceBrand = brand;
993
- if (deviceBrand) {
994
- deviceBrand = deviceBrand.toLocaleLowerCase();
995
- }
996
- return deviceBrand;
997
- }
998
- function getAppLanguage(defaultLanguage) {
999
- return getLocale ? getLocale() : defaultLanguage;
1000
- }
1001
- function getHostName(fromRes) {
1002
- const _platform = "mp-toutiao".split('-')[1];
1003
- let _hostName = fromRes.hostName || _platform; // mp-jd
1004
- {
1005
- _hostName = fromRes.appName;
1006
- }
1007
- return _hostName;
883
+ const UUID_KEY = '__DC_STAT_UUID';
884
+ let deviceId;
885
+ function useDeviceId(global = tt) {
886
+ return function addDeviceId(_, toRes) {
887
+ deviceId = deviceId || global.getStorageSync(UUID_KEY);
888
+ if (!deviceId) {
889
+ deviceId = Date.now() + '' + Math.floor(Math.random() * 1e7);
890
+ tt.setStorage({
891
+ key: UUID_KEY,
892
+ data: deviceId,
893
+ });
894
+ }
895
+ toRes.deviceId = deviceId;
896
+ };
897
+ }
898
+ function addSafeAreaInsets(fromRes, toRes) {
899
+ if (fromRes.safeArea) {
900
+ const safeArea = fromRes.safeArea;
901
+ toRes.safeAreaInsets = {
902
+ top: safeArea.top,
903
+ left: safeArea.left,
904
+ right: fromRes.windowWidth - safeArea.right,
905
+ bottom: fromRes.screenHeight - safeArea.bottom,
906
+ };
907
+ }
908
+ }
909
+ function populateParameters(fromRes, toRes) {
910
+ const { brand = '', model = '', system = '', language = '', theme, version, platform, fontSizeSetting, SDKVersion, pixelRatio, deviceOrientation, } = fromRes;
911
+ // const isQuickApp = "mp-toutiao".indexOf('quickapp-webview') !== -1
912
+ // osName osVersion
913
+ let osName = '';
914
+ let osVersion = '';
915
+ {
916
+ osName = system.split(' ')[0] || '';
917
+ osVersion = system.split(' ')[1] || '';
918
+ }
919
+ let hostVersion = version;
920
+ // deviceType
921
+ let deviceType = getGetDeviceType(fromRes, model);
922
+ // deviceModel
923
+ let deviceBrand = getDeviceBrand(brand);
924
+ // hostName
925
+ let _hostName = getHostName(fromRes);
926
+ // deviceOrientation
927
+ let _deviceOrientation = deviceOrientation; // 仅 微信 百度 支持
928
+ // devicePixelRatio
929
+ let _devicePixelRatio = pixelRatio;
930
+ // SDKVersion
931
+ let _SDKVersion = SDKVersion;
932
+ // hostLanguage
933
+ const hostLanguage = language.replace(/_/g, '-');
934
+ // wx.getAccountInfoSync
935
+ const parameters = {
936
+ appId: process.env.UNI_APP_ID,
937
+ appName: process.env.UNI_APP_NAME,
938
+ appVersion: process.env.UNI_APP_VERSION_NAME,
939
+ appVersionCode: process.env.UNI_APP_VERSION_CODE,
940
+ appLanguage: getAppLanguage(hostLanguage),
941
+ uniCompileVersion: process.env.UNI_COMPILER_VERSION,
942
+ uniRuntimeVersion: process.env.UNI_COMPILER_VERSION,
943
+ uniPlatform: process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM,
944
+ deviceBrand,
945
+ deviceModel: model,
946
+ deviceType,
947
+ devicePixelRatio: _devicePixelRatio,
948
+ deviceOrientation: _deviceOrientation,
949
+ osName: osName.toLocaleLowerCase(),
950
+ osVersion,
951
+ hostTheme: theme,
952
+ hostVersion,
953
+ hostLanguage,
954
+ hostName: _hostName,
955
+ hostSDKVersion: _SDKVersion,
956
+ hostFontSizeSetting: fontSizeSetting,
957
+ windowTop: 0,
958
+ windowBottom: 0,
959
+ // TODO
960
+ osLanguage: undefined,
961
+ osTheme: undefined,
962
+ ua: undefined,
963
+ hostPackageName: undefined,
964
+ browserName: undefined,
965
+ browserVersion: undefined,
966
+ };
967
+ extend(toRes, parameters);
968
+ }
969
+ function getGetDeviceType(fromRes, model) {
970
+ // deviceType
971
+ let deviceType = fromRes.deviceType || 'phone';
972
+ {
973
+ const deviceTypeMaps = {
974
+ ipad: 'pad',
975
+ windows: 'pc',
976
+ mac: 'pc',
977
+ };
978
+ const deviceTypeMapsKeys = Object.keys(deviceTypeMaps);
979
+ const _model = model.toLocaleLowerCase();
980
+ for (let index = 0; index < deviceTypeMapsKeys.length; index++) {
981
+ const _m = deviceTypeMapsKeys[index];
982
+ if (_model.indexOf(_m) !== -1) {
983
+ deviceType = deviceTypeMaps[_m];
984
+ break;
985
+ }
986
+ }
987
+ }
988
+ return deviceType;
989
+ }
990
+ function getDeviceBrand(brand) {
991
+ // deviceModel
992
+ let deviceBrand = brand;
993
+ if (deviceBrand) {
994
+ deviceBrand = deviceBrand.toLocaleLowerCase();
995
+ }
996
+ return deviceBrand;
997
+ }
998
+ function getAppLanguage(defaultLanguage) {
999
+ return getLocale ? getLocale() : defaultLanguage;
1000
+ }
1001
+ function getHostName(fromRes) {
1002
+ const _platform = "mp-toutiao".split('-')[1];
1003
+ let _hostName = fromRes.hostName || _platform; // mp-jd
1004
+ {
1005
+ _hostName = fromRes.appName;
1006
+ }
1007
+ return _hostName;
1008
1008
  }
1009
1009
 
1010
- const getSystemInfo = {
1011
- returnValue: (fromRes, toRes) => {
1012
- addSafeAreaInsets(fromRes, toRes);
1013
- useDeviceId()(fromRes, toRes);
1014
- populateParameters(fromRes, toRes);
1015
- },
1010
+ const getSystemInfo = {
1011
+ returnValue: (fromRes, toRes) => {
1012
+ addSafeAreaInsets(fromRes, toRes);
1013
+ useDeviceId()(fromRes, toRes);
1014
+ populateParameters(fromRes, toRes);
1015
+ },
1016
1016
  };
1017
1017
 
1018
1018
  const getSystemInfoSync = getSystemInfo;
1019
1019
 
1020
1020
  const redirectTo = {};
1021
1021
 
1022
- const previewImage = {
1023
- args(fromArgs, toArgs) {
1024
- let currentIndex = parseInt(fromArgs.current);
1025
- if (isNaN(currentIndex)) {
1026
- return;
1027
- }
1028
- const urls = fromArgs.urls;
1029
- if (!isArray(urls)) {
1030
- return;
1031
- }
1032
- const len = urls.length;
1033
- if (!len) {
1034
- return;
1035
- }
1036
- if (currentIndex < 0) {
1037
- currentIndex = 0;
1038
- }
1039
- else if (currentIndex >= len) {
1040
- currentIndex = len - 1;
1041
- }
1042
- if (currentIndex > 0) {
1043
- toArgs.current = urls[currentIndex];
1044
- toArgs.urls = urls.filter((item, index) => index < currentIndex ? item !== urls[currentIndex] : true);
1045
- }
1046
- else {
1047
- toArgs.current = urls[0];
1048
- }
1049
- return {
1050
- indicator: false,
1051
- loop: false,
1052
- };
1053
- },
1022
+ const previewImage = {
1023
+ args(fromArgs, toArgs) {
1024
+ let currentIndex = parseInt(fromArgs.current);
1025
+ if (isNaN(currentIndex)) {
1026
+ return;
1027
+ }
1028
+ const urls = fromArgs.urls;
1029
+ if (!isArray(urls)) {
1030
+ return;
1031
+ }
1032
+ const len = urls.length;
1033
+ if (!len) {
1034
+ return;
1035
+ }
1036
+ if (currentIndex < 0) {
1037
+ currentIndex = 0;
1038
+ }
1039
+ else if (currentIndex >= len) {
1040
+ currentIndex = len - 1;
1041
+ }
1042
+ if (currentIndex > 0) {
1043
+ toArgs.current = urls[currentIndex];
1044
+ toArgs.urls = urls.filter((item, index) => index < currentIndex ? item !== urls[currentIndex] : true);
1045
+ }
1046
+ else {
1047
+ toArgs.current = urls[0];
1048
+ }
1049
+ return {
1050
+ indicator: false,
1051
+ loop: false,
1052
+ };
1053
+ },
1054
1054
  };
1055
1055
 
1056
- const eventChannels = {};
1057
- const eventChannelStack = [];
1058
- let id = 0;
1059
- function initEventChannel(events, cache = true) {
1060
- id++;
1061
- const eventChannel = new tt.EventChannel(id, events);
1062
- if (cache) {
1063
- eventChannels[id] = eventChannel;
1064
- eventChannelStack.push(eventChannel);
1065
- }
1066
- return eventChannel;
1067
- }
1068
- function getEventChannel(id) {
1069
- if (id) {
1070
- const eventChannel = eventChannels[id];
1071
- delete eventChannels[id];
1072
- return eventChannel;
1073
- }
1074
- return eventChannelStack.shift();
1075
- }
1076
- const navigateTo = {
1077
- args(fromArgs) {
1078
- const id = initEventChannel(fromArgs.events).id;
1079
- if (fromArgs.url) {
1080
- fromArgs.url =
1081
- fromArgs.url +
1082
- (fromArgs.url.indexOf('?') === -1 ? '?' : '&') +
1083
- '__id__=' +
1084
- id;
1085
- }
1086
- },
1087
- returnValue(fromRes) {
1088
- fromRes.eventChannel = getEventChannel();
1089
- },
1056
+ const eventChannels = {};
1057
+ const eventChannelStack = [];
1058
+ let id = 0;
1059
+ function initEventChannel(events, cache = true) {
1060
+ id++;
1061
+ const eventChannel = new tt.EventChannel(id, events);
1062
+ if (cache) {
1063
+ eventChannels[id] = eventChannel;
1064
+ eventChannelStack.push(eventChannel);
1065
+ }
1066
+ return eventChannel;
1067
+ }
1068
+ function getEventChannel(id) {
1069
+ if (id) {
1070
+ const eventChannel = eventChannels[id];
1071
+ delete eventChannels[id];
1072
+ return eventChannel;
1073
+ }
1074
+ return eventChannelStack.shift();
1075
+ }
1076
+ const navigateTo = {
1077
+ args(fromArgs) {
1078
+ const id = initEventChannel(fromArgs.events).id;
1079
+ if (fromArgs.url) {
1080
+ fromArgs.url =
1081
+ fromArgs.url +
1082
+ (fromArgs.url.indexOf('?') === -1 ? '?' : '&') +
1083
+ '__id__=' +
1084
+ id;
1085
+ }
1086
+ },
1087
+ returnValue(fromRes) {
1088
+ fromRes.eventChannel = getEventChannel();
1089
+ },
1090
1090
  };
1091
1091
 
1092
- const baseApis = {
1093
- $on,
1094
- $off,
1095
- $once,
1096
- $emit,
1097
- upx2px,
1098
- interceptors,
1099
- addInterceptor,
1100
- removeInterceptor,
1101
- onCreateVueApp,
1102
- invokeCreateVueAppHook,
1103
- getLocale,
1104
- setLocale,
1105
- onLocaleChange,
1106
- getPushClientId,
1107
- onPushMessage,
1108
- offPushMessage,
1109
- invokePushCallback,
1110
- };
1111
- function initUni(api, protocols, platform = tt) {
1112
- const wrapper = initWrapper(protocols);
1113
- const UniProxyHandlers = {
1114
- get(target, key) {
1115
- if (hasOwn(target, key)) {
1116
- return target[key];
1117
- }
1118
- if (hasOwn(api, key)) {
1119
- return promisify(key, api[key]);
1120
- }
1121
- if (hasOwn(baseApis, key)) {
1122
- return promisify(key, baseApis[key]);
1123
- }
1124
- // event-api
1125
- // provider-api?
1126
- return promisify(key, wrapper(key, platform[key]));
1127
- },
1128
- };
1129
- // 处理 api mp 打包后为不同js,getEventChannel 无法共享问题
1130
- {
1131
- platform.getEventChannel = getEventChannel;
1132
- }
1133
- return new Proxy({}, UniProxyHandlers);
1092
+ const baseApis = {
1093
+ $on,
1094
+ $off,
1095
+ $once,
1096
+ $emit,
1097
+ upx2px,
1098
+ interceptors,
1099
+ addInterceptor,
1100
+ removeInterceptor,
1101
+ onCreateVueApp,
1102
+ invokeCreateVueAppHook,
1103
+ getLocale,
1104
+ setLocale,
1105
+ onLocaleChange,
1106
+ getPushClientId,
1107
+ onPushMessage,
1108
+ offPushMessage,
1109
+ invokePushCallback,
1110
+ };
1111
+ function initUni(api, protocols, platform = tt) {
1112
+ const wrapper = initWrapper(protocols);
1113
+ const UniProxyHandlers = {
1114
+ get(target, key) {
1115
+ if (hasOwn(target, key)) {
1116
+ return target[key];
1117
+ }
1118
+ if (hasOwn(api, key)) {
1119
+ return promisify(key, api[key]);
1120
+ }
1121
+ if (hasOwn(baseApis, key)) {
1122
+ return promisify(key, baseApis[key]);
1123
+ }
1124
+ // event-api
1125
+ // provider-api?
1126
+ return promisify(key, wrapper(key, platform[key]));
1127
+ },
1128
+ };
1129
+ // 处理 api mp 打包后为不同js,getEventChannel 无法共享问题
1130
+ {
1131
+ platform.getEventChannel = getEventChannel;
1132
+ }
1133
+ return new Proxy({}, UniProxyHandlers);
1134
1134
  }
1135
1135
 
1136
- function initGetProvider(providers) {
1137
- return function getProvider({ service, success, fail, complete, }) {
1138
- let res;
1139
- if (providers[service]) {
1140
- res = {
1141
- errMsg: 'getProvider:ok',
1142
- service,
1143
- provider: providers[service],
1144
- };
1145
- isFunction(success) && success(res);
1146
- }
1147
- else {
1148
- res = {
1149
- errMsg: 'getProvider:fail:服务[' + service + ']不存在',
1150
- };
1151
- isFunction(fail) && fail(res);
1152
- }
1153
- isFunction(complete) && complete(res);
1154
- };
1136
+ function initGetProvider(providers) {
1137
+ return function getProvider({ service, success, fail, complete, }) {
1138
+ let res;
1139
+ if (providers[service]) {
1140
+ res = {
1141
+ errMsg: 'getProvider:ok',
1142
+ service,
1143
+ provider: providers[service],
1144
+ };
1145
+ isFunction(success) && success(res);
1146
+ }
1147
+ else {
1148
+ res = {
1149
+ errMsg: 'getProvider:fail:服务[' + service + ']不存在',
1150
+ };
1151
+ isFunction(fail) && fail(res);
1152
+ }
1153
+ isFunction(complete) && complete(res);
1154
+ };
1155
1155
  }
1156
1156
 
1157
- const getProvider = initGetProvider({
1158
- oauth: ['toutiao'],
1159
- share: ['toutiao'],
1160
- payment: ['toutiao'],
1161
- push: ['toutiao'],
1157
+ const getProvider = initGetProvider({
1158
+ oauth: ['toutiao'],
1159
+ share: ['toutiao'],
1160
+ payment: ['toutiao'],
1161
+ push: ['toutiao'],
1162
1162
  });
1163
1163
 
1164
1164
  var shims = /*#__PURE__*/Object.freeze({
@@ -1166,65 +1166,65 @@ var shims = /*#__PURE__*/Object.freeze({
1166
1166
  getProvider: getProvider
1167
1167
  });
1168
1168
 
1169
- const connectSocket = {
1170
- args: {
1171
- method: false,
1172
- },
1173
- };
1174
- const chooseVideo = {
1175
- args: {
1176
- camera: false,
1177
- },
1178
- };
1179
- const scanCode = {
1180
- args: {
1181
- onlyFromCamera: false,
1182
- scanType: false,
1183
- },
1184
- };
1185
- const startAccelerometer = {
1186
- args: {
1187
- interval: false,
1188
- },
1189
- };
1190
- const showToast = {
1191
- args: {
1192
- image: false,
1193
- mask: false,
1194
- },
1195
- };
1196
- const showLoading = {
1197
- args: {
1198
- mask: false,
1199
- },
1200
- };
1201
- const showActionSheet = {
1202
- args: {
1203
- itemColor: false,
1204
- },
1205
- };
1206
- const login = {
1207
- args: {
1208
- scopes: false,
1209
- timeout: false,
1210
- },
1211
- };
1212
- const getUserInfo = {
1213
- args: {
1214
- lang: false,
1215
- timeout: false,
1216
- },
1217
- };
1218
- const requestPayment = {
1219
- name: tt.pay ? 'pay' : 'requestPayment',
1220
- args: {
1221
- orderInfo: tt.pay ? 'orderInfo' : 'data',
1222
- },
1223
- };
1224
- const getFileInfo = {
1225
- args: {
1226
- digestAlgorithm: false,
1227
- },
1169
+ const connectSocket = {
1170
+ args: {
1171
+ method: false,
1172
+ },
1173
+ };
1174
+ const chooseVideo = {
1175
+ args: {
1176
+ camera: false,
1177
+ },
1178
+ };
1179
+ const scanCode = {
1180
+ args: {
1181
+ onlyFromCamera: false,
1182
+ scanType: false,
1183
+ },
1184
+ };
1185
+ const startAccelerometer = {
1186
+ args: {
1187
+ interval: false,
1188
+ },
1189
+ };
1190
+ const showToast = {
1191
+ args: {
1192
+ image: false,
1193
+ mask: false,
1194
+ },
1195
+ };
1196
+ const showLoading = {
1197
+ args: {
1198
+ mask: false,
1199
+ },
1200
+ };
1201
+ const showActionSheet = {
1202
+ args: {
1203
+ itemColor: false,
1204
+ },
1205
+ };
1206
+ const login = {
1207
+ args: {
1208
+ scopes: false,
1209
+ timeout: false,
1210
+ },
1211
+ };
1212
+ const getUserInfo = {
1213
+ args: {
1214
+ lang: false,
1215
+ timeout: false,
1216
+ },
1217
+ };
1218
+ const requestPayment = {
1219
+ name: tt.pay ? 'pay' : 'requestPayment',
1220
+ args: {
1221
+ orderInfo: tt.pay ? 'orderInfo' : 'data',
1222
+ },
1223
+ };
1224
+ const getFileInfo = {
1225
+ args: {
1226
+ digestAlgorithm: false,
1227
+ },
1228
1228
  };
1229
1229
 
1230
1230
  var protocols = /*#__PURE__*/Object.freeze({