@tarojs/shared 4.0.0-canary.8 → 4.0.0

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