@tarojs/components-react 4.0.0-beta.87 → 4.0.0-beta.88

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.
Files changed (30) hide show
  1. package/LICENSE +8 -8
  2. package/dist/components/button/index.js.map +1 -1
  3. package/dist/components/icon/index.js.map +1 -1
  4. package/dist/components/image/index.js.map +1 -1
  5. package/dist/components/input/index.js.map +1 -1
  6. package/dist/components/pull-down-refresh/index.js.map +1 -1
  7. package/dist/components/scroll-view/index.js +1 -1
  8. package/dist/components/scroll-view/index.js.map +1 -1
  9. package/dist/components/swiper/index.js +2 -0
  10. package/dist/components/swiper/index.js.map +1 -1
  11. package/dist/components/view/index.js.map +1 -1
  12. package/dist/shared/dist/shared.esm.js +1210 -0
  13. package/dist/shared/dist/shared.esm.js.map +1 -0
  14. package/dist/solid/components/button/index.js.map +1 -1
  15. package/dist/solid/components/icon/index.js.map +1 -1
  16. package/dist/solid/components/image/index.js.map +1 -1
  17. package/dist/solid/components/input/index.js +1 -1
  18. package/dist/solid/components/input/index.js.map +1 -1
  19. package/dist/solid/components/pull-down-refresh/index.js +1 -1
  20. package/dist/solid/components/pull-down-refresh/index.js.map +1 -1
  21. package/dist/solid/components/scroll-view/index.js +1 -1
  22. package/dist/solid/components/scroll-view/index.js.map +1 -1
  23. package/dist/solid/components/swiper/index.js +3 -1
  24. package/dist/solid/components/swiper/index.js.map +1 -1
  25. package/dist/solid/components/view/index.js.map +1 -1
  26. package/dist/solid/shared/dist/shared.esm.js +1210 -0
  27. package/dist/solid/shared/dist/shared.esm.js.map +1 -0
  28. package/dist/solid/utils/index.js.map +1 -1
  29. package/dist/utils/index.js.map +1 -1
  30. package/package.json +19 -10
