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