@tarojs/shared 4.0.0-beta.1 → 4.0.0-beta.3

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