@@ -0,0 +1,1210 @@
1
+ const DEFAULT_EMPTY_ARRAY = '[]';
2
+ const NO_DEFAULT_VALUE = '';
3
+ const DEFAULT_TRUE = '!0';
4
+ const DEFAULT_FALSE = '!1';
5
+ const touchEvents = {
6
+ bindTouchStart: NO_DEFAULT_VALUE,
7
+ bindTouchMove: NO_DEFAULT_VALUE,
8
+ bindTouchEnd: NO_DEFAULT_VALUE,
9
+ bindTouchCancel: NO_DEFAULT_VALUE,
10
+ bindLongTap: NO_DEFAULT_VALUE
11
+ };
12
+ const animation = {
13
+ animation: NO_DEFAULT_VALUE,
14
+ bindAnimationStart: NO_DEFAULT_VALUE,
15
+ bindAnimationIteration: NO_DEFAULT_VALUE,
16
+ bindAnimationEnd: NO_DEFAULT_VALUE,
17
+ bindTransitionEnd: NO_DEFAULT_VALUE
18
+ };
19
+ function singleQuote(s) {
20
+ return `'${s}'`;
21
+ }
22
+ const View = Object.assign(Object.assign({
23
+ 'hover-class': singleQuote('none'),
24
+ 'hover-stop-propagation': DEFAULT_FALSE,
25
+ 'hover-start-time': '50',
26
+ 'hover-stay-time': '400'
27
+ }, touchEvents), animation);
28
+ const Icon = {
29
+ type: NO_DEFAULT_VALUE,
30
+ size: '23',
31
+ color: NO_DEFAULT_VALUE
32
+ };
33
+ const MapComp = Object.assign({
34
+ longitude: NO_DEFAULT_VALUE,
35
+ latitude: NO_DEFAULT_VALUE,
36
+ scale: '16',
37
+ markers: DEFAULT_EMPTY_ARRAY,
38
+ covers: NO_DEFAULT_VALUE,
39
+ polyline: DEFAULT_EMPTY_ARRAY,
40
+ circles: DEFAULT_EMPTY_ARRAY,
41
+ controls: DEFAULT_EMPTY_ARRAY,
42
+ 'include-points': DEFAULT_EMPTY_ARRAY,
43
+ 'show-location': NO_DEFAULT_VALUE,
44
+ 'layer-style': '1',
45
+ bindMarkerTap: NO_DEFAULT_VALUE,
46
+ bindControlTap: NO_DEFAULT_VALUE,
47
+ bindCalloutTap: NO_DEFAULT_VALUE,
48
+ bindUpdated: NO_DEFAULT_VALUE
49
+ }, touchEvents);
50
+ const Progress = {
51
+ percent: NO_DEFAULT_VALUE,
52
+ 'stroke-width': '6',
53
+ color: singleQuote('#09BB07'),
54
+ activeColor: singleQuote('#09BB07'),
55
+ backgroundColor: singleQuote('#EBEBEB'),
56
+ active: DEFAULT_FALSE,
57
+ 'active-mode': singleQuote('backwards'),
58
+ 'show-info': DEFAULT_FALSE
59
+ };
60
+ const RichText = {
61
+ nodes: DEFAULT_EMPTY_ARRAY
62
+ };
63
+ const Text = Object.assign({
64
+ selectable: DEFAULT_FALSE,
65
+ space: NO_DEFAULT_VALUE,
66
+ decode: DEFAULT_FALSE
67
+ }, touchEvents);
68
+ const Button = Object.assign({
69
+ size: singleQuote('default'),
70
+ type: NO_DEFAULT_VALUE,
71
+ plain: DEFAULT_FALSE,
72
+ disabled: NO_DEFAULT_VALUE,
73
+ loading: DEFAULT_FALSE,
74
+ 'form-type': NO_DEFAULT_VALUE,
75
+ 'open-type': NO_DEFAULT_VALUE,
76
+ 'hover-class': singleQuote('button-hover'),
77
+ 'hover-stop-propagation': DEFAULT_FALSE,
78
+ 'hover-start-time': '20',
79
+ 'hover-stay-time': '70',
80
+ name: NO_DEFAULT_VALUE,
81
+ bindagreeprivacyauthorization: NO_DEFAULT_VALUE
82
+ }, touchEvents);
83
+ const Checkbox = {
84
+ value: NO_DEFAULT_VALUE,
85
+ disabled: NO_DEFAULT_VALUE,
86
+ checked: DEFAULT_FALSE,
87
+ color: singleQuote('#09BB07'),
88
+ name: NO_DEFAULT_VALUE
89
+ };
90
+ const CheckboxGroup = {
91
+ bindChange: NO_DEFAULT_VALUE,
92
+ name: NO_DEFAULT_VALUE
93
+ };
94
+ const Form = {
95
+ 'report-submit': DEFAULT_FALSE,
96
+ bindSubmit: NO_DEFAULT_VALUE,
97
+ bindReset: NO_DEFAULT_VALUE,
98
+ name: NO_DEFAULT_VALUE
99
+ };
100
+ const Input = {
101
+ value: NO_DEFAULT_VALUE,
102
+ type: singleQuote(NO_DEFAULT_VALUE),
103
+ password: DEFAULT_FALSE,
104
+ placeholder: NO_DEFAULT_VALUE,
105
+ 'placeholder-style': NO_DEFAULT_VALUE,
106
+ 'placeholder-class': singleQuote('input-placeholder'),
107
+ disabled: NO_DEFAULT_VALUE,
108
+ maxlength: '140',
109
+ 'cursor-spacing': '0',
110
+ focus: DEFAULT_FALSE,
111
+ 'confirm-type': singleQuote('done'),
112
+ 'confirm-hold': DEFAULT_FALSE,
113
+ cursor: '-1',
114
+ 'selection-start': '-1',
115
+ 'selection-end': '-1',
116
+ bindInput: NO_DEFAULT_VALUE,
117
+ bindFocus: NO_DEFAULT_VALUE,
118
+ bindBlur: NO_DEFAULT_VALUE,
119
+ bindConfirm: NO_DEFAULT_VALUE,
120
+ name: NO_DEFAULT_VALUE
121
+ };
122
+ const Label = Object.assign({
123
+ for: NO_DEFAULT_VALUE,
124
+ name: NO_DEFAULT_VALUE
125
+ }, touchEvents);
126
+ const Picker = {
127
+ mode: singleQuote('selector'),
128
+ disabled: NO_DEFAULT_VALUE,
129
+ range: NO_DEFAULT_VALUE,
130
+ 'range-key': NO_DEFAULT_VALUE,
131
+ value: NO_DEFAULT_VALUE,
132
+ start: NO_DEFAULT_VALUE,
133
+ end: NO_DEFAULT_VALUE,
134
+ fields: singleQuote('day'),
135
+ 'custom-item': NO_DEFAULT_VALUE,
136
+ name: NO_DEFAULT_VALUE,
137
+ bindCancel: NO_DEFAULT_VALUE,
138
+ bindChange: NO_DEFAULT_VALUE,
139
+ bindColumnChange: NO_DEFAULT_VALUE
140
+ };
141
+ const PickerView = {
142
+ value: NO_DEFAULT_VALUE,
143
+ 'indicator-style': NO_DEFAULT_VALUE,
144
+ 'indicator-class': NO_DEFAULT_VALUE,
145
+ 'mask-style': NO_DEFAULT_VALUE,
146
+ 'mask-class': NO_DEFAULT_VALUE,
147
+ bindChange: NO_DEFAULT_VALUE,
148
+ name: NO_DEFAULT_VALUE
149
+ };
150
+ const PickerViewColumn = {
151
+ name: NO_DEFAULT_VALUE
152
+ };
153
+ const Radio = {
154
+ value: NO_DEFAULT_VALUE,
155
+ checked: DEFAULT_FALSE,
156
+ disabled: NO_DEFAULT_VALUE,
157
+ color: singleQuote('#09BB07'),
158
+ name: NO_DEFAULT_VALUE
159
+ };
160
+ const RadioGroup = {
161
+ bindChange: NO_DEFAULT_VALUE,
162
+ name: NO_DEFAULT_VALUE
163
+ };
164
+ const Slider = {
165
+ min: '0',
166
+ max: '100',
167
+ step: '1',
168
+ disabled: NO_DEFAULT_VALUE,
169
+ value: '0',
170
+ activeColor: singleQuote('#1aad19'),
171
+ backgroundColor: singleQuote('#e9e9e9'),
172
+ 'block-size': '28',
173
+ 'block-color': singleQuote('#ffffff'),
174
+ 'show-value': DEFAULT_FALSE,
175
+ bindChange: NO_DEFAULT_VALUE,
176
+ bindChanging: NO_DEFAULT_VALUE,
177
+ name: NO_DEFAULT_VALUE
178
+ };
179
+ const Switch = {
180
+ checked: DEFAULT_FALSE,
181
+ disabled: NO_DEFAULT_VALUE,
182
+ type: singleQuote('switch'),
183
+ color: singleQuote('#04BE02'),
184
+ bindChange: NO_DEFAULT_VALUE,
185
+ name: NO_DEFAULT_VALUE
186
+ };
187
+ const Textarea = {
188
+ value: NO_DEFAULT_VALUE,
189
+ placeholder: NO_DEFAULT_VALUE,
190
+ 'placeholder-style': NO_DEFAULT_VALUE,
191
+ 'placeholder-class': singleQuote('textarea-placeholder'),
192
+ disabled: NO_DEFAULT_VALUE,
193
+ maxlength: '140',
194
+ 'auto-focus': DEFAULT_FALSE,
195
+ focus: DEFAULT_FALSE,
196
+ 'auto-height': DEFAULT_FALSE,
197
+ fixed: DEFAULT_FALSE,
198
+ 'cursor-spacing': '0',
199
+ cursor: '-1',
200
+ 'selection-start': '-1',
201
+ 'selection-end': '-1',
202
+ bindFocus: NO_DEFAULT_VALUE,
203
+ bindBlur: NO_DEFAULT_VALUE,
204
+ bindLineChange: NO_DEFAULT_VALUE,
205
+ bindInput: NO_DEFAULT_VALUE,
206
+ bindConfirm: NO_DEFAULT_VALUE,
207
+ name: NO_DEFAULT_VALUE
208
+ };
209
+ const CoverImage = {
210
+ src: NO_DEFAULT_VALUE,
211
+ bindLoad: 'eh',
212
+ bindError: 'eh'
213
+ };
214
+ const CoverView = Object.assign({
215
+ 'scroll-top': DEFAULT_FALSE
216
+ }, touchEvents);
217
+ const MovableArea = {
218
+ 'scale-area': DEFAULT_FALSE
219
+ };
220
+ const MovableView = Object.assign(Object.assign({
221
+ direction: 'none',
222
+ inertia: DEFAULT_FALSE,
223
+ 'out-of-bounds': DEFAULT_FALSE,
224
+ x: NO_DEFAULT_VALUE,
225
+ y: NO_DEFAULT_VALUE,
226
+ damping: '20',
227
+ friction: '2',
228
+ disabled: NO_DEFAULT_VALUE,
229
+ scale: DEFAULT_FALSE,
230
+ 'scale-min': '0.5',
231
+ 'scale-max': '10',
232
+ 'scale-value': '1',
233
+ bindChange: NO_DEFAULT_VALUE,
234
+ bindScale: NO_DEFAULT_VALUE,
235
+ bindHTouchMove: NO_DEFAULT_VALUE,
236
+ bindVTouchMove: NO_DEFAULT_VALUE,
237
+ width: singleQuote('10px'),
238
+ height: singleQuote('10px')
239
+ }, touchEvents), animation);
240
+ const ScrollView = Object.assign(Object.assign({
241
+ 'scroll-x': DEFAULT_FALSE,
242
+ 'scroll-y': DEFAULT_FALSE,
243
+ 'upper-threshold': '50',
244
+ 'lower-threshold': '50',
245
+ 'scroll-top': NO_DEFAULT_VALUE,
246
+ 'scroll-left': NO_DEFAULT_VALUE,
247
+ 'scroll-into-view': NO_DEFAULT_VALUE,
248
+ 'scroll-with-animation': DEFAULT_FALSE,
249
+ 'enable-back-to-top': DEFAULT_FALSE,
250
+ bindScrollToUpper: NO_DEFAULT_VALUE,
251
+ bindScrollToLower: NO_DEFAULT_VALUE,
252
+ bindScroll: NO_DEFAULT_VALUE
253
+ }, touchEvents), animation);
254
+ const Swiper = Object.assign({
255
+ 'indicator-dots': DEFAULT_FALSE,
256
+ 'indicator-color': singleQuote('rgba(0, 0, 0, .3)'),
257
+ 'indicator-active-color': singleQuote('#000000'),
258
+ autoplay: DEFAULT_FALSE,
259
+ current: '0',
260
+ interval: '5000',
261
+ duration: '500',
262
+ circular: DEFAULT_FALSE,
263
+ vertical: DEFAULT_FALSE,
264
+ 'previous-margin': singleQuote('0px'),
265
+ 'next-margin': singleQuote('0px'),
266
+ 'display-multiple-items': '1',
267
+ bindChange: NO_DEFAULT_VALUE,
268
+ bindTransition: NO_DEFAULT_VALUE,
269
+ bindAnimationFinish: NO_DEFAULT_VALUE
270
+ }, touchEvents);
271
+ const SwiperItem = {
272
+ 'item-id': NO_DEFAULT_VALUE
273
+ };
274
+ const Navigator = {
275
+ url: NO_DEFAULT_VALUE,
276
+ 'open-type': singleQuote('navigate'),
277
+ delta: '1',
278
+ 'hover-class': singleQuote('navigator-hover'),
279
+ 'hover-stop-propagation': DEFAULT_FALSE,
280
+ 'hover-start-time': '50',
281
+ 'hover-stay-time': '600',
282
+ bindSuccess: NO_DEFAULT_VALUE,
283
+ bindFail: NO_DEFAULT_VALUE,
284
+ bindComplete: NO_DEFAULT_VALUE
285
+ };
286
+ const Audio = {
287
+ id: NO_DEFAULT_VALUE,
288
+ src: NO_DEFAULT_VALUE,
289
+ loop: DEFAULT_FALSE,
290
+ controls: DEFAULT_FALSE,
291
+ poster: NO_DEFAULT_VALUE,
292
+ name: NO_DEFAULT_VALUE,
293
+ author: NO_DEFAULT_VALUE,
294
+ bindError: NO_DEFAULT_VALUE,
295
+ bindPlay: NO_DEFAULT_VALUE,
296
+ bindPause: NO_DEFAULT_VALUE,
297
+ bindTimeUpdate: NO_DEFAULT_VALUE,
298
+ bindEnded: NO_DEFAULT_VALUE
299
+ };
300
+ const Camera = {
301
+ 'device-position': singleQuote('back'),
302
+ flash: singleQuote('auto'),
303
+ bindStop: NO_DEFAULT_VALUE,
304
+ bindError: NO_DEFAULT_VALUE
305
+ };
306
+ const Image = Object.assign({
307
+ src: NO_DEFAULT_VALUE,
308
+ mode: singleQuote('scaleToFill'),
309
+ 'lazy-load': DEFAULT_FALSE,
310
+ bindError: NO_DEFAULT_VALUE,
311
+ bindLoad: NO_DEFAULT_VALUE
312
+ }, touchEvents);
313
+ const LivePlayer = Object.assign({
314
+ src: NO_DEFAULT_VALUE,
315
+ autoplay: DEFAULT_FALSE,
316
+ muted: DEFAULT_FALSE,
317
+ orientation: singleQuote('vertical'),
318
+ 'object-fit': singleQuote('contain'),
319
+ 'background-mute': DEFAULT_FALSE,
320
+ 'min-cache': '1',
321
+ 'max-cache': '3',
322
+ bindStateChange: NO_DEFAULT_VALUE,
323
+ bindFullScreenChange: NO_DEFAULT_VALUE,
324
+ bindNetStatus: NO_DEFAULT_VALUE
325
+ }, animation);
326
+ const Video = Object.assign({
327
+ src: NO_DEFAULT_VALUE,
328
+ duration: NO_DEFAULT_VALUE,
329
+ controls: DEFAULT_TRUE,
330
+ 'danmu-list': NO_DEFAULT_VALUE,
331
+ 'danmu-btn': NO_DEFAULT_VALUE,
332
+ 'enable-danmu': NO_DEFAULT_VALUE,
333
+ autoplay: DEFAULT_FALSE,
334
+ loop: DEFAULT_FALSE,
335
+ muted: DEFAULT_FALSE,
336
+ 'initial-time': '0',
337
+ 'page-gesture': DEFAULT_FALSE,
338
+ direction: NO_DEFAULT_VALUE,
339
+ 'show-progress': DEFAULT_TRUE,
340
+ 'show-fullscreen-btn': DEFAULT_TRUE,
341
+ 'show-play-btn': DEFAULT_TRUE,
342
+ 'show-center-play-btn': DEFAULT_TRUE,
343
+ 'enable-progress-gesture': DEFAULT_TRUE,
344
+ 'object-fit': singleQuote('contain'),
345
+ poster: NO_DEFAULT_VALUE,
346
+ 'show-mute-btn': DEFAULT_FALSE,
347
+ bindPlay: NO_DEFAULT_VALUE,
348
+ bindPause: NO_DEFAULT_VALUE,
349
+ bindEnded: NO_DEFAULT_VALUE,
350
+ bindTimeUpdate: NO_DEFAULT_VALUE,
351
+ bindFullScreenChange: NO_DEFAULT_VALUE,
352
+ bindWaiting: NO_DEFAULT_VALUE,
353
+ bindError: NO_DEFAULT_VALUE
354
+ }, animation);
355
+ const Canvas = Object.assign({
356
+ 'canvas-id': NO_DEFAULT_VALUE,
357
+ 'disable-scroll': DEFAULT_FALSE,
358
+ bindError: NO_DEFAULT_VALUE
359
+ }, touchEvents);
360
+ const Ad = {
361
+ 'unit-id': NO_DEFAULT_VALUE,
362
+ 'ad-intervals': NO_DEFAULT_VALUE,
363
+ bindLoad: NO_DEFAULT_VALUE,
364
+ bindError: NO_DEFAULT_VALUE,
365
+ bindClose: NO_DEFAULT_VALUE
366
+ };
367
+ const WebView = {
368
+ src: NO_DEFAULT_VALUE,
369
+ bindMessage: NO_DEFAULT_VALUE,
370
+ bindLoad: NO_DEFAULT_VALUE,
371
+ bindError: NO_DEFAULT_VALUE
372
+ };
373
+ const Block = {};
374
+ // For Vue,因为 slot 标签被 vue 占用了
375
+ const SlotView = {
376
+ name: NO_DEFAULT_VALUE
377
+ };
378
+ // For React
379
+ // Slot 和 SlotView 最终都会编译成 <view slot={{ i.name }} />
380
+ // 因为 <slot name="{{ i.name }}" /> 适用性没有前者高(无法添加类和样式)
381
+ // 不给 View 直接加 slot 属性的原因是性能损耗
382
+ const Slot = {
383
+ name: NO_DEFAULT_VALUE
384
+ };
385
+ const NativeSlot = {
386
+ name: NO_DEFAULT_VALUE
387
+ };
388
+ const Script = {};
389
+ const internalComponents = {
390
+ View,
391
+ Icon,
392
+ Progress,
393
+ RichText,
394
+ Text,
395
+ Button,
396
+ Checkbox,
397
+ CheckboxGroup,
398
+ Form,
399
+ Input,
400
+ Label,
401
+ Picker,
402
+ PickerView,
403
+ PickerViewColumn,
404
+ Radio,
405
+ RadioGroup,
406
+ Slider,
407
+ Switch,
408
+ CoverImage,
409
+ Textarea,
410
+ CoverView,
411
+ MovableArea,
412
+ MovableView,
413
+ ScrollView,
414
+ Swiper,
415
+ SwiperItem,
416
+ Navigator,
417
+ Audio,
418
+ Camera,
419
+ Image,
420
+ LivePlayer,
421
+ Video,
422
+ Canvas,
423
+ Ad,
424
+ WebView,
425
+ Block,
426
+ Map: MapComp,
427
+ Slot,
428
+ SlotView,
429
+ NativeSlot,
430
+ Script
431
+ };
432
+ const controlledComponent = new Set(['input', 'checkbox', 'picker', 'picker-view', 'radio', 'slider', 'switch', 'textarea']);
433
+ const focusComponents = new Set(['input', 'textarea']);
434
+ const voidElements = new Set(['progress', 'icon', 'rich-text', 'input', 'textarea', 'slider', 'switch', 'audio', 'ad', 'official-account', 'open-data', 'navigation-bar']);
435
+ const nestElements = new Map([['view', -1], ['catch-view', -1], ['cover-view', -1], ['static-view', -1], ['pure-view', -1], ['block', -1], ['text', -1], ['static-text', 6], ['slot', 8], ['slot-view', 8], ['label', 6], ['form', 4], ['scroll-view', 4], ['swiper', 4], ['swiper-item', 4]]);
436
+ var PLATFORM_TYPE;
437
+ (function (PLATFORM_TYPE) {
438
+ PLATFORM_TYPE["MINI"] = "mini";
439
+ PLATFORM_TYPE["WEB"] = "web";
440
+ PLATFORM_TYPE["RN"] = "rn";
441
+ PLATFORM_TYPE["HARMONY"] = "harmony";
442
+ PLATFORM_TYPE["QUICK"] = "quickapp";
443
+ })(PLATFORM_TYPE || (PLATFORM_TYPE = {}));
444
+ const PLATFORM_CONFIG_MAP = {
445
+ h5: {
446
+ type: PLATFORM_TYPE.WEB
447
+ },
448
+ harmony: {
449
+ type: PLATFORM_TYPE.HARMONY
450
+ },
451
+ mini: {
452
+ type: PLATFORM_TYPE.MINI
453
+ },
454
+ rn: {
455
+ type: PLATFORM_TYPE.RN
456
+ },
457
+ quickapp: {
458
+ type: PLATFORM_TYPE.QUICK
459
+ }
460
+ };
461
+ class Events {
462
+ constructor(opts) {
463
+ var _a;
464
+ this.callbacks = (_a = opts === null || opts === void 0 ? void 0 : opts.callbacks) !== null && _a !== void 0 ? _a : {};
465
+ }
466
+ on(eventName, callback, context) {
467
+ let event, tail, _eventName;
468
+ if (!callback) {
469
+ return this;
470
+ }
471
+ if (typeof eventName === 'symbol') {
472
+ _eventName = [eventName];
473
+ } else {
474
+ _eventName = eventName.split(Events.eventSplitter);
475
+ }
476
+ this.callbacks || (this.callbacks = {});
477
+ const calls = this.callbacks;
478
+ while (event = _eventName.shift()) {
479
+ const list = calls[event];
480
+ const node = list ? list.tail : {};
481
+ node.next = tail = {};
482
+ node.context = context;
483
+ node.callback = callback;
484
+ calls[event] = {
485
+ tail,
486
+ next: list ? list.next : node
487
+ };
488
+ }
489
+ return this;
490
+ }
491
+ once(events, callback, context) {
492
+ var _this = this;
493
+ const wrapper = function () {
494
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
495
+ args[_key] = arguments[_key];
496
+ }
497
+ callback.apply(_this, args);
498
+ _this.off(events, wrapper, context);
499
+ };
500
+ this.on(events, wrapper, context);
501
+ return this;
502
+ }
503
+ off(events, callback, context) {
504
+ let event, calls, _events;
505
+ if (!(calls = this.callbacks)) {
506
+ return this;
507
+ }
508
+ if (!(events || callback || context)) {
509
+ delete this.callbacks;
510
+ return this;
511
+ }
512
+ if (typeof events === 'symbol') {
513
+ _events = [events];
514
+ } else {
515
+ _events = events ? events.split(Events.eventSplitter) : Object.keys(calls);
516
+ }
517
+ while (event = _events.shift()) {
518
+ let node = calls[event];
519
+ delete calls[event];
520
+ if (!node || !(callback || context)) {
521
+ continue;
522
+ }
523
+ const tail = node.tail;
524
+ while ((node = node.next) !== tail) {
525
+ const cb = node.callback;
526
+ const ctx = node.context;
527
+ if (callback && cb !== callback || context && ctx !== context) {
528
+ this.on(event, cb, ctx);
529
+ }
530
+ }
531
+ }
532
+ return this;
533
+ }
534
+ trigger(events) {
535
+ let event, node, calls, _events;
536
+ if (!(calls = this.callbacks)) {
537
+ return this;
538
+ }
539
+ if (typeof events === 'symbol') {
540
+ _events = [events];
541
+ } else {
542
+ _events = events.split(Events.eventSplitter);
543
+ }
544
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
545
+ args[_key2 - 1] = arguments[_key2];
546
+ }
547
+ while (event = _events.shift()) {
548
+ if (node = calls[event]) {
549
+ const tail = node.tail;
550
+ while ((node = node.next) !== tail) {
551
+ node.callback.apply(node.context || this, args);
552
+ }
553
+ }
554
+ }
555
+ return this;
556
+ }
557
+ }
558
+ Events.eventSplitter = ','; // Note: Harmony ACE API 8 开发板不支持使用正则 split 字符串 /\s+/
559
+
560
+ class PageEvts extends Events {
561
+ constructor() {
562
+ super(...arguments);
563
+ this.exeList = [];
564
+ }
565
+ on(eventName, callback) {
566
+ super.on(eventName, callback, this);
567
+ this.exeList = this.exeList.reduce((prev, item) => {
568
+ if (item.eventName === eventName) {
569
+ super.trigger(item.eventName, item.data);
570
+ } else {
571
+ prev.push(item);
572
+ }
573
+ return prev;
574
+ }, []);
575
+ return this;
576
+ }
577
+ emit(events, data) {
578
+ // eslint-disable-next-line
579
+ routeChannel.trigger(events, data);
580
+ }
581
+ }
582
+ const pageChannel = new PageEvts();
583
+ class RouteEvts extends Events {
584
+ emit(events, data) {
585
+ pageChannel.off(events);
586
+ pageChannel.exeList.push({
587
+ eventName: events,
588
+ data
589
+ });
590
+ }
591
+ addEvents(events) {
592
+ if (!events || typeof events !== 'object') return;
593
+ Object.keys(events).forEach(key => {
594
+ this.off(key);
595
+ this.on(key, events[key], this);
596
+ });
597
+ }
598
+ }
599
+ const routeChannel = new RouteEvts();
600
+ const EventChannel = {
601
+ pageChannel,
602
+ routeChannel
603
+ };
604
+ function isString(o) {
605
+ return typeof o === 'string';
606
+ }
607
+ function isUndefined(o) {
608
+ return typeof o === 'undefined';
609
+ }
610
+ function isNull(o) {
611
+ return o === null;
612
+ }
613
+ function isObject(o) {
614
+ return o !== null && typeof o === 'object';
615
+ }
616
+ function isBoolean(o) {
617
+ return o === true || o === false;
618
+ }
619
+ function isFunction(o) {
620
+ return typeof o === 'function';
621
+ }
622
+ function isNumber(o) {
623
+ return typeof o === 'number';
624
+ }
625
+ function isBooleanStringLiteral(o) {
626
+ return o === 'true' || o === 'false';
627
+ }
628
+ const isArray = Array.isArray;
629
+ const isWebPlatform = () => process.env.TARO_ENV === 'h5' || process.env.TARO_PLATFORM === 'web';
630
+ var HOOK_TYPE;
631
+ (function (HOOK_TYPE) {
632
+ HOOK_TYPE[HOOK_TYPE["SINGLE"] = 0] = "SINGLE";
633
+ HOOK_TYPE[HOOK_TYPE["MULTI"] = 1] = "MULTI";
634
+ HOOK_TYPE[HOOK_TYPE["WATERFALL"] = 2] = "WATERFALL";
635
+ })(HOOK_TYPE || (HOOK_TYPE = {}));
636
+ const defaultMiniLifecycle = {
637
+ app: ['onLaunch', 'onShow', 'onHide'],
638
+ page: ['onLoad', 'onUnload', 'onReady', 'onShow', 'onHide', ['onPullDownRefresh', 'onReachBottom', 'onPageScroll', 'onResize', 'defer:onTabItemTap', 'onTitleClick', 'onOptionMenuClick', 'onPopMenuClick', 'onPullIntercept', 'onAddToFavorites'], ['onShareAppMessage', 'onShareTimeline']],
639
+ component: ['attached', 'detached']
640
+ };
641
+ function TaroHook(type, initial) {
642
+ return {
643
+ type,
644
+ initial: initial || null
645
+ };
646
+ }
647
+ class TaroHooks extends Events {
648
+ constructor(hooks, opts) {
649
+ super(opts);
650
+ this.hooks = hooks;
651
+ for (const hookName in hooks) {
652
+ const {
653
+ initial
654
+ } = hooks[hookName];
655
+ if (isFunction(initial)) {
656
+ this.on(hookName, initial);
657
+ }
658
+ }
659
+ }
660
+ tapOneOrMany(hookName, callback) {
661
+ const list = isFunction(callback) ? [callback] : callback;
662
+ list.forEach(cb => this.on(hookName, cb));
663
+ }
664
+ tap(hookName, callback) {
665
+ const hooks = this.hooks;
666
+ const {
667
+ type,
668
+ initial
669
+ } = hooks[hookName];
670
+ if (type === HOOK_TYPE.SINGLE) {
671
+ this.off(hookName);
672
+ this.on(hookName, isFunction(callback) ? callback : callback[callback.length - 1]);
673
+ } else {
674
+ initial && this.off(hookName, initial);
675
+ this.tapOneOrMany(hookName, callback);
676
+ }
677
+ }
678
+ call(hookName) {
679
+ var _a;
680
+ const hook = this.hooks[hookName];
681
+ if (!hook) return;
682
+ const {
683
+ type
684
+ } = hook;
685
+ const calls = this.callbacks;
686
+ if (!calls) return;
687
+ const list = calls[hookName];
688
+ if (list) {
689
+ const tail = list.tail;
690
+ let node = list.next;
691
+ for (var _len3 = arguments.length, rest = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
692
+ rest[_key3 - 1] = arguments[_key3];
693
+ }
694
+ let args = rest;
695
+ let res;
696
+ while (node !== tail) {
697
+ res = (_a = node.callback) === null || _a === void 0 ? void 0 : _a.apply(node.context || this, args);
698
+ if (type === HOOK_TYPE.WATERFALL) {
699
+ const params = [res];
700
+ args = params;
701
+ }
702
+ node = node.next;
703
+ }
704
+ return res;
705
+ }
706
+ }
707
+ isExist(hookName) {
708
+ var _a;
709
+ return Boolean((_a = this.callbacks) === null || _a === void 0 ? void 0 : _a[hookName]);
710
+ }
711
+ }
712
+ const hooks = new TaroHooks({
713
+ getMiniLifecycle: TaroHook(HOOK_TYPE.SINGLE, defaultConfig => defaultConfig),
714
+ getMiniLifecycleImpl: TaroHook(HOOK_TYPE.SINGLE, function () {
715
+ return this.call('getMiniLifecycle', defaultMiniLifecycle);
716
+ }),
717
+ getLifecycle: TaroHook(HOOK_TYPE.SINGLE, (instance, lifecycle) => instance[lifecycle]),
718
+ modifyRecursiveComponentConfig: TaroHook(HOOK_TYPE.SINGLE, defaultConfig => defaultConfig),
719
+ getPathIndex: TaroHook(HOOK_TYPE.SINGLE, indexOfNode => `[${indexOfNode}]`),
720
+ getEventCenter: TaroHook(HOOK_TYPE.SINGLE, Events => new Events()),
721
+ isBubbleEvents: TaroHook(HOOK_TYPE.SINGLE, eventName => {
722
+ /**
723
+ * 支持冒泡的事件, 除 支付宝小程序外,其余的可冒泡事件都和微信保持一致
724
+ * 详见 见 https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxml/event.html
725
+ */
726
+ const BUBBLE_EVENTS = new Set(['touchstart', 'touchmove', 'touchcancel', 'touchend', 'touchforcechange', 'tap', 'longpress', 'longtap', 'transitionend', 'animationstart', 'animationiteration', 'animationend']);
727
+ return BUBBLE_EVENTS.has(eventName);
728
+ }),
729
+ getSpecialNodes: TaroHook(HOOK_TYPE.SINGLE, () => ['view', 'text', 'image']),
730
+ onRemoveAttribute: TaroHook(HOOK_TYPE.SINGLE),
731
+ batchedEventUpdates: TaroHook(HOOK_TYPE.SINGLE),
732
+ mergePageInstance: TaroHook(HOOK_TYPE.SINGLE),
733
+ modifyPageObject: TaroHook(HOOK_TYPE.SINGLE),
734
+ createPullDownComponent: TaroHook(HOOK_TYPE.SINGLE),
735
+ getDOMNode: TaroHook(HOOK_TYPE.SINGLE),
736
+ modifyHydrateData: TaroHook(HOOK_TYPE.SINGLE),
737
+ transferHydrateData: TaroHook(HOOK_TYPE.SINGLE),
738
+ modifySetAttrPayload: TaroHook(HOOK_TYPE.SINGLE),
739
+ modifyRmAttrPayload: TaroHook(HOOK_TYPE.SINGLE),
740
+ onAddEvent: TaroHook(HOOK_TYPE.SINGLE),
741
+ proxyToRaw: TaroHook(HOOK_TYPE.SINGLE, function (proxyObj) {
742
+ return proxyObj;
743
+ }),
744
+ modifyMpEvent: TaroHook(HOOK_TYPE.MULTI),
745
+ modifyMpEventImpl: TaroHook(HOOK_TYPE.SINGLE, function (e) {
746
+ try {
747
+ // 有些小程序的事件对象的某些属性只读
748
+ this.call('modifyMpEvent', e);
749
+ } catch (error) {
750
+ console.warn('[Taro modifyMpEvent hook Error]: ' + (error === null || error === void 0 ? void 0 : error.message));
751
+ }
752
+ }),
753
+ injectNewStyleProperties: TaroHook(HOOK_TYPE.SINGLE),
754
+ modifyTaroEvent: TaroHook(HOOK_TYPE.MULTI),
755
+ dispatchTaroEvent: TaroHook(HOOK_TYPE.SINGLE, (e, node) => {
756
+ node.dispatchEvent(e);
757
+ }),
758
+ dispatchTaroEventFinish: TaroHook(HOOK_TYPE.MULTI),
759
+ modifyTaroEventReturn: TaroHook(HOOK_TYPE.SINGLE, () => undefined),
760
+ modifyDispatchEvent: TaroHook(HOOK_TYPE.MULTI),
761
+ initNativeApi: TaroHook(HOOK_TYPE.MULTI),
762
+ patchElement: TaroHook(HOOK_TYPE.MULTI),
763
+ modifyAddEventListener: TaroHook(HOOK_TYPE.SINGLE),
764
+ modifyRemoveEventListener: TaroHook(HOOK_TYPE.SINGLE),
765
+ getMemoryLevel: TaroHook(HOOK_TYPE.SINGLE)
766
+ });
767
+ const EMPTY_OBJ = {};
768
+ const EMPTY_ARR = [];
769
+ const noop = function () {};
770
+ /**
771
+ * box creates a boxed value.
772
+ *
773
+ * @typeparam T Value type.
774
+ * @param v Value.
775
+ * @returns Boxed value.
776
+ */
777
+ const box = v => ({
778
+ v
779
+ });
780
+ /**
781
+ * box creates a boxed value.
782
+ *
783
+ * @typeparam T Value type.
784
+ * @param b Boxed value.
785
+ * @returns Value.
786
+ */
787
+ const unbox = b => b.v;
788
+ function toDashed(s) {
789
+ return s.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
790
+ }
791
+ function toCamelCase(s) {
792
+ let camel = '';
793
+ let nextCap = false;
794
+ for (let i = 0; i < s.length; i++) {
795
+ if (s[i] !== '-') {
796
+ camel += nextCap ? s[i].toUpperCase() : s[i];
797
+ nextCap = false;
798
+ } else {
799
+ nextCap = true;
800
+ }
801
+ }
802
+ return camel;
803
+ }
804
+ const toKebabCase = function (string) {
805
+ return string.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
806
+ };
807
+ function capitalize(s) {
808
+ return s.charAt(0).toUpperCase() + s.slice(1);
809
+ }
810
+ const hasOwnProperty = Object.prototype.hasOwnProperty;
811
+ const hasOwn = (val, key) => hasOwnProperty.call(val, key);
812
+ /**
813
+ * ensure takes a condition and throw a error if the condition fails,
814
+ * like failure::ensure: https://docs.rs/failure/0.1.1/failure/macro.ensure.html
815
+ * @param condition condition.
816
+ * @param msg error message.
817
+ */
818
+ function ensure(condition, msg) {
819
+ if (!condition) {
820
+ if (process.env.NODE_ENV !== 'production') {
821
+ const reportIssue = '\n如有疑问,请提交 issue 至:https://github.com/nervjs/taro/issues';
822
+ throw new Error(msg + reportIssue);
823
+ } else {
824
+ throw new Error(msg);
825
+ }
826
+ }
827
+ }
828
+ function warn(condition, msg) {
829
+ if (process.env.NODE_ENV !== 'production') {
830
+ if (condition) {
831
+ console.warn(`[taro warn] ${msg}`);
832
+ }
833
+ }
834
+ }
835
+ function queryToJson(str) {
836
+ const dec = decodeURIComponent;
837
+ const qp = str.split('&');
838
+ const ret = {};
839
+ let name;
840
+ let val;
841
+ for (let i = 0, l = qp.length, item; i < l; ++i) {
842
+ item = qp[i];
843
+ if (item.length) {
844
+ const s = item.indexOf('=');
845
+ if (s < 0) {
846
+ name = dec(item);
847
+ val = '';
848
+ } else {
849
+ name = dec(item.slice(0, s));
850
+ val = dec(item.slice(s + 1));
851
+ }
852
+ if (typeof ret[name] === 'string') {
853
+ // inline'd type check
854
+ ret[name] = [ret[name]];
855
+ }
856
+ if (Array.isArray(ret[name])) {
857
+ ret[name].push(val);
858
+ } else {
859
+ ret[name] = val;
860
+ }
861
+ }
862
+ }
863
+ return ret; // Object
864
+ }
865
+
866
+ let _uniqueId = 1;
867
+ const _loadTime = new Date().getTime().toString();
868
+ function getUniqueKey() {
869
+ return _loadTime + _uniqueId++;
870
+ }
871
+ const cacheData = {};
872
+ function cacheDataSet(key, val) {
873
+ cacheData[key] = val;
874
+ }
875
+ function cacheDataGet(key, delelteAfterGet) {
876
+ const temp = cacheData[key];
877
+ delelteAfterGet && delete cacheData[key];
878
+ return temp;
879
+ }
880
+ function cacheDataHas(key) {
881
+ return key in cacheData;
882
+ }
883
+ function mergeInternalComponents(components) {
884
+ Object.keys(components).forEach(name => {
885
+ if (name in internalComponents) {
886
+ Object.assign(internalComponents[name], components[name]);
887
+ } else {
888
+ internalComponents[name] = components[name];
889
+ }
890
+ });
891
+ return internalComponents;
892
+ }
893
+ function getComponentsAlias(origin) {
894
+ const mapping = {};
895
+ const viewAttrs = origin.View;
896
+ const extraList = {
897
+ '#text': {},
898
+ StaticView: viewAttrs,
899
+ StaticImage: origin.Image,
900
+ StaticText: origin.Text,
901
+ PureView: viewAttrs,
902
+ CatchView: viewAttrs
903
+ };
904
+ origin = Object.assign(Object.assign({}, origin), extraList);
905
+ Object.keys(origin).sort((a, b) => {
906
+ const reg = /^(Static|Pure|Catch)*(View|Image|Text)$/;
907
+ const isACommonly = reg.test(a);
908
+ const isBCommonly = reg.test(b);
909
+ if (isACommonly && isBCommonly) {
910
+ return a > b ? 1 : -1;
911
+ } else if (isACommonly) {
912
+ return -1;
913
+ } else if (isBCommonly) {
914
+ return 1;
915
+ } else {
916
+ return a >= b ? 1 : -1;
917
+ }
918
+ }).forEach((key, num) => {
919
+ const obj = {
920
+ _num: String(num)
921
+ };
922
+ Object.keys(origin[key]).filter(attr => !/^bind/.test(attr) && !['focus', 'blur'].includes(attr)).sort().forEach((attr, index) => {
923
+ obj[toCamelCase(attr)] = 'p' + index;
924
+ });
925
+ mapping[toDashed(key)] = obj;
926
+ });
927
+ return mapping;
928
+ }
929
+ function getPlatformType() {
930
+ let platform = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'weapp';
931
+ let configNameOrType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : PLATFORM_TYPE.MINI;
932
+ if (Object.keys(PLATFORM_CONFIG_MAP).includes(platform)) {
933
+ configNameOrType = platform;
934
+ }
935
+ const param = PLATFORM_CONFIG_MAP[configNameOrType] || {};
936
+ return param.type || configNameOrType;
937
+ }
938
+ function mergeReconciler(hostConfig, hooksForTest) {
939
+ const obj = hooksForTest || hooks;
940
+ const keys = Object.keys(hostConfig);
941
+ keys.forEach(key => {
942
+ obj.tap(key, hostConfig[key]);
943
+ });
944
+ }
945
+ function nonsupport(api) {
946
+ return function () {
947
+ console.warn(`小程序暂不支持 ${api}`);
948
+ };
949
+ }
950
+ function setUniqueKeyToRoute(key, obj) {
951
+ const routerParamsPrivateKey = '__key_';
952
+ const useDataCacheApis = ['navigateTo', 'redirectTo', 'reLaunch', 'switchTab'];
953
+ if (useDataCacheApis.indexOf(key) > -1) {
954
+ const url = obj.url = obj.url || '';
955
+ const hasMark = url.indexOf('?') > -1;
956
+ const cacheKey = getUniqueKey();
957
+ obj.url += (hasMark ? '&' : '?') + `${routerParamsPrivateKey}=${cacheKey}`;
958
+ }
959
+ }
960
+ function indent(str, size) {
961
+ return str.split('\n').map((line, index) => {
962
+ const indent = index === 0 ? '' : Array(size).fill(' ').join('');
963
+ return indent + line;
964
+ }).join('\n');
965
+ }
966
+ const needPromiseApis = new Set(['addPhoneContact', 'authorize', 'canvasGetImageData', 'canvasPutImageData', 'canvasToTempFilePath', 'checkSession', 'chooseAddress', 'chooseImage', 'chooseInvoiceTitle', 'chooseLocation', 'chooseVideo', 'clearStorage', 'closeBLEConnection', 'closeBluetoothAdapter', 'closeSocket', 'compressImage', 'connectSocket', 'createBLEConnection', 'downloadFile', 'exitMiniProgram', 'getAvailableAudioSources', 'getBLEDeviceCharacteristics', 'getBLEDeviceServices', 'getBatteryInfo', 'getBeacons', 'getBluetoothAdapterState', 'getBluetoothDevices', 'getClipboardData', 'getConnectedBluetoothDevices', 'getConnectedWifi', 'getExtConfig', 'getFileInfo', 'getImageInfo', 'getLocation', 'getNetworkType', 'getSavedFileInfo', 'getSavedFileList', 'getScreenBrightness', 'getSetting', 'getStorage', 'getStorageInfo', 'getSystemInfo', 'getUserInfo', 'getWifiList', 'hideHomeButton', 'hideShareMenu', 'hideTabBar', 'hideTabBarRedDot', 'loadFontFace', 'login', 'makePhoneCall', 'navigateBack', 'navigateBackMiniProgram', 'navigateTo', 'navigateToBookshelf', 'navigateToMiniProgram', 'notifyBLECharacteristicValueChange', 'hideKeyboard', 'hideLoading', 'hideNavigationBarLoading', 'hideToast', 'openBluetoothAdapter', 'openDocument', 'openLocation', 'openSetting', 'pageScrollTo', 'previewImage', 'queryBookshelf', 'reLaunch', 'readBLECharacteristicValue', 'redirectTo', 'removeSavedFile', 'removeStorage', 'removeTabBarBadge', 'requestSubscribeMessage', 'saveFile', 'saveImageToPhotosAlbum', 'saveVideoToPhotosAlbum', 'scanCode', 'sendSocketMessage', 'setBackgroundColor', 'setBackgroundTextStyle', 'setClipboardData', 'setEnableDebug', 'setInnerAudioOption', 'setKeepScreenOn', 'setNavigationBarColor', 'setNavigationBarTitle', 'setScreenBrightness', 'setStorage', 'setTabBarBadge', 'setTabBarItem', 'setTabBarStyle', 'showActionSheet', 'showFavoriteGuide', 'showLoading', 'showModal', 'showShareMenu', 'showTabBar', 'showTabBarRedDot', 'showToast', 'startBeaconDiscovery', 'startBluetoothDevicesDiscovery', 'startDeviceMotionListening', 'startPullDownRefresh', 'stopBeaconDiscovery', 'stopBluetoothDevicesDiscovery', 'stopCompass', 'startCompass', 'startAccelerometer', 'stopAccelerometer', 'showNavigationBarLoading', 'stopDeviceMotionListening', 'stopPullDownRefresh', 'switchTab', 'uploadFile', 'vibrateLong', 'vibrateShort', 'writeBLECharacteristicValue']);
967
+ function getCanIUseWebp(taro) {
968
+ return function () {
969
+ var _a;
970
+ const res = (_a = taro.getSystemInfoSync) === null || _a === void 0 ? void 0 : _a.call(taro);
971
+ if (!res) {
972
+ if (process.env.NODE_ENV !== 'production') {
973
+ console.error('不支持 API canIUseWebp');
974
+ }
975
+ return false;
976
+ }
977
+ const {
978
+ platform
979
+ } = res;
980
+ const platformLower = platform.toLowerCase();
981
+ if (platformLower === 'android' || platformLower === 'devtools') {
982
+ return true;
983
+ }
984
+ return false;
985
+ };
986
+ }
987
+ function getNormalRequest(global) {
988
+ return function request(options) {
989
+ options = options ? isString(options) ? {
990
+ url: options
991
+ } : options : {};
992
+ const originSuccess = options.success;
993
+ const originFail = options.fail;
994
+ const originComplete = options.complete;
995
+ let requestTask;
996
+ const p = new Promise((resolve, reject) => {
997
+ options.success = res => {
998
+ originSuccess && originSuccess(res);
999
+ resolve(res);
1000
+ };
1001
+ options.fail = res => {
1002
+ originFail && originFail(res);
1003
+ reject(res);
1004
+ };
1005
+ options.complete = res => {
1006
+ originComplete && originComplete(res);
1007
+ };
1008
+ requestTask = global.request(options);
1009
+ });
1010
+ equipTaskMethodsIntoPromise(requestTask, p);
1011
+ p.abort = cb => {
1012
+ cb && cb();
1013
+ if (requestTask) {
1014
+ requestTask.abort();
1015
+ }
1016
+ return p;
1017
+ };
1018
+ return p;
1019
+ };
1020
+ }
1021
+ function processApis(taro, global) {
1022
+ let config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1023
+ const patchNeedPromiseApis = config.needPromiseApis || [];
1024
+ const _needPromiseApis = new Set([...patchNeedPromiseApis, ...needPromiseApis]);
1025
+ const preserved = ['getEnv', 'interceptors', 'Current', 'getCurrentInstance', 'options', 'nextTick', 'eventCenter', 'Events', 'preload', 'webpackJsonp'];
1026
+ const apis = new Set(!config.isOnlyPromisify ? Object.keys(global).filter(api => preserved.indexOf(api) === -1) : patchNeedPromiseApis);
1027
+ if (config.modifyApis) {
1028
+ config.modifyApis(apis);
1029
+ }
1030
+ apis.forEach(key => {
1031
+ if (_needPromiseApis.has(key)) {
1032
+ const originKey = key;
1033
+ taro[originKey] = function () {
1034
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1035
+ for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
1036
+ args[_key4 - 1] = arguments[_key4];
1037
+ }
1038
+ let key = originKey;
1039
+ // 第一个参数 options 为字符串,单独处理
1040
+ if (typeof options === 'string') {
1041
+ if (args.length) {
1042
+ return global[key](options, ...args);
1043
+ }
1044
+ return global[key](options);
1045
+ }
1046
+ // 改变 key 或 option 字段,如需要把支付宝标准的字段对齐微信标准的字段
1047
+ if (config.transformMeta) {
1048
+ const transformResult = config.transformMeta(key, options);
1049
+ key = transformResult.key;
1050
+ options = transformResult.options;
1051
+ // 新 key 可能不存在
1052
+ if (!global.hasOwnProperty(key)) {
1053
+ return nonsupport(key)();
1054
+ }
1055
+ }
1056
+ let task = null;
1057
+ const obj = Object.assign({}, options);
1058
+ // 为页面跳转相关的 API 设置一个随机数作为路由参数。为了给 runtime 区分页面。
1059
+ setUniqueKeyToRoute(key, options);
1060
+ // Promise 化
1061
+ const p = new Promise((resolve, reject) => {
1062
+ obj.success = res => {
1063
+ var _a, _b;
1064
+ (_a = config.modifyAsyncResult) === null || _a === void 0 ? void 0 : _a.call(config, key, res);
1065
+ (_b = options.success) === null || _b === void 0 ? void 0 : _b.call(options, res);
1066
+ if (key === 'connectSocket') {
1067
+ resolve(Promise.resolve().then(() => task ? Object.assign(task, res) : res));
1068
+ } else {
1069
+ resolve(res);
1070
+ }
1071
+ };
1072
+ obj.fail = res => {
1073
+ var _a;
1074
+ (_a = options.fail) === null || _a === void 0 ? void 0 : _a.call(options, res);
1075
+ reject(res);
1076
+ };
1077
+ obj.complete = res => {
1078
+ var _a;
1079
+ (_a = options.complete) === null || _a === void 0 ? void 0 : _a.call(options, res);
1080
+ };
1081
+ if (args.length) {
1082
+ task = global[key](obj, ...args);
1083
+ } else {
1084
+ task = global[key](obj);
1085
+ }
1086
+ });
1087
+ // 给 promise 对象挂载属性
1088
+ if (['uploadFile', 'downloadFile'].includes(key)) {
1089
+ equipTaskMethodsIntoPromise(task, p);
1090
+ p.progress = cb => {
1091
+ task === null || task === void 0 ? void 0 : task.onProgressUpdate(cb);
1092
+ return p;
1093
+ };
1094
+ p.abort = cb => {
1095
+ cb === null || cb === void 0 ? void 0 : cb();
1096
+ task === null || task === void 0 ? void 0 : task.abort();
1097
+ return p;
1098
+ };
1099
+ }
1100
+ return p;
1101
+ };
1102
+ } else {
1103
+ let platformKey = key;
1104
+ // 改变 key 或 option 字段,如需要把支付宝标准的字段对齐微信标准的字段
1105
+ if (config.transformMeta) {
1106
+ platformKey = config.transformMeta(key, {}).key;
1107
+ }
1108
+ // API 不存在
1109
+ if (!global.hasOwnProperty(platformKey)) {
1110
+ taro[key] = nonsupport(key);
1111
+ return;
1112
+ }
1113
+ if (isFunction(global[key])) {
1114
+ taro[key] = function () {
1115
+ for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
1116
+ args[_key5] = arguments[_key5];
1117
+ }
1118
+ if (config.handleSyncApis) {
1119
+ return config.handleSyncApis(key, global, args);
1120
+ } else {
1121
+ return global[platformKey].apply(global, args);
1122
+ }
1123
+ };
1124
+ } else {
1125
+ taro[key] = global[platformKey];
1126
+ }
1127
+ }
1128
+ });
1129
+ !config.isOnlyPromisify && equipCommonApis(taro, global, config);
1130
+ }
1131
+ /**
1132
+ * 挂载常用 API
1133
+ * @param taro Taro 对象
1134
+ * @param global 小程序全局对象,如微信的 wx,支付宝的 my
1135
+ */
1136
+ function equipCommonApis(taro, global) {
1137
+ let apis = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1138
+ taro.canIUseWebp = getCanIUseWebp(taro);
1139
+ taro.getCurrentPages = getCurrentPages || nonsupport('getCurrentPages');
1140
+ taro.getApp = getApp || nonsupport('getApp');
1141
+ taro.env = global.env || {};
1142
+ try {
1143
+ taro.requirePlugin = requirePlugin || nonsupport('requirePlugin');
1144
+ } catch (error) {
1145
+ taro.requirePlugin = nonsupport('requirePlugin');
1146
+ }
1147
+ // request & interceptors
1148
+ const request = apis.request || getNormalRequest(global);
1149
+ function taroInterceptor(chain) {
1150
+ return request(chain.requestParams);
1151
+ }
1152
+ const link = new taro.Link(taroInterceptor);
1153
+ taro.request = link.request.bind(link);
1154
+ taro.addInterceptor = link.addInterceptor.bind(link);
1155
+ taro.cleanInterceptors = link.cleanInterceptors.bind(link);
1156
+ taro.miniGlobal = taro.options.miniGlobal = global;
1157
+ taro.getAppInfo = function () {
1158
+ return {
1159
+ platform: process.env.TARO_PLATFORM || 'MiniProgram',
1160
+ taroVersion: process.env.TARO_VERSION || 'unknown',
1161
+ designWidth: taro.config.designWidth
1162
+ };
1163
+ };
1164
+ taro.createSelectorQuery = delayRef(taro, global, 'createSelectorQuery', 'exec');
1165
+ taro.createIntersectionObserver = delayRef(taro, global, 'createIntersectionObserver', 'observe');
1166
+ }
1167
+ /**
1168
+ * 将Task对象中的方法挂载到promise对象中,适配小程序api原生返回结果
1169
+ * @param task Task对象 {RequestTask | DownloadTask | UploadTask}
1170
+ * @param promise Promise
1171
+ */
1172
+ function equipTaskMethodsIntoPromise(task, promise) {
1173
+ if (!task || !promise) return;
1174
+ const taskMethods = ['abort', 'onHeadersReceived', 'offHeadersReceived', 'onProgressUpdate', 'offProgressUpdate', 'onChunkReceived', 'offChunkReceived'];
1175
+ task && taskMethods.forEach(method => {
1176
+ if (method in task) {
1177
+ promise[method] = task[method].bind(task);
1178
+ }
1179
+ });
1180
+ }
1181
+ function delayRef(taro, global, name, method) {
1182
+ return function () {
1183
+ const res = global[name](...arguments);
1184
+ const raw = res[method].bind(res);
1185
+ res[method] = function () {
1186
+ for (var _len6 = arguments.length, methodArgs = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
1187
+ methodArgs[_key6] = arguments[_key6];
1188
+ }
1189
+ taro.nextTick(() => raw(...methodArgs));
1190
+ };
1191
+ return res;
1192
+ };
1193
+ }
1194
+
1195
+ // 字符串简写
1196
+ var Shortcuts;
1197
+ (function (Shortcuts) {
1198
+ Shortcuts["Container"] = "container";
1199
+ Shortcuts["Childnodes"] = "cn";
1200
+ Shortcuts["Text"] = "v";
1201
+ Shortcuts["NodeType"] = "nt";
1202
+ Shortcuts["NodeName"] = "nn";
1203
+ // Attrtibutes
1204
+ Shortcuts["Style"] = "st";
1205
+ Shortcuts["Class"] = "cl";
1206
+ Shortcuts["Src"] = "src";
1207
+ })(Shortcuts || (Shortcuts = {}));
1208
+
1209
+ export { EMPTY_ARR, EMPTY_OBJ, EventChannel, Events, HOOK_TYPE, PLATFORM_CONFIG_MAP, PLATFORM_TYPE, Shortcuts, TaroHook, TaroHooks, animation, box, cacheDataGet, cacheDataHas, cacheDataSet, capitalize, controlledComponent, ensure, focusComponents, getComponentsAlias, getPlatformType, getUniqueKey, hasOwn, hooks, indent, internalComponents, isArray, isBoolean, isBooleanStringLiteral, isFunction, isNull, isNumber, isObject, isString, isUndefined, isWebPlatform, mergeInternalComponents, mergeReconciler, nestElements, nonsupport, noop, processApis, queryToJson, setUniqueKeyToRoute, singleQuote, toCamelCase, toDashed, toKebabCase, touchEvents, unbox, voidElements, warn };
1210
+ //# sourceMappingURL=shared.esm.js.map