@dcloudio/uni-mp-toutiao 3.0.0-alpha-4030320241109001 → 3.0.0-alpha-4030320241117001

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.
@@ -0,0 +1,1780 @@
1
+ import { SLOT_DEFAULT_NAME, EventChannel, invokeArrayFns, MINI_PROGRAM_PAGE_RUNTIME_HOOKS, ON_LOAD, ON_SHOW, ON_HIDE, ON_UNLOAD, ON_RESIZE, ON_TAB_ITEM_TAP, ON_REACH_BOTTOM, ON_PULL_DOWN_REFRESH, ON_ADD_TO_FAVORITES, isUniLifecycleHook, ON_READY, once, ON_LAUNCH, ON_ERROR, ON_THEME_CHANGE, ON_PAGE_NOT_FOUND, ON_UNHANDLE_REJECTION, addLeadingSlash, stringifyQuery, customizeEvent } from '@dcloudio/uni-shared';
2
+ import { hasOwn, isArray, isString, isFunction, extend, isPlainObject as isPlainObject$1, isObject } from '@vue/shared';
3
+ import { nextTick, onUpdated, pruneUniElements, onUnmounted, destroyUniElements, ref, findComponentPropsData, toRaw, updateProps, hasQueueJob, invalidateJob, registerCustomElement, devtoolsComponentAdded, getExposeProxy, pruneComponentPropsCache } from 'vue';
4
+ import { normalizeLocale, LOCALE_EN } from '@dcloudio/uni-i18n';
5
+
6
+ function arrayPop(array) {
7
+ if (array.length === 0) {
8
+ return null;
9
+ }
10
+ return array.pop();
11
+ }
12
+ function arrayShift(array) {
13
+ if (array.length === 0) {
14
+ return null;
15
+ }
16
+ return array.shift();
17
+ }
18
+ function arrayFind(array, predicate) {
19
+ const index = array.findIndex(predicate);
20
+ if (index < 0) {
21
+ return null;
22
+ }
23
+ return array[index];
24
+ }
25
+ function arrayFindLast(array, predicate) {
26
+ const index = array.findLastIndex(predicate);
27
+ if (index < 0) {
28
+ return null;
29
+ }
30
+ return array[index];
31
+ }
32
+ function arrayAt(array, index) {
33
+ if (index < -array.length || index >= array.length) {
34
+ return null;
35
+ }
36
+ return array.at(index);
37
+ }
38
+
39
+ /**
40
+ * copy from @uts/shared
41
+ */
42
+ var IDENTIFIER;
43
+ (function (IDENTIFIER) {
44
+ IDENTIFIER["UTSJSONObject"] = "UTSJSONObject";
45
+ IDENTIFIER["JSON"] = "JSON";
46
+ IDENTIFIER["UTS"] = "UTS";
47
+ IDENTIFIER["DEFINE_COMPONENT"] = "defineComponent";
48
+ IDENTIFIER["VUE"] = "vue";
49
+ IDENTIFIER["GLOBAL_THIS"] = "globalThis";
50
+ IDENTIFIER["UTS_TYPE"] = "UTSType";
51
+ IDENTIFIER["UTS_METADATA"] = "$UTSMetadata$";
52
+ IDENTIFIER["TEMP_UTS_METADATA"] = "$TempUTSMetadata$";
53
+ IDENTIFIER["JSON_FIELD"] = "JSON_FIELD";
54
+ })(IDENTIFIER || (IDENTIFIER = {}));
55
+ var UTS_CLASS_METADATA_KIND;
56
+ (function (UTS_CLASS_METADATA_KIND) {
57
+ UTS_CLASS_METADATA_KIND[UTS_CLASS_METADATA_KIND["CLASS"] = 0] = "CLASS";
58
+ UTS_CLASS_METADATA_KIND[UTS_CLASS_METADATA_KIND["INTERFACE"] = 1] = "INTERFACE";
59
+ UTS_CLASS_METADATA_KIND[UTS_CLASS_METADATA_KIND["TYPE"] = 2] = "TYPE";
60
+ })(UTS_CLASS_METADATA_KIND || (UTS_CLASS_METADATA_KIND = {}));
61
+
62
+ function getType(val) {
63
+ return Object.prototype.toString.call(val).slice(8, -1).toLowerCase();
64
+ }
65
+ function isPlainObject(val) {
66
+ if (val == null || typeof val !== 'object') {
67
+ return false;
68
+ }
69
+ const proto = Object.getPrototypeOf(val);
70
+ return proto === Object.prototype || proto === null;
71
+ }
72
+
73
+ // TODO 实现UTSError
74
+ class UTSError extends Error {
75
+ constructor(message) {
76
+ super(message);
77
+ }
78
+ }
79
+
80
+ function isUTSMetadata(metadata) {
81
+ return !!(metadata &&
82
+ metadata.kind in UTS_CLASS_METADATA_KIND &&
83
+ metadata.interfaces);
84
+ }
85
+ function isNativeType(proto) {
86
+ return !proto || proto === Object.prototype;
87
+ }
88
+ const utsMetadataKey = IDENTIFIER.UTS_METADATA;
89
+ /**
90
+ * 处理复杂的继承关系。
91
+ * 例如:
92
+ * class A extends abstract class B,abstract class B implements interface C
93
+ * new A() instanceof C -> true
94
+ */
95
+ function getParentTypeList(type) {
96
+ const metadata = utsMetadataKey in type ? type[utsMetadataKey] : {};
97
+ let interfaces = [];
98
+ if (!isUTSMetadata(metadata)) {
99
+ interfaces = [];
100
+ }
101
+ else {
102
+ interfaces = metadata.interfaces || [];
103
+ }
104
+ const proto = Object.getPrototypeOf(type);
105
+ if (!isNativeType(proto)) {
106
+ interfaces.push(proto.constructor);
107
+ }
108
+ return interfaces;
109
+ }
110
+ function isImplementationOf(leftType, rightType, visited = []) {
111
+ if (isNativeType(leftType)) {
112
+ return false;
113
+ }
114
+ if (leftType === rightType) {
115
+ return true;
116
+ }
117
+ visited.push(leftType);
118
+ const parentTypeList = getParentTypeList(leftType);
119
+ return parentTypeList.some((parentType) => {
120
+ if (visited.includes(parentType)) {
121
+ return false;
122
+ }
123
+ return isImplementationOf(parentType, rightType, visited);
124
+ });
125
+ }
126
+ function isInstanceOf(value, type) {
127
+ const isNativeInstanceofType = value instanceof type;
128
+ if (isNativeInstanceofType || typeof value !== 'object') {
129
+ return isNativeInstanceofType;
130
+ }
131
+ const proto = Object.getPrototypeOf(value).constructor;
132
+ return isImplementationOf(proto, type);
133
+ }
134
+ function isBaseType(type) {
135
+ return type === Number || type === String || type === Boolean;
136
+ }
137
+ function isUnknownType(type) {
138
+ return type === 'Unknown';
139
+ }
140
+ function isAnyType(type) {
141
+ return type === 'Any';
142
+ }
143
+ function isUTSType(type) {
144
+ return type && type.prototype && type.prototype instanceof UTSType;
145
+ }
146
+ function normalizeGenericValue(value, genericType, isJSONParse = false) {
147
+ return value == null
148
+ ? null
149
+ : isBaseType(genericType) ||
150
+ isUnknownType(genericType) ||
151
+ isAnyType(genericType)
152
+ ? value
153
+ : genericType === Array
154
+ ? new Array(...value)
155
+ : new genericType(value, undefined, isJSONParse);
156
+ }
157
+ class UTSType {
158
+ static get$UTSMetadata$(...args) {
159
+ return {
160
+ kind: UTS_CLASS_METADATA_KIND.TYPE,
161
+ interfaces: [],
162
+ fields: {},
163
+ };
164
+ }
165
+ get $UTSMetadata$() {
166
+ return UTSType.get$UTSMetadata$();
167
+ }
168
+ // TODO 缓存withGenerics结果
169
+ static withGenerics(parent, generics, isJSONParse = false) {
170
+ // 仅JSON.parse uni.request内报错,其他地方不报错
171
+ // generic类型为UTSType子类或Array或基础类型,否则报错
172
+ if (isJSONParse) {
173
+ const illegalGeneric = generics.find((item) => !(item === Array ||
174
+ isBaseType(item) ||
175
+ isUnknownType(item) ||
176
+ isAnyType(item) ||
177
+ item === UTSJSONObject ||
178
+ (item.prototype && item.prototype instanceof UTSType)));
179
+ if (illegalGeneric) {
180
+ throw new Error('Generic is not UTSType or Array or UTSJSONObject or base type, generic: ' +
181
+ illegalGeneric);
182
+ }
183
+ }
184
+ if (parent === Array) {
185
+ // 不带泛型的Array有一部分不会进入这里,需要在构造type时处理
186
+ return class UTSArray extends UTSType {
187
+ constructor(options, isJSONParse = false) {
188
+ if (!Array.isArray(options)) {
189
+ throw new UTSError(`Failed to contruct type, ${options} is not an array`);
190
+ }
191
+ super();
192
+ // @ts-ignore
193
+ return options.map((item) => {
194
+ return normalizeGenericValue(item, generics[0], isJSONParse);
195
+ });
196
+ }
197
+ };
198
+ }
199
+ else if (parent === Map || parent === WeakMap) {
200
+ return class UTSMap extends UTSType {
201
+ constructor(options, isJSONParse = false) {
202
+ if (options == null || typeof options !== 'object') {
203
+ throw new UTSError(`Failed to contruct type, ${options} is not an object`);
204
+ }
205
+ super();
206
+ const obj = new parent();
207
+ for (const key in options) {
208
+ obj.set(normalizeGenericValue(key, generics[0], isJSONParse), normalizeGenericValue(options[key], generics[1], isJSONParse));
209
+ }
210
+ return obj;
211
+ }
212
+ };
213
+ }
214
+ else if (isUTSType(parent)) {
215
+ return class VirtualClassWithGenerics extends parent {
216
+ static get$UTSMetadata$() {
217
+ return parent.get$UTSMetadata$(...generics);
218
+ }
219
+ constructor(options, metadata = VirtualClassWithGenerics.get$UTSMetadata$(), isJSONParse = false) {
220
+ // @ts-ignore
221
+ super(options, metadata, isJSONParse);
222
+ }
223
+ };
224
+ }
225
+ else {
226
+ return parent;
227
+ }
228
+ }
229
+ constructor() { }
230
+ static initProps(options, metadata, isJSONParse = false) {
231
+ const obj = {};
232
+ if (!metadata.fields) {
233
+ return obj;
234
+ }
235
+ for (const key in metadata.fields) {
236
+ const { type, optional, jsonField } = metadata.fields[key];
237
+ const realKey = isJSONParse ? jsonField || key : key;
238
+ if (options[realKey] == null) {
239
+ if (optional) {
240
+ obj[key] = null;
241
+ continue;
242
+ }
243
+ else {
244
+ throw new UTSError(`Failed to contruct type, missing required property: ${key}`);
245
+ }
246
+ }
247
+ if (isUTSType(type)) {
248
+ // 带有泛型的数组会走此分支
249
+ // @ts-ignore
250
+ obj[key] = new type(options[realKey], undefined, isJSONParse);
251
+ }
252
+ else if (type === Array) {
253
+ // 不带泛型的数组会走此分支
254
+ if (!Array.isArray(options[realKey])) {
255
+ throw new UTSError(`Failed to contruct type, property ${key} is not an array`);
256
+ }
257
+ obj[key] = options[realKey].map((item) => {
258
+ return item == null ? null : item;
259
+ });
260
+ }
261
+ else {
262
+ obj[key] = options[realKey];
263
+ }
264
+ }
265
+ return obj;
266
+ }
267
+ }
268
+
269
+ const OriginalJSON = JSON;
270
+ function createUTSJSONObject(obj) {
271
+ const result = new UTSJSONObject({});
272
+ for (const key in obj) {
273
+ const value = obj[key];
274
+ if (isPlainObject(value)) {
275
+ result[key] = createUTSJSONObject(value);
276
+ }
277
+ else if (getType(value) === 'array') {
278
+ result[key] = value.map((item) => {
279
+ if (isPlainObject(item)) {
280
+ return createUTSJSONObject(item);
281
+ }
282
+ else {
283
+ return item;
284
+ }
285
+ });
286
+ }
287
+ else {
288
+ result[key] = value;
289
+ }
290
+ }
291
+ return result;
292
+ }
293
+ function parseObjectOrArray(object, utsType) {
294
+ const objectType = getType(object);
295
+ if (object === null || (objectType !== 'object' && objectType !== 'array')) {
296
+ return object;
297
+ }
298
+ if (utsType && utsType !== UTSJSONObject) {
299
+ try {
300
+ return new utsType(object, undefined, true);
301
+ }
302
+ catch (error) {
303
+ console.error(error);
304
+ return null;
305
+ }
306
+ }
307
+ if (objectType === 'array') {
308
+ return object.map((value) => {
309
+ return parseObjectOrArray(value);
310
+ });
311
+ }
312
+ else if (objectType === 'object') {
313
+ return createUTSJSONObject(object);
314
+ }
315
+ return object;
316
+ }
317
+ const UTSJSON = {
318
+ parse: (text, reviver, utsType) => {
319
+ // @ts-ignore
320
+ if (reviver && (isUTSType(reviver) || reviver === UTSJSONObject)) {
321
+ utsType = reviver;
322
+ reviver = undefined;
323
+ }
324
+ try {
325
+ const parseResult = OriginalJSON.parse(text, reviver);
326
+ return parseObjectOrArray(parseResult, utsType);
327
+ }
328
+ catch (error) {
329
+ console.error(error);
330
+ return null;
331
+ }
332
+ },
333
+ parseArray(text, utsType) {
334
+ try {
335
+ const parseResult = OriginalJSON.parse(text);
336
+ if (Array.isArray(parseResult)) {
337
+ return parseObjectOrArray(parseResult, utsType ? UTSType.withGenerics(Array, [utsType], true) : undefined);
338
+ }
339
+ return null;
340
+ }
341
+ catch (error) {
342
+ console.error(error);
343
+ return null;
344
+ }
345
+ },
346
+ parseObject(text, utsType) {
347
+ try {
348
+ const parseResult = OriginalJSON.parse(text);
349
+ if (Array.isArray(parseResult)) {
350
+ return null;
351
+ }
352
+ return parseObjectOrArray(parseResult, utsType);
353
+ }
354
+ catch (error) {
355
+ console.error(error);
356
+ return null;
357
+ }
358
+ },
359
+ stringify: (value) => {
360
+ return OriginalJSON.stringify(value);
361
+ },
362
+ };
363
+
364
+ function mapGet(map, key) {
365
+ if (!map.has(key)) {
366
+ return null;
367
+ }
368
+ return map.get(key);
369
+ }
370
+
371
+ function stringCodePointAt(str, pos) {
372
+ if (pos < 0 || pos >= str.length) {
373
+ return null;
374
+ }
375
+ return str.codePointAt(pos);
376
+ }
377
+ function stringAt(str, pos) {
378
+ if (pos < -str.length || pos >= str.length) {
379
+ return null;
380
+ }
381
+ return str.at(pos);
382
+ }
383
+
384
+ function weakMapGet(map, key) {
385
+ if (!map.has(key)) {
386
+ return null;
387
+ }
388
+ return map.get(key);
389
+ }
390
+
391
+ const UTS = {
392
+ arrayAt,
393
+ arrayFind,
394
+ arrayFindLast,
395
+ arrayPop,
396
+ arrayShift,
397
+ isInstanceOf,
398
+ UTSType,
399
+ mapGet,
400
+ stringAt,
401
+ stringCodePointAt,
402
+ weakMapGet,
403
+ JSON: UTSJSON,
404
+ };
405
+
406
+ class UniError extends Error {
407
+ constructor(errSubject, errCode, errMsg) {
408
+ let options = {};
409
+ const argsLength = Array.from(arguments).length;
410
+ switch (argsLength) {
411
+ case 0:
412
+ errSubject = '';
413
+ errMsg = '';
414
+ errCode = 0;
415
+ break;
416
+ case 1:
417
+ errMsg = errSubject;
418
+ errSubject = '';
419
+ errCode = 0;
420
+ break;
421
+ case 2:
422
+ errMsg = errSubject;
423
+ options = errCode;
424
+ errCode = options.errCode || 0;
425
+ errSubject = options.errSubject || '';
426
+ break;
427
+ }
428
+ super(errMsg);
429
+ this.name = 'UniError';
430
+ this.errSubject = errSubject;
431
+ this.errCode = errCode;
432
+ this.errMsg = errMsg;
433
+ if (options.data) {
434
+ this.data = options.data;
435
+ }
436
+ if (options.cause) {
437
+ this.cause = options.cause;
438
+ }
439
+ }
440
+ set errMsg(msg) {
441
+ this.message = msg;
442
+ }
443
+ get errMsg() {
444
+ return this.message;
445
+ }
446
+ toString() {
447
+ return this.errMsg;
448
+ }
449
+ toJSON() {
450
+ return {
451
+ errSubject: this.errSubject,
452
+ errCode: this.errCode,
453
+ errMsg: this.errMsg,
454
+ data: this.data,
455
+ cause: this.cause && typeof this.cause.toJSON === 'function'
456
+ ? this.cause.toJSON()
457
+ : this.cause,
458
+ };
459
+ }
460
+ }
461
+
462
+ function initUTSJSONObjectProperties(obj) {
463
+ const propertyList = [
464
+ '_resolveKeyPath',
465
+ '_getValue',
466
+ 'toJSON',
467
+ 'get',
468
+ 'set',
469
+ 'getAny',
470
+ 'getString',
471
+ 'getNumber',
472
+ 'getBoolean',
473
+ 'getJSON',
474
+ 'getArray',
475
+ 'toMap',
476
+ 'forEach',
477
+ ];
478
+ const propertyDescriptorMap = {};
479
+ for (let i = 0; i < propertyList.length; i++) {
480
+ const property = propertyList[i];
481
+ propertyDescriptorMap[property] = {
482
+ enumerable: false,
483
+ value: obj[property],
484
+ };
485
+ }
486
+ Object.defineProperties(obj, propertyDescriptorMap);
487
+ }
488
+ let UTSJSONObject$1 = class UTSJSONObject {
489
+ static keys(obj) {
490
+ return Object.keys(obj);
491
+ }
492
+ static assign(target, ...sources) {
493
+ for (let i = 0; i < sources.length; i++) {
494
+ const source = sources[i];
495
+ for (let key in source) {
496
+ target[key] = source[key];
497
+ }
498
+ }
499
+ return target;
500
+ }
501
+ constructor(content = {}) {
502
+ if (content instanceof Map) {
503
+ content.forEach((value, key) => {
504
+ this[key] = value;
505
+ });
506
+ }
507
+ else {
508
+ for (const key in content) {
509
+ if (Object.prototype.hasOwnProperty.call(content, key)) {
510
+ this[key] = content[key];
511
+ }
512
+ }
513
+ }
514
+ initUTSJSONObjectProperties(this);
515
+ }
516
+ _resolveKeyPath(keyPath) {
517
+ // 非法keyPath不抛出错误,直接返回空数组
518
+ let token = '';
519
+ const keyPathArr = [];
520
+ let inOpenParentheses = false;
521
+ for (let i = 0; i < keyPath.length; i++) {
522
+ const word = keyPath[i];
523
+ switch (word) {
524
+ case '.':
525
+ if (token.length > 0) {
526
+ keyPathArr.push(token);
527
+ token = '';
528
+ }
529
+ break;
530
+ case '[': {
531
+ inOpenParentheses = true;
532
+ if (token.length > 0) {
533
+ keyPathArr.push(token);
534
+ token = '';
535
+ }
536
+ break;
537
+ }
538
+ case ']':
539
+ if (inOpenParentheses) {
540
+ if (token.length > 0) {
541
+ const tokenFirstChar = token[0];
542
+ const tokenLastChar = token[token.length - 1];
543
+ if ((tokenFirstChar === '"' && tokenLastChar === '"') ||
544
+ (tokenFirstChar === "'" && tokenLastChar === "'") ||
545
+ (tokenFirstChar === '`' && tokenLastChar === '`')) {
546
+ if (token.length > 2) {
547
+ token = token.slice(1, -1);
548
+ }
549
+ else {
550
+ return [];
551
+ }
552
+ }
553
+ else if (!/^\d+$/.test(token)) {
554
+ return [];
555
+ }
556
+ keyPathArr.push(token);
557
+ token = '';
558
+ }
559
+ else {
560
+ return [];
561
+ }
562
+ inOpenParentheses = false;
563
+ }
564
+ else {
565
+ return [];
566
+ }
567
+ break;
568
+ default:
569
+ token += word;
570
+ break;
571
+ }
572
+ if (i === keyPath.length - 1) {
573
+ if (token.length > 0) {
574
+ keyPathArr.push(token);
575
+ token = '';
576
+ }
577
+ }
578
+ }
579
+ return keyPathArr;
580
+ }
581
+ _getValue(keyPath) {
582
+ const keyPathArr = this._resolveKeyPath(keyPath);
583
+ if (keyPathArr.length === 0) {
584
+ return null;
585
+ }
586
+ let value = this;
587
+ for (let i = 0; i < keyPathArr.length; i++) {
588
+ const key = keyPathArr[i];
589
+ if (value instanceof Object) {
590
+ value = value[key];
591
+ }
592
+ else {
593
+ return null;
594
+ }
595
+ }
596
+ return value;
597
+ }
598
+ get(key) {
599
+ return this._getValue(key);
600
+ }
601
+ set(key, value) {
602
+ this[key] = value;
603
+ }
604
+ getAny(key) {
605
+ return this._getValue(key);
606
+ }
607
+ getString(key) {
608
+ const value = this._getValue(key);
609
+ if (typeof value === 'string') {
610
+ return value;
611
+ }
612
+ else {
613
+ return null;
614
+ }
615
+ }
616
+ getNumber(key) {
617
+ const value = this._getValue(key);
618
+ if (typeof value === 'number') {
619
+ return value;
620
+ }
621
+ else {
622
+ return null;
623
+ }
624
+ }
625
+ getBoolean(key) {
626
+ const boolean = this._getValue(key);
627
+ if (typeof boolean === 'boolean') {
628
+ return boolean;
629
+ }
630
+ else {
631
+ return null;
632
+ }
633
+ }
634
+ getJSON(key) {
635
+ let value = this._getValue(key);
636
+ if (value instanceof Object) {
637
+ return new UTSJSONObject(value);
638
+ }
639
+ else {
640
+ return null;
641
+ }
642
+ }
643
+ getArray(key) {
644
+ let value = this._getValue(key);
645
+ if (value instanceof Array) {
646
+ return value;
647
+ }
648
+ else {
649
+ return null;
650
+ }
651
+ }
652
+ toMap() {
653
+ let map = new Map();
654
+ for (let key in this) {
655
+ map.set(key, this[key]);
656
+ }
657
+ return map;
658
+ }
659
+ forEach(callback) {
660
+ for (let key in this) {
661
+ callback(this[key], key);
662
+ }
663
+ }
664
+ };
665
+
666
+ // @ts-nocheck
667
+ function getGlobal() {
668
+ if (typeof globalThis !== 'undefined') {
669
+ return globalThis;
670
+ }
671
+ // worker
672
+ if (typeof self !== 'undefined') {
673
+ return self;
674
+ }
675
+ // browser
676
+ if (typeof window !== 'undefined') {
677
+ return window;
678
+ }
679
+ // nodejs
680
+ if (typeof global !== 'undefined') {
681
+ return global;
682
+ }
683
+ function g() {
684
+ return this;
685
+ }
686
+ if (typeof g() !== 'undefined') {
687
+ return g();
688
+ }
689
+ return (function () {
690
+ return new Function('return this')();
691
+ })();
692
+ }
693
+ const realGlobal = getGlobal();
694
+ realGlobal.UTSJSONObject = UTSJSONObject$1;
695
+ realGlobal.UniError = UniError;
696
+ realGlobal.UTS = UTS;
697
+
698
+ function initVueIds(vueIds, mpInstance) {
699
+ if (!vueIds) {
700
+ return;
701
+ }
702
+ const ids = vueIds.split(',');
703
+ const len = ids.length;
704
+ if (len === 1) {
705
+ mpInstance._$vueId = ids[0];
706
+ }
707
+ else if (len === 2) {
708
+ mpInstance._$vueId = ids[0];
709
+ mpInstance._$vuePid = ids[1];
710
+ }
711
+ }
712
+ const EXTRAS = ['externalClasses'];
713
+ function initExtraOptions(miniProgramComponentOptions, vueOptions) {
714
+ EXTRAS.forEach((name) => {
715
+ if (hasOwn(vueOptions, name)) {
716
+ miniProgramComponentOptions[name] = vueOptions[name];
717
+ }
718
+ });
719
+ }
720
+ function initWxsCallMethods(methods, wxsCallMethods) {
721
+ if (!isArray(wxsCallMethods)) {
722
+ return;
723
+ }
724
+ wxsCallMethods.forEach((callMethod) => {
725
+ methods[callMethod] = function (args) {
726
+ return this.$vm[callMethod](args);
727
+ };
728
+ });
729
+ }
730
+ function selectAllComponents(mpInstance, selector, $refs) {
731
+ const components = mpInstance.selectAllComponents(selector);
732
+ components.forEach((component) => {
733
+ const ref = component.properties.uR;
734
+ $refs[ref] = component.$vm || component;
735
+ });
736
+ }
737
+ function initRefs(instance, mpInstance) {
738
+ Object.defineProperty(instance, 'refs', {
739
+ get() {
740
+ const $refs = {};
741
+ selectAllComponents(mpInstance, '.r', $refs);
742
+ const forComponents = mpInstance.selectAllComponents('.r-i-f');
743
+ forComponents.forEach((component) => {
744
+ const ref = component.properties.uR;
745
+ if (!ref) {
746
+ return;
747
+ }
748
+ if (!$refs[ref]) {
749
+ $refs[ref] = [];
750
+ }
751
+ $refs[ref].push(component.$vm || component);
752
+ });
753
+ {
754
+ const { $templateUniElementRefs } = instance;
755
+ if ($templateUniElementRefs && $templateUniElementRefs.length) {
756
+ $templateUniElementRefs.forEach((templateRef) => {
757
+ if (isString(templateRef.r)) {
758
+ $refs[templateRef.r] = templateRef.v;
759
+ }
760
+ });
761
+ }
762
+ }
763
+ return $refs;
764
+ },
765
+ });
766
+ }
767
+ function findVmByVueId(instance, vuePid) {
768
+ // 标准 vue3 中 没有 $children,定制了内核
769
+ const $children = instance.$children;
770
+ // 优先查找直属(反向查找:https://github.com/dcloudio/uni-app/issues/1200)
771
+ for (let i = $children.length - 1; i >= 0; i--) {
772
+ const childVm = $children[i];
773
+ if (childVm.$scope._$vueId === vuePid) {
774
+ return childVm;
775
+ }
776
+ }
777
+ // 反向递归查找
778
+ let parentVm;
779
+ for (let i = $children.length - 1; i >= 0; i--) {
780
+ parentVm = findVmByVueId($children[i], vuePid);
781
+ if (parentVm) {
782
+ return parentVm;
783
+ }
784
+ }
785
+ }
786
+ function nextSetDataTick(mpInstance, fn) {
787
+ // 随便设置一个字段来触发回调(部分平台必须有字段才可以,比如头条)
788
+ mpInstance.setData({ r1: 1 }, () => fn());
789
+ }
790
+ function initSetRef(mpInstance) {
791
+ if (!mpInstance._$setRef) {
792
+ mpInstance._$setRef = (fn) => {
793
+ nextTick(() => nextSetDataTick(mpInstance, fn));
794
+ };
795
+ }
796
+ }
797
+
798
+ const MP_METHODS = [
799
+ 'createSelectorQuery',
800
+ 'createIntersectionObserver',
801
+ 'selectAllComponents',
802
+ 'selectComponent',
803
+ ];
804
+ function createEmitFn(oldEmit, ctx) {
805
+ return function emit(event, ...args) {
806
+ const scope = ctx.$scope;
807
+ if (scope && event) {
808
+ const detail = { __args__: args };
809
+ {
810
+ scope.triggerEvent(event, detail);
811
+ }
812
+ }
813
+ return oldEmit.apply(this, [event, ...args]);
814
+ };
815
+ }
816
+ function initBaseInstance(instance, options) {
817
+ const ctx = instance.ctx;
818
+ // mp
819
+ ctx.mpType = options.mpType; // @deprecated
820
+ ctx.$mpType = options.mpType;
821
+ ctx.$mpPlatform = "mp-toutiao";
822
+ ctx.$scope = options.mpInstance;
823
+ // TODO @deprecated
824
+ ctx.$mp = {};
825
+ if (__VUE_OPTIONS_API__) {
826
+ ctx._self = {};
827
+ }
828
+ // slots
829
+ instance.slots = {};
830
+ if (isArray(options.slots) && options.slots.length) {
831
+ options.slots.forEach((name) => {
832
+ instance.slots[name] = true;
833
+ });
834
+ if (instance.slots[SLOT_DEFAULT_NAME]) {
835
+ instance.slots.default = true;
836
+ }
837
+ }
838
+ ctx.getOpenerEventChannel = function () {
839
+ if (!this.__eventChannel__) {
840
+ this.__eventChannel__ = new EventChannel();
841
+ }
842
+ return this.__eventChannel__;
843
+ };
844
+ ctx.$hasHook = hasHook;
845
+ ctx.$callHook = callHook;
846
+ // $emit
847
+ instance.emit = createEmitFn(instance.emit, ctx);
848
+ {
849
+ onUpdated(() => {
850
+ pruneUniElements(instance);
851
+ }, instance);
852
+ onUnmounted(() => {
853
+ destroyUniElements(instance);
854
+ }, instance);
855
+ }
856
+ }
857
+ function initComponentInstance(instance, options) {
858
+ initBaseInstance(instance, options);
859
+ const ctx = instance.ctx;
860
+ MP_METHODS.forEach((method) => {
861
+ ctx[method] = function (...args) {
862
+ const mpInstance = ctx.$scope;
863
+ if (mpInstance && mpInstance[method]) {
864
+ return mpInstance[method].apply(mpInstance, args);
865
+ }
866
+ };
867
+ });
868
+ }
869
+ function initMocks(instance, mpInstance, mocks) {
870
+ const ctx = instance.ctx;
871
+ mocks.forEach((mock) => {
872
+ if (hasOwn(mpInstance, mock)) {
873
+ instance[mock] = ctx[mock] = mpInstance[mock];
874
+ }
875
+ });
876
+ }
877
+ function hasHook(name) {
878
+ const hooks = this.$[name];
879
+ if (hooks && hooks.length) {
880
+ return true;
881
+ }
882
+ return false;
883
+ }
884
+ function callHook(name, args) {
885
+ if (name === 'mounted') {
886
+ callHook.call(this, 'bm'); // beforeMount
887
+ this.$.isMounted = true;
888
+ name = 'm';
889
+ }
890
+ {
891
+ if (name === 'onLoad' &&
892
+ args &&
893
+ args.__id__ &&
894
+ isFunction(tt.getEventChannel)) {
895
+ this.__eventChannel__ = tt.getEventChannel(args.__id__);
896
+ delete args.__id__;
897
+ }
898
+ }
899
+ const hooks = this.$[name];
900
+ return hooks && invokeArrayFns(hooks, args);
901
+ }
902
+
903
+ const PAGE_INIT_HOOKS = [
904
+ ON_LOAD,
905
+ ON_SHOW,
906
+ ON_HIDE,
907
+ ON_UNLOAD,
908
+ ON_RESIZE,
909
+ ON_TAB_ITEM_TAP,
910
+ ON_REACH_BOTTOM,
911
+ ON_PULL_DOWN_REFRESH,
912
+ ON_ADD_TO_FAVORITES,
913
+ // 'onReady', // lifetimes.ready
914
+ // 'onPageScroll', // 影响性能,开发者手动注册
915
+ // 'onShareTimeline', // 右上角菜单,开发者手动注册
916
+ // 'onShareAppMessage' // 右上角菜单,开发者手动注册
917
+ ];
918
+ function findHooks(vueOptions, hooks = new Set()) {
919
+ if (vueOptions) {
920
+ Object.keys(vueOptions).forEach((name) => {
921
+ if (isUniLifecycleHook(name, vueOptions[name])) {
922
+ hooks.add(name);
923
+ }
924
+ });
925
+ if (__VUE_OPTIONS_API__) {
926
+ const { extends: extendsOptions, mixins } = vueOptions;
927
+ if (mixins) {
928
+ mixins.forEach((mixin) => findHooks(mixin, hooks));
929
+ }
930
+ if (extendsOptions) {
931
+ findHooks(extendsOptions, hooks);
932
+ }
933
+ }
934
+ }
935
+ return hooks;
936
+ }
937
+ function initHook(mpOptions, hook, excludes) {
938
+ if (excludes.indexOf(hook) === -1 && !hasOwn(mpOptions, hook)) {
939
+ mpOptions[hook] = function (args) {
940
+ if (hook === 'onError') {
941
+ return getApp().$vm.$callHook(hook, args);
942
+ }
943
+ return this.$vm && this.$vm.$callHook(hook, args);
944
+ };
945
+ }
946
+ }
947
+ const EXCLUDE_HOOKS = [ON_READY];
948
+ function initHooks(mpOptions, hooks, excludes = EXCLUDE_HOOKS) {
949
+ hooks.forEach((hook) => initHook(mpOptions, hook, excludes));
950
+ }
951
+ function initUnknownHooks(mpOptions, vueOptions, excludes = EXCLUDE_HOOKS) {
952
+ findHooks(vueOptions).forEach((hook) => initHook(mpOptions, hook, excludes));
953
+ }
954
+ function initRuntimeHooks(mpOptions, runtimeHooks) {
955
+ if (!runtimeHooks) {
956
+ return;
957
+ }
958
+ const hooks = Object.keys(MINI_PROGRAM_PAGE_RUNTIME_HOOKS);
959
+ hooks.forEach((hook) => {
960
+ if (runtimeHooks & MINI_PROGRAM_PAGE_RUNTIME_HOOKS[hook]) {
961
+ initHook(mpOptions, hook, []);
962
+ }
963
+ });
964
+ }
965
+ const findMixinRuntimeHooks = /*#__PURE__*/ once(() => {
966
+ const runtimeHooks = [];
967
+ const app = isFunction(getApp) && getApp({ allowDefault: true });
968
+ if (app && app.$vm && app.$vm.$) {
969
+ const mixins = app.$vm.$.appContext.mixins;
970
+ if (isArray(mixins)) {
971
+ const hooks = Object.keys(MINI_PROGRAM_PAGE_RUNTIME_HOOKS);
972
+ mixins.forEach((mixin) => {
973
+ hooks.forEach((hook) => {
974
+ if (hasOwn(mixin, hook) && !runtimeHooks.includes(hook)) {
975
+ runtimeHooks.push(hook);
976
+ }
977
+ });
978
+ });
979
+ }
980
+ }
981
+ return runtimeHooks;
982
+ });
983
+ function initMixinRuntimeHooks(mpOptions) {
984
+ initHooks(mpOptions, findMixinRuntimeHooks());
985
+ }
986
+
987
+ const HOOKS = [
988
+ ON_SHOW,
989
+ ON_HIDE,
990
+ ON_ERROR,
991
+ ON_THEME_CHANGE,
992
+ ON_PAGE_NOT_FOUND,
993
+ ON_UNHANDLE_REJECTION,
994
+ ];
995
+ function parseApp(instance, parseAppOptions) {
996
+ const internalInstance = instance.$;
997
+ if (__VUE_PROD_DEVTOOLS__) {
998
+ // 定制 App 的 $children
999
+ Object.defineProperty(internalInstance.ctx, '$children', {
1000
+ get() {
1001
+ return getCurrentPages().map((page) => page.$vm);
1002
+ },
1003
+ });
1004
+ }
1005
+ const appOptions = {
1006
+ globalData: (instance.$options && instance.$options.globalData) || {},
1007
+ $vm: instance, // mp-alipay 组件 data 初始化比 onLaunch 早,提前挂载
1008
+ onLaunch(options) {
1009
+ this.$vm = instance; // 飞书小程序可能会把 AppOptions 序列化,导致 $vm 对象部分属性丢失
1010
+ const ctx = internalInstance.ctx;
1011
+ if (this.$vm && ctx.$scope && ctx.$callHook) {
1012
+ // 已经初始化过了,主要是为了百度,百度 onShow 在 onLaunch 之前
1013
+ // $scope值在微信小程序混合分包情况下存在,额外用$callHook兼容判断处理
1014
+ return;
1015
+ }
1016
+ initBaseInstance(internalInstance, {
1017
+ mpType: 'app',
1018
+ mpInstance: this,
1019
+ slots: [],
1020
+ });
1021
+ ctx.globalData = this.globalData;
1022
+ instance.$callHook(ON_LAUNCH, options);
1023
+ },
1024
+ };
1025
+ const { onError } = internalInstance;
1026
+ if (onError) {
1027
+ internalInstance.appContext.config.errorHandler = (err) => {
1028
+ instance.$callHook(ON_ERROR, err);
1029
+ };
1030
+ }
1031
+ initLocale(instance);
1032
+ const vueOptions = instance.$.type;
1033
+ initHooks(appOptions, HOOKS);
1034
+ initUnknownHooks(appOptions, vueOptions);
1035
+ if (__VUE_OPTIONS_API__) {
1036
+ const methods = vueOptions.methods;
1037
+ methods && extend(appOptions, methods);
1038
+ }
1039
+ return appOptions;
1040
+ }
1041
+ function initCreateApp(parseAppOptions) {
1042
+ return function createApp(vm) {
1043
+ return App(parseApp(vm));
1044
+ };
1045
+ }
1046
+ function initCreateSubpackageApp(parseAppOptions) {
1047
+ return function createApp(vm) {
1048
+ const appOptions = parseApp(vm);
1049
+ const app = isFunction(getApp) &&
1050
+ getApp({
1051
+ allowDefault: true,
1052
+ });
1053
+ if (!app)
1054
+ return;
1055
+ vm.$.ctx.$scope = app;
1056
+ const globalData = app.globalData;
1057
+ if (globalData) {
1058
+ Object.keys(appOptions.globalData).forEach((name) => {
1059
+ if (!hasOwn(globalData, name)) {
1060
+ globalData[name] = appOptions.globalData[name];
1061
+ }
1062
+ });
1063
+ }
1064
+ Object.keys(appOptions).forEach((name) => {
1065
+ if (!hasOwn(app, name)) {
1066
+ app[name] = appOptions[name];
1067
+ }
1068
+ });
1069
+ initAppLifecycle(appOptions, vm);
1070
+ if (process.env.UNI_SUBPACKAGE) {
1071
+ (tt.$subpackages || (tt.$subpackages = {}))[process.env.UNI_SUBPACKAGE] = {
1072
+ $vm: vm,
1073
+ };
1074
+ }
1075
+ };
1076
+ }
1077
+ function initAppLifecycle(appOptions, vm) {
1078
+ if (isFunction(appOptions.onLaunch)) {
1079
+ const args = tt.getLaunchOptionsSync && tt.getLaunchOptionsSync();
1080
+ appOptions.onLaunch(args);
1081
+ }
1082
+ if (isFunction(appOptions.onShow) && tt.onAppShow) {
1083
+ tt.onAppShow((args) => {
1084
+ vm.$callHook('onShow', args);
1085
+ });
1086
+ }
1087
+ if (isFunction(appOptions.onHide) && tt.onAppHide) {
1088
+ tt.onAppHide((args) => {
1089
+ vm.$callHook('onHide', args);
1090
+ });
1091
+ }
1092
+ }
1093
+ function initLocale(appVm) {
1094
+ const locale = ref(normalizeLocale(tt.getSystemInfoSync().language) || LOCALE_EN);
1095
+ Object.defineProperty(appVm, '$locale', {
1096
+ get() {
1097
+ return locale.value;
1098
+ },
1099
+ set(v) {
1100
+ locale.value = v;
1101
+ },
1102
+ });
1103
+ }
1104
+
1105
+ const builtInProps = [
1106
+ // 百度小程序,快手小程序自定义组件不支持绑定动态事件,动态dataset,故通过props传递事件信息
1107
+ // event-opts
1108
+ 'eO',
1109
+ // 组件 ref
1110
+ 'uR',
1111
+ // 组件 ref-in-for
1112
+ 'uRIF',
1113
+ // 组件 id
1114
+ 'uI',
1115
+ // 组件类型 m: 小程序组件
1116
+ 'uT',
1117
+ // 组件 props
1118
+ 'uP',
1119
+ // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
1120
+ 'uS',
1121
+ ];
1122
+ function initDefaultProps(options, isBehavior = false) {
1123
+ const properties = {};
1124
+ if (!isBehavior) {
1125
+ // 均不指定类型,避免微信小程序 property received type-uncompatible value 警告
1126
+ builtInProps.forEach((name) => {
1127
+ properties[name] = {
1128
+ type: null,
1129
+ value: '',
1130
+ };
1131
+ });
1132
+ // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
1133
+ function observerSlots(newVal) {
1134
+ const $slots = Object.create(null);
1135
+ newVal &&
1136
+ newVal.forEach((slotName) => {
1137
+ $slots[slotName] = true;
1138
+ });
1139
+ this.setData({
1140
+ $slots,
1141
+ });
1142
+ }
1143
+ properties.uS = {
1144
+ type: null,
1145
+ value: [],
1146
+ };
1147
+ {
1148
+ properties.uS.observer = observerSlots;
1149
+ }
1150
+ }
1151
+ if (options.behaviors) {
1152
+ // wx://form-field
1153
+ if (options.behaviors.includes('tt' + '://form-field')) {
1154
+ if (!options.properties || !options.properties.name) {
1155
+ properties.name = {
1156
+ type: null,
1157
+ value: '',
1158
+ };
1159
+ }
1160
+ if (!options.properties || !options.properties.value) {
1161
+ properties.value = {
1162
+ type: null,
1163
+ value: '',
1164
+ };
1165
+ }
1166
+ }
1167
+ }
1168
+ return properties;
1169
+ }
1170
+ function initVirtualHostProps(options) {
1171
+ const properties = {};
1172
+ {
1173
+ if ((options && options.virtualHost)) {
1174
+ {
1175
+ options.applyFragment = true;
1176
+ }
1177
+ properties.virtualHostStyle = {
1178
+ type: null,
1179
+ value: '',
1180
+ };
1181
+ properties.virtualHostClass = {
1182
+ type: null,
1183
+ value: '',
1184
+ };
1185
+ }
1186
+ }
1187
+ return properties;
1188
+ }
1189
+ /**
1190
+ *
1191
+ * @param mpComponentOptions
1192
+ * @param isBehavior
1193
+ */
1194
+ function initProps(mpComponentOptions) {
1195
+ if (!mpComponentOptions.properties) {
1196
+ mpComponentOptions.properties = {};
1197
+ }
1198
+ extend(mpComponentOptions.properties, initDefaultProps(mpComponentOptions), initVirtualHostProps(mpComponentOptions.options));
1199
+ }
1200
+ const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
1201
+ function parsePropType(type, defaultValue) {
1202
+ // [String]=>String
1203
+ if (isArray(type) && type.length === 1) {
1204
+ return type[0];
1205
+ }
1206
+ return type;
1207
+ }
1208
+ function normalizePropType(type, defaultValue) {
1209
+ const res = parsePropType(type);
1210
+ return PROP_TYPES.indexOf(res) !== -1 ? res : null;
1211
+ }
1212
+ /**
1213
+ * 初始化页面 props,方便接收页面参数,类型均为String,默认值均为''
1214
+ * @param param
1215
+ * @param rawProps
1216
+ */
1217
+ function initPageProps({ properties }, rawProps) {
1218
+ if (isArray(rawProps)) {
1219
+ rawProps.forEach((key) => {
1220
+ properties[key] = {
1221
+ type: String,
1222
+ value: '',
1223
+ };
1224
+ });
1225
+ }
1226
+ else if (isPlainObject$1(rawProps)) {
1227
+ Object.keys(rawProps).forEach((key) => {
1228
+ const opts = rawProps[key];
1229
+ if (isPlainObject$1(opts)) {
1230
+ // title:{type:String,default:''}
1231
+ let value = opts.default;
1232
+ if (isFunction(value)) {
1233
+ value = value();
1234
+ }
1235
+ const type = opts.type;
1236
+ opts.type = normalizePropType(type);
1237
+ properties[key] = {
1238
+ type: opts.type,
1239
+ value,
1240
+ };
1241
+ }
1242
+ else {
1243
+ // content:String
1244
+ properties[key] = {
1245
+ type: normalizePropType(opts),
1246
+ };
1247
+ }
1248
+ });
1249
+ }
1250
+ }
1251
+ function findPropsData(properties, isPage) {
1252
+ return ((isPage
1253
+ ? findPagePropsData(properties)
1254
+ : findComponentPropsData(resolvePropValue(properties.uP))) || {});
1255
+ }
1256
+ function findPagePropsData(properties) {
1257
+ const propsData = {};
1258
+ if (isPlainObject$1(properties)) {
1259
+ Object.keys(properties).forEach((name) => {
1260
+ if (builtInProps.indexOf(name) === -1) {
1261
+ propsData[name] = resolvePropValue(properties[name]);
1262
+ }
1263
+ });
1264
+ }
1265
+ return propsData;
1266
+ }
1267
+ function initFormField(vm) {
1268
+ // 同步 form-field 的 name,value 值
1269
+ const vueOptions = vm.$options;
1270
+ if (isArray(vueOptions.behaviors) &&
1271
+ vueOptions.behaviors.includes('uni://form-field')) {
1272
+ vm.$watch('modelValue', () => {
1273
+ vm.$scope &&
1274
+ vm.$scope.setData({
1275
+ name: vm.name,
1276
+ value: vm.modelValue,
1277
+ });
1278
+ }, {
1279
+ immediate: true,
1280
+ });
1281
+ }
1282
+ }
1283
+ function resolvePropValue(prop) {
1284
+ return prop;
1285
+ }
1286
+
1287
+ function initData(_) {
1288
+ return {};
1289
+ }
1290
+ function initPropsObserver(componentOptions) {
1291
+ const observe = function observe() {
1292
+ const up = this.properties.uP;
1293
+ if (!up) {
1294
+ return;
1295
+ }
1296
+ if (this.$vm) {
1297
+ updateComponentProps(resolvePropValue(up), this.$vm.$);
1298
+ }
1299
+ else if (resolvePropValue(this.properties.uT) === 'm') {
1300
+ // 小程序组件
1301
+ updateMiniProgramComponentProperties(resolvePropValue(up), this);
1302
+ }
1303
+ };
1304
+ {
1305
+ componentOptions.properties.uP.observer = observe;
1306
+ }
1307
+ }
1308
+ function updateMiniProgramComponentProperties(up, mpInstance) {
1309
+ const prevProps = mpInstance.properties;
1310
+ const nextProps = findComponentPropsData(up) || {};
1311
+ if (hasPropsChanged(prevProps, nextProps, false)) {
1312
+ mpInstance.setData(nextProps);
1313
+ }
1314
+ }
1315
+ function updateComponentProps(up, instance) {
1316
+ const prevProps = toRaw(instance.props);
1317
+ const nextProps = findComponentPropsData(up) || {};
1318
+ if (hasPropsChanged(prevProps, nextProps)) {
1319
+ updateProps(instance, nextProps, prevProps, false);
1320
+ if (hasQueueJob(instance.update)) {
1321
+ invalidateJob(instance.update);
1322
+ }
1323
+ {
1324
+ // 字节跳动小程序 https://github.com/dcloudio/uni-app/issues/3340
1325
+ // 百度小程序 https://github.com/dcloudio/uni-app/issues/3612
1326
+ if (!hasQueueJob(instance.update)) {
1327
+ instance.update();
1328
+ }
1329
+ }
1330
+ }
1331
+ }
1332
+ function hasPropsChanged(prevProps, nextProps, checkLen = true) {
1333
+ const nextKeys = Object.keys(nextProps);
1334
+ if (checkLen && nextKeys.length !== Object.keys(prevProps).length) {
1335
+ return true;
1336
+ }
1337
+ for (let i = 0; i < nextKeys.length; i++) {
1338
+ const key = nextKeys[i];
1339
+ if (nextProps[key] !== prevProps[key]) {
1340
+ return true;
1341
+ }
1342
+ }
1343
+ return false;
1344
+ }
1345
+ function initBehaviors(vueOptions) {
1346
+ const vueBehaviors = vueOptions.behaviors;
1347
+ let vueProps = vueOptions.props;
1348
+ if (!vueProps) {
1349
+ vueOptions.props = vueProps = [];
1350
+ }
1351
+ const behaviors = [];
1352
+ if (isArray(vueBehaviors)) {
1353
+ vueBehaviors.forEach((behavior) => {
1354
+ // 这里的 global 应该是个变量
1355
+ behaviors.push(behavior.replace('uni://', 'tt' + '://'));
1356
+ if (behavior === 'uni://form-field') {
1357
+ if (isArray(vueProps)) {
1358
+ vueProps.push('name');
1359
+ vueProps.push('modelValue');
1360
+ }
1361
+ else {
1362
+ vueProps.name = {
1363
+ type: String,
1364
+ default: '',
1365
+ };
1366
+ vueProps.modelValue = {
1367
+ type: [String, Number, Boolean, Array, Object, Date],
1368
+ default: '',
1369
+ };
1370
+ }
1371
+ }
1372
+ });
1373
+ }
1374
+ return behaviors;
1375
+ }
1376
+ function applyOptions(componentOptions, vueOptions) {
1377
+ componentOptions.data = initData();
1378
+ componentOptions.behaviors = initBehaviors(vueOptions);
1379
+ }
1380
+
1381
+ function parseComponent(vueOptions, { parse, mocks, isPage, initRelation, handleLink, initLifetimes, }) {
1382
+ vueOptions = vueOptions.default || vueOptions;
1383
+ const options = {
1384
+ multipleSlots: true,
1385
+ // styleIsolation: 'apply-shared',
1386
+ addGlobalClass: true,
1387
+ pureDataPattern: /^uP$/,
1388
+ };
1389
+ if (isArray(vueOptions.mixins)) {
1390
+ vueOptions.mixins.forEach((item) => {
1391
+ if (isObject(item.options)) {
1392
+ extend(options, item.options);
1393
+ }
1394
+ });
1395
+ }
1396
+ if (vueOptions.options) {
1397
+ extend(options, vueOptions.options);
1398
+ }
1399
+ const mpComponentOptions = {
1400
+ options,
1401
+ lifetimes: initLifetimes({ mocks, isPage, initRelation, vueOptions }),
1402
+ pageLifetimes: {
1403
+ show() {
1404
+ if (__VUE_PROD_DEVTOOLS__) {
1405
+ devtoolsComponentAdded(this.$vm.$);
1406
+ }
1407
+ this.$vm && this.$vm.$callHook('onPageShow');
1408
+ },
1409
+ hide() {
1410
+ this.$vm && this.$vm.$callHook('onPageHide');
1411
+ },
1412
+ resize(size) {
1413
+ this.$vm && this.$vm.$callHook('onPageResize', size);
1414
+ },
1415
+ },
1416
+ methods: {
1417
+ __l: handleLink,
1418
+ },
1419
+ };
1420
+ if (__VUE_OPTIONS_API__) {
1421
+ applyOptions(mpComponentOptions, vueOptions);
1422
+ }
1423
+ initProps(mpComponentOptions);
1424
+ initPropsObserver(mpComponentOptions);
1425
+ initExtraOptions(mpComponentOptions, vueOptions);
1426
+ initWxsCallMethods(mpComponentOptions.methods, vueOptions.wxsCallMethods);
1427
+ if (parse) {
1428
+ parse(mpComponentOptions, { handleLink });
1429
+ }
1430
+ return mpComponentOptions;
1431
+ }
1432
+ function initCreateComponent(parseOptions) {
1433
+ return function createComponent(vueComponentOptions) {
1434
+ {
1435
+ const rootElement = vueComponentOptions.rootElement;
1436
+ if (rootElement) {
1437
+ registerCustomElement(rootElement.name, rootElement.class);
1438
+ }
1439
+ }
1440
+ return Component(parseComponent(vueComponentOptions, parseOptions));
1441
+ };
1442
+ }
1443
+ let $createComponentFn;
1444
+ let $destroyComponentFn;
1445
+ function getAppVm() {
1446
+ if (process.env.UNI_MP_PLUGIN) {
1447
+ return tt.$vm;
1448
+ }
1449
+ if (process.env.UNI_SUBPACKAGE) {
1450
+ return tt.$subpackages[process.env.UNI_SUBPACKAGE].$vm;
1451
+ }
1452
+ return getApp().$vm;
1453
+ }
1454
+ function $createComponent(initialVNode, options) {
1455
+ if (!$createComponentFn) {
1456
+ $createComponentFn = getAppVm().$createComponent;
1457
+ }
1458
+ const proxy = $createComponentFn(initialVNode, options);
1459
+ return getExposeProxy(proxy.$) || proxy;
1460
+ }
1461
+ function $destroyComponent(instance) {
1462
+ if (!$destroyComponentFn) {
1463
+ $destroyComponentFn = getAppVm().$destroyComponent;
1464
+ }
1465
+ return $destroyComponentFn(instance);
1466
+ }
1467
+
1468
+ function parsePage(vueOptions, parseOptions) {
1469
+ const { parse, mocks, isPage, initRelation, handleLink, initLifetimes } = parseOptions;
1470
+ const miniProgramPageOptions = parseComponent(vueOptions, {
1471
+ mocks,
1472
+ isPage,
1473
+ initRelation,
1474
+ handleLink,
1475
+ initLifetimes,
1476
+ });
1477
+ initPageProps(miniProgramPageOptions, (vueOptions.default || vueOptions).props);
1478
+ const methods = miniProgramPageOptions.methods;
1479
+ methods.onLoad = function (query) {
1480
+ this.options = query;
1481
+ this.$page = {
1482
+ fullPath: addLeadingSlash(this.route + stringifyQuery(query)),
1483
+ };
1484
+ return this.$vm && this.$vm.$callHook(ON_LOAD, query);
1485
+ };
1486
+ initHooks(methods, PAGE_INIT_HOOKS);
1487
+ {
1488
+ initUnknownHooks(methods, vueOptions);
1489
+ }
1490
+ initRuntimeHooks(methods, vueOptions.__runtimeHooks);
1491
+ initMixinRuntimeHooks(methods);
1492
+ parse && parse(miniProgramPageOptions, { handleLink });
1493
+ return miniProgramPageOptions;
1494
+ }
1495
+ function initCreatePage(parseOptions) {
1496
+ return function createPage(vuePageOptions) {
1497
+ return Component(parsePage(vuePageOptions, parseOptions));
1498
+ };
1499
+ }
1500
+
1501
+ const MPPage = Page;
1502
+ const MPComponent = Component;
1503
+ function initTriggerEvent(mpInstance) {
1504
+ const oldTriggerEvent = mpInstance.triggerEvent;
1505
+ const newTriggerEvent = function (event, ...args) {
1506
+ return oldTriggerEvent.apply(mpInstance, [
1507
+ customizeEvent(event),
1508
+ ...args,
1509
+ ]);
1510
+ };
1511
+ // 京东小程序triggerEvent为只读属性
1512
+ try {
1513
+ mpInstance.triggerEvent = newTriggerEvent;
1514
+ }
1515
+ catch (error) {
1516
+ mpInstance._triggerEvent = newTriggerEvent;
1517
+ }
1518
+ }
1519
+ function initMiniProgramHook(name, options, isComponent) {
1520
+ if (isComponent) {
1521
+ // fix by Lxh 字节自定义组件Component构造器文档上写有created,但是实测只触发了lifetimes上的created
1522
+ options = options.lifetimes || {};
1523
+ }
1524
+ const oldHook = options[name];
1525
+ if (!oldHook) {
1526
+ options[name] = function () {
1527
+ initTriggerEvent(this);
1528
+ };
1529
+ }
1530
+ else {
1531
+ options[name] = function (...args) {
1532
+ initTriggerEvent(this);
1533
+ return oldHook.apply(this, args);
1534
+ };
1535
+ }
1536
+ }
1537
+ Page = function (options) {
1538
+ initMiniProgramHook(ON_LOAD, options);
1539
+ return MPPage(options);
1540
+ };
1541
+ Component = function (options) {
1542
+ initMiniProgramHook('created', options, true);
1543
+ // 小程序组件
1544
+ const isVueComponent = options.properties && options.properties.uP;
1545
+ if (!isVueComponent) {
1546
+ initProps(options);
1547
+ initPropsObserver(options);
1548
+ }
1549
+ return MPComponent(options);
1550
+ };
1551
+
1552
+ // @ts-expect-error
1553
+ // 基础库 2.0 以上 attached 顺序错乱,按照 created 顺序强制纠正
1554
+ const components = [];
1555
+ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
1556
+ function created() {
1557
+ components.push(this);
1558
+ }
1559
+ function attached() {
1560
+ initSetRef(this);
1561
+ const properties = this.properties;
1562
+ initVueIds(resolvePropValue(properties.uI), this);
1563
+ const relationOptions = {
1564
+ vuePid: this._$vuePid,
1565
+ };
1566
+ // 初始化 vue 实例
1567
+ const mpInstance = this;
1568
+ const mpType = isPage(mpInstance) ? 'page' : 'component';
1569
+ if (mpType === 'page' && !mpInstance.route && mpInstance.__route__) {
1570
+ mpInstance.route = mpInstance.__route__;
1571
+ }
1572
+ const props = findPropsData(properties, mpType === 'page');
1573
+ this.$vm = $createComponent({
1574
+ type: vueOptions,
1575
+ props,
1576
+ }, {
1577
+ mpType,
1578
+ mpInstance,
1579
+ slots: resolvePropValue(properties.uS) || {}, // vueSlots
1580
+ parentComponent: relationOptions.parent && relationOptions.parent.$,
1581
+ onBeforeSetup(instance, options) {
1582
+ initRefs(instance, mpInstance);
1583
+ initMocks(instance, mpInstance, mocks);
1584
+ initComponentInstance(instance, options);
1585
+ },
1586
+ });
1587
+ if (process.env.UNI_DEBUG) {
1588
+ console.log('uni-app:[' +
1589
+ Date.now() +
1590
+ '][' +
1591
+ (mpInstance.is || mpInstance.route) +
1592
+ '][' +
1593
+ this.$vm.$.uid +
1594
+ ']attached');
1595
+ }
1596
+ if (mpType === 'component') {
1597
+ initFormField(this.$vm);
1598
+ }
1599
+ // 处理父子关系
1600
+ initRelation(this, relationOptions);
1601
+ }
1602
+ function detached() {
1603
+ if (this.$vm) {
1604
+ pruneComponentPropsCache(this.$vm.$.uid);
1605
+ $destroyComponent(this.$vm);
1606
+ }
1607
+ }
1608
+ return {
1609
+ created,
1610
+ attached() {
1611
+ this.__lifetimes_attached = function () {
1612
+ attached.call(this);
1613
+ };
1614
+ let component = this;
1615
+ while (component &&
1616
+ component.__lifetimes_attached &&
1617
+ components[0] &&
1618
+ component === components[0]) {
1619
+ components.shift();
1620
+ component.__lifetimes_attached();
1621
+ delete component.__lifetimes_attached;
1622
+ component = components[0];
1623
+ }
1624
+ },
1625
+ detached,
1626
+ };
1627
+ }
1628
+
1629
+ const mocks = [
1630
+ '__route__',
1631
+ '__webviewId__',
1632
+ '__nodeId__',
1633
+ '__nodeid__' /* @Deprecated */,
1634
+ ];
1635
+ function isPage(mpInstance) {
1636
+ return (mpInstance.__nodeId__ === 0 || mpInstance.__nodeid__ === 0);
1637
+ }
1638
+ const instances = Object.create(null);
1639
+ function initRelation(mpInstance, detail) {
1640
+ var _a, _b, _c;
1641
+ // 头条 triggerEvent 后,接收事件时机特别晚,已经到了 ready 之后
1642
+ const nodeId = (hasOwn(mpInstance, '__nodeId__')
1643
+ ? mpInstance.__nodeId__
1644
+ : mpInstance.__nodeid__);
1645
+ const webviewId = mpInstance.__webviewId__ + '';
1646
+ instances[webviewId + '_' + nodeId] = mpInstance.$vm;
1647
+ // 使用 virtualHost 后,头条不支持 triggerEvent,通过主动调用方法抹平差异
1648
+ if (((_c = (_b = (_a = mpInstance === null || mpInstance === void 0 ? void 0 : mpInstance.$vm) === null || _a === void 0 ? void 0 : _a.$options) === null || _b === void 0 ? void 0 : _b.options) === null || _c === void 0 ? void 0 : _c.virtualHost)) {
1649
+ nextSetDataTick(mpInstance, () => {
1650
+ handleLink.apply(mpInstance, [
1651
+ {
1652
+ detail: {
1653
+ vuePid: detail.vuePid,
1654
+ nodeId,
1655
+ webviewId,
1656
+ // 如果是 virtualHost,则需要找到页面 vm 传递给 handleLink,因为此时的上下文是不对的,需要从页面 vm 递归查找
1657
+ // 目前测试来看,页面的 nodeId 是 0
1658
+ pageVm: instances[webviewId + '_0'],
1659
+ },
1660
+ },
1661
+ ]);
1662
+ });
1663
+ }
1664
+ else {
1665
+ mpInstance.triggerEvent('__l', {
1666
+ vuePid: detail.vuePid,
1667
+ nodeId,
1668
+ webviewId,
1669
+ });
1670
+ }
1671
+ }
1672
+ function handleLink({ detail: { vuePid, nodeId, webviewId, pageVm }, }) {
1673
+ const vm = instances[webviewId + '_' + nodeId];
1674
+ if (!vm) {
1675
+ return;
1676
+ }
1677
+ let parentVm;
1678
+ if (vuePid) {
1679
+ parentVm = findVmByVueId(pageVm || this.$vm, vuePid);
1680
+ }
1681
+ else {
1682
+ // 如果 vuePid 不存在,则认为当前组件的父是页面,目前测试来看,页面的 nodeId 是 0
1683
+ parentVm = instances[webviewId + '_0'];
1684
+ }
1685
+ if (parentVm) {
1686
+ vm.$.parent = parentVm.$;
1687
+ }
1688
+ // 不再需要下述逻辑
1689
+ // if (this.$vm?.$options?.options?.virtualHost) {
1690
+ // // 抖音小程序下 form 组件开启 virtualHost 出现 infinite loop. see: https://github.com/vuejs/core/blob/32a1433e0debd538c199bde18390bb903b4cde5a/packages/runtime-core/src/componentProps.ts#L227
1691
+ // // vm.$.parent = null
1692
+ // } else {
1693
+ // vm.$.parent = parentVm.$
1694
+ // }
1695
+ if (__VUE_OPTIONS_API__ && parentVm) {
1696
+ parentVm.$children.push(vm);
1697
+ }
1698
+ vm.$callCreatedHook();
1699
+ // TODO 字节小程序父子组件关系建立的较晚,导致 inject 和 provide 初始化变慢
1700
+ // 由此引发在 setup 中暂不可用,只能通过 options 方式配置
1701
+ // 初始化完 inject 后,再次调用 update,触发一次更新
1702
+ if (vm.$options.inject) {
1703
+ vm.$.update();
1704
+ }
1705
+ nextSetDataTick(this, () => {
1706
+ vm.$callHook('mounted');
1707
+ vm.$callHook(ON_READY);
1708
+ });
1709
+ }
1710
+ function parse(componentOptions, { handleLink }) {
1711
+ componentOptions.methods.__l = handleLink;
1712
+ }
1713
+
1714
+ var parseComponentOptions = /*#__PURE__*/Object.freeze({
1715
+ __proto__: null,
1716
+ handleLink: handleLink,
1717
+ initLifetimes: initLifetimes$1,
1718
+ initRelation: initRelation,
1719
+ instances: instances,
1720
+ isPage: isPage,
1721
+ mocks: mocks,
1722
+ parse: parse
1723
+ });
1724
+
1725
+ function initLifetimes(lifetimesOptions) {
1726
+ return extend(initLifetimes$1(lifetimesOptions), {
1727
+ ready() {
1728
+ if (this.$vm && lifetimesOptions.isPage(this)) {
1729
+ if (this.pageinstance) {
1730
+ this.__webviewId__ = this.pageinstance.__pageId__;
1731
+ }
1732
+ if (process.env.UNI_DEBUG) {
1733
+ console.log('uni-app:[' + Date.now() + '][' + (this.is || this.route) + ']ready');
1734
+ }
1735
+ this.$vm.$callCreatedHook();
1736
+ nextSetDataTick(this, () => {
1737
+ this.$vm.$callHook('mounted');
1738
+ this.$vm.$callHook(ON_READY);
1739
+ });
1740
+ }
1741
+ else {
1742
+ this.is && console.warn(this.is + ' is not ready');
1743
+ }
1744
+ },
1745
+ detached() {
1746
+ this.$vm && $destroyComponent(this.$vm);
1747
+ // 清理
1748
+ const webviewId = this.__webviewId__;
1749
+ webviewId &&
1750
+ Object.keys(instances).forEach((key) => {
1751
+ if (key.indexOf(webviewId + '_') === 0) {
1752
+ delete instances[key];
1753
+ }
1754
+ });
1755
+ },
1756
+ });
1757
+ }
1758
+
1759
+ var parsePageOptions = /*#__PURE__*/Object.freeze({
1760
+ __proto__: null,
1761
+ handleLink: handleLink,
1762
+ initLifetimes: initLifetimes,
1763
+ initRelation: initRelation,
1764
+ isPage: isPage,
1765
+ mocks: mocks,
1766
+ parse: parse
1767
+ });
1768
+
1769
+ const createApp = initCreateApp();
1770
+ const createPage = initCreatePage(parsePageOptions);
1771
+ const createComponent = initCreateComponent(parseComponentOptions);
1772
+ const createSubpackageApp = initCreateSubpackageApp();
1773
+ tt.EventChannel = EventChannel;
1774
+ tt.createApp = global.createApp = createApp;
1775
+ tt.createPage = createPage;
1776
+ tt.createComponent = createComponent;
1777
+ tt.createSubpackageApp = global.createSubpackageApp =
1778
+ createSubpackageApp;
1779
+
1780
+ export { UTSJSONObject$1 as UTSJSONObject, UniError, createApp, createComponent, createPage, createSubpackageApp };