@tarojs/shared 3.5.0-beta.2 → 3.5.0-beta.5

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
@@ -2,1103 +2,1140 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const DEFAULT_EMPTY_ARRAY = '[]';
6
- const NO_DEFAULT_VALUE = '';
7
- const DEFAULT_TRUE = 'true';
8
- const DEFAULT_FALSE = 'false';
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 }, 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: 'i.value.length',
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 internalComponents = {
255
- View,
256
- Icon,
257
- Progress,
258
- RichText,
259
- Text,
260
- Button,
261
- Checkbox,
262
- CheckboxGroup,
263
- Form,
264
- Input,
265
- Label,
266
- Picker,
267
- PickerView,
268
- PickerViewColumn,
269
- Radio,
270
- RadioGroup,
271
- Slider,
272
- Switch,
273
- CoverImage,
274
- Textarea,
275
- CoverView,
276
- MovableArea,
277
- MovableView,
278
- ScrollView,
279
- Swiper,
280
- SwiperItem,
281
- Navigator,
282
- Audio,
283
- Camera,
284
- Image,
285
- LivePlayer,
286
- Video,
287
- Canvas,
288
- Ad,
289
- WebView,
290
- Block,
291
- Map: MapComp,
292
- Slot,
293
- SlotView
294
- };
295
- const controlledComponent = new Set([
296
- 'input',
297
- 'checkbox',
298
- 'picker',
299
- 'picker-view',
300
- 'radio',
301
- 'slider',
302
- 'switch',
303
- 'textarea'
304
- ]);
305
- const focusComponents = new Set([
306
- 'input',
307
- 'textarea'
308
- ]);
309
- const voidElements = new Set([
310
- 'progress',
311
- 'icon',
312
- 'rich-text',
313
- 'input',
314
- 'textarea',
315
- 'slider',
316
- 'switch',
317
- 'audio',
318
- 'ad',
319
- 'official-account',
320
- 'open-data',
321
- 'navigation-bar'
322
- ]);
323
- const nestElements = new Map([
324
- ['view', -1],
325
- ['catch-view', -1],
326
- ['cover-view', -1],
327
- ['static-view', -1],
328
- ['pure-view', -1],
329
- ['block', -1],
330
- ['text', -1],
331
- ['static-text', 6],
332
- ['slot', 8],
333
- ['slot-view', 8],
334
- ['label', 6],
335
- ['form', 4],
336
- ['scroll-view', 4],
337
- ['swiper', 4],
338
- ['swiper-item', 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 }, 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: 'i.value.length',
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 internalComponents = {
255
+ View,
256
+ Icon,
257
+ Progress,
258
+ RichText,
259
+ Text,
260
+ Button,
261
+ Checkbox,
262
+ CheckboxGroup,
263
+ Form,
264
+ Input,
265
+ Label,
266
+ Picker,
267
+ PickerView,
268
+ PickerViewColumn,
269
+ Radio,
270
+ RadioGroup,
271
+ Slider,
272
+ Switch,
273
+ CoverImage,
274
+ Textarea,
275
+ CoverView,
276
+ MovableArea,
277
+ MovableView,
278
+ ScrollView,
279
+ Swiper,
280
+ SwiperItem,
281
+ Navigator,
282
+ Audio,
283
+ Camera,
284
+ Image,
285
+ LivePlayer,
286
+ Video,
287
+ Canvas,
288
+ Ad,
289
+ WebView,
290
+ Block,
291
+ Map: MapComp,
292
+ Slot,
293
+ SlotView
294
+ };
295
+ const controlledComponent = new Set([
296
+ 'input',
297
+ 'checkbox',
298
+ 'picker',
299
+ 'picker-view',
300
+ 'radio',
301
+ 'slider',
302
+ 'switch',
303
+ 'textarea'
304
+ ]);
305
+ const focusComponents = new Set([
306
+ 'input',
307
+ 'textarea'
308
+ ]);
309
+ const voidElements = new Set([
310
+ 'progress',
311
+ 'icon',
312
+ 'rich-text',
313
+ 'input',
314
+ 'textarea',
315
+ 'slider',
316
+ 'switch',
317
+ 'audio',
318
+ 'ad',
319
+ 'official-account',
320
+ 'open-data',
321
+ 'navigation-bar'
322
+ ]);
323
+ const nestElements = new Map([
324
+ ['view', -1],
325
+ ['catch-view', -1],
326
+ ['cover-view', -1],
327
+ ['static-view', -1],
328
+ ['pure-view', -1],
329
+ ['block', -1],
330
+ ['text', -1],
331
+ ['static-text', 6],
332
+ ['slot', 8],
333
+ ['slot-view', 8],
334
+ ['label', 6],
335
+ ['form', 4],
336
+ ['scroll-view', 4],
337
+ ['swiper', 4],
338
+ ['swiper-item', 4]
339
339
  ]);
340
340
 
341
- class Events {
342
- constructor(opts) {
343
- var _a;
344
- this.callbacks = (_a = opts === null || opts === void 0 ? void 0 : opts.callbacks) !== null && _a !== void 0 ? _a : {};
345
- }
346
- on(eventName, callback, context) {
347
- let event, node, tail, list;
348
- if (!callback) {
349
- return this;
350
- }
351
- eventName = eventName.split(Events.eventSplitter);
352
- this.callbacks || (this.callbacks = {});
353
- const calls = this.callbacks;
354
- while ((event = eventName.shift())) {
355
- list = calls[event];
356
- node = list ? list.tail : {};
357
- node.next = tail = {};
358
- node.context = context;
359
- node.callback = callback;
360
- calls[event] = {
361
- tail,
362
- next: list ? list.next : node
363
- };
364
- }
365
- return this;
366
- }
367
- once(events, callback, context) {
368
- const wrapper = (...args) => {
369
- callback.apply(this, args);
370
- this.off(events, wrapper, context);
371
- };
372
- this.on(events, wrapper, context);
373
- return this;
374
- }
375
- off(events, callback, context) {
376
- let event, calls, node, tail, cb, ctx;
377
- if (!(calls = this.callbacks)) {
378
- return this;
379
- }
380
- if (!(events || callback || context)) {
381
- delete this.callbacks;
382
- return this;
383
- }
384
- events = events ? events.split(Events.eventSplitter) : Object.keys(calls);
385
- while ((event = events.shift())) {
386
- node = calls[event];
387
- delete calls[event];
388
- if (!node || !(callback || context)) {
389
- continue;
390
- }
391
- tail = node.tail;
392
- while ((node = node.next) !== tail) {
393
- cb = node.callback;
394
- ctx = node.context;
395
- if ((callback && cb !== callback) || (context && ctx !== context)) {
396
- this.on(event, cb, ctx);
397
- }
398
- }
399
- }
400
- return this;
401
- }
402
- trigger(events) {
403
- let event, node, calls, tail;
404
- if (!(calls = this.callbacks)) {
405
- return this;
406
- }
407
- events = events.split(Events.eventSplitter);
408
- const rest = [].slice.call(arguments, 1);
409
- while ((event = events.shift())) {
410
- if ((node = calls[event])) {
411
- tail = node.tail;
412
- while ((node = node.next) !== tail) {
413
- node.callback.apply(node.context || this, rest);
414
- }
415
- }
416
- }
417
- return this;
418
- }
419
- }
341
+ class Events {
342
+ constructor(opts) {
343
+ var _a;
344
+ this.callbacks = (_a = opts === null || opts === void 0 ? void 0 : opts.callbacks) !== null && _a !== void 0 ? _a : {};
345
+ }
346
+ on(eventName, callback, context) {
347
+ let event, node, tail, list;
348
+ if (!callback) {
349
+ return this;
350
+ }
351
+ eventName = eventName.split(Events.eventSplitter);
352
+ this.callbacks || (this.callbacks = {});
353
+ const calls = this.callbacks;
354
+ while ((event = eventName.shift())) {
355
+ list = calls[event];
356
+ node = list ? list.tail : {};
357
+ node.next = tail = {};
358
+ node.context = context;
359
+ node.callback = callback;
360
+ calls[event] = {
361
+ tail,
362
+ next: list ? list.next : node
363
+ };
364
+ }
365
+ return this;
366
+ }
367
+ once(events, callback, context) {
368
+ const wrapper = (...args) => {
369
+ callback.apply(this, args);
370
+ this.off(events, wrapper, context);
371
+ };
372
+ this.on(events, wrapper, context);
373
+ return this;
374
+ }
375
+ off(events, callback, context) {
376
+ let event, calls, node, tail, cb, ctx;
377
+ if (!(calls = this.callbacks)) {
378
+ return this;
379
+ }
380
+ if (!(events || callback || context)) {
381
+ delete this.callbacks;
382
+ return this;
383
+ }
384
+ events = events ? events.split(Events.eventSplitter) : Object.keys(calls);
385
+ while ((event = events.shift())) {
386
+ node = calls[event];
387
+ delete calls[event];
388
+ if (!node || !(callback || context)) {
389
+ continue;
390
+ }
391
+ tail = node.tail;
392
+ while ((node = node.next) !== tail) {
393
+ cb = node.callback;
394
+ ctx = node.context;
395
+ if ((callback && cb !== callback) || (context && ctx !== context)) {
396
+ this.on(event, cb, ctx);
397
+ }
398
+ }
399
+ }
400
+ return this;
401
+ }
402
+ trigger(events) {
403
+ let event, node, calls, tail;
404
+ if (!(calls = this.callbacks)) {
405
+ return this;
406
+ }
407
+ events = events.split(Events.eventSplitter);
408
+ const rest = [].slice.call(arguments, 1);
409
+ while ((event = events.shift())) {
410
+ if ((node = calls[event])) {
411
+ tail = node.tail;
412
+ while ((node = node.next) !== tail) {
413
+ node.callback.apply(node.context || this, rest);
414
+ }
415
+ }
416
+ }
417
+ return this;
418
+ }
419
+ }
420
420
  Events.eventSplitter = /\s+/;
421
421
 
422
- function isString(o) {
423
- return typeof o === 'string';
424
- }
425
- function isUndefined(o) {
426
- return typeof o === 'undefined';
427
- }
428
- function isNull(o) {
429
- return o === null;
430
- }
431
- function isObject(o) {
432
- return o !== null && typeof o === 'object';
433
- }
434
- function isBoolean(o) {
435
- return o === true || o === false;
436
- }
437
- function isFunction(o) {
438
- return typeof o === 'function';
439
- }
440
- function isNumber(o) {
441
- return typeof o === 'number';
442
- }
443
- function isBooleanStringLiteral(o) {
444
- return o === 'true' || o === 'false';
445
- }
422
+ function isString(o) {
423
+ return typeof o === 'string';
424
+ }
425
+ function isUndefined(o) {
426
+ return typeof o === 'undefined';
427
+ }
428
+ function isNull(o) {
429
+ return o === null;
430
+ }
431
+ function isObject(o) {
432
+ return o !== null && typeof o === 'object';
433
+ }
434
+ function isBoolean(o) {
435
+ return o === true || o === false;
436
+ }
437
+ function isFunction(o) {
438
+ return typeof o === 'function';
439
+ }
440
+ function isNumber(o) {
441
+ return typeof o === 'number';
442
+ }
443
+ function isBooleanStringLiteral(o) {
444
+ return o === 'true' || o === 'false';
445
+ }
446
446
  const isArray = Array.isArray;
447
447
 
448
- exports.HOOK_TYPE = void 0;
449
- (function (HOOK_TYPE) {
450
- HOOK_TYPE[HOOK_TYPE["SINGLE"] = 0] = "SINGLE";
451
- HOOK_TYPE[HOOK_TYPE["MULTI"] = 1] = "MULTI";
452
- HOOK_TYPE[HOOK_TYPE["WATERFALL"] = 2] = "WATERFALL";
453
- })(exports.HOOK_TYPE || (exports.HOOK_TYPE = {}));
454
- const defaultMiniLifecycle = {
455
- app: [
456
- 'onLaunch',
457
- 'onShow',
458
- 'onHide'
459
- ],
460
- page: [
461
- 'onLoad',
462
- 'onUnload',
463
- 'onReady',
464
- 'onShow',
465
- 'onHide',
466
- [
467
- 'onPullDownRefresh',
468
- 'onReachBottom',
469
- 'onPageScroll',
470
- 'onResize',
471
- 'onTabItemTap',
472
- 'onTitleClick',
473
- 'onOptionMenuClick',
474
- 'onPopMenuClick',
475
- 'onPullIntercept',
476
- 'onAddToFavorites'
477
- ]
478
- ]
479
- };
480
- function TaroHook(type, initial) {
481
- return {
482
- type,
483
- initial: initial || null
484
- };
485
- }
486
- class TaroHooks extends Events {
487
- constructor(hooks, opts) {
488
- super(opts);
489
- this.hooks = hooks;
490
- for (const hookName in hooks) {
491
- const { initial } = hooks[hookName];
492
- if (isFunction(initial)) {
493
- this.on(hookName, initial);
494
- }
495
- }
496
- }
497
- tapOneOrMany(hookName, callback) {
498
- const list = isFunction(callback) ? [callback] : callback;
499
- list.forEach(cb => this.on(hookName, cb));
500
- }
501
- tap(hookName, callback) {
502
- const hooks = this.hooks;
503
- const { type, initial } = hooks[hookName];
504
- if (type === exports.HOOK_TYPE.SINGLE) {
505
- this.off(hookName);
506
- this.on(hookName, isFunction(callback) ? callback : callback[callback.length - 1]);
507
- }
508
- else {
509
- initial && this.off(hookName, initial);
510
- this.tapOneOrMany(hookName, callback);
511
- }
512
- }
513
- call(hookName, ...rest) {
514
- var _a;
515
- const hook = this.hooks[hookName];
516
- if (!hook)
517
- return;
518
- const { type } = hook;
519
- const calls = this.callbacks;
520
- if (!calls)
521
- return;
522
- const list = calls[hookName];
523
- if (list) {
524
- const tail = list.tail;
525
- let node = list.next;
526
- let args = rest;
527
- let res;
528
- while (node !== tail) {
529
- res = (_a = node.callback) === null || _a === void 0 ? void 0 : _a.apply(node.context || this, args);
530
- if (type === exports.HOOK_TYPE.WATERFALL) {
531
- const params = [res];
532
- args = params;
533
- }
534
- node = node.next;
535
- }
536
- return res;
537
- }
538
- }
539
- isExist(hookName) {
540
- var _a;
541
- return Boolean((_a = this.callbacks) === null || _a === void 0 ? void 0 : _a[hookName]);
542
- }
543
- }
544
- const hooks = new TaroHooks({
545
- getMiniLifecycle: TaroHook(exports.HOOK_TYPE.SINGLE, defaultConfig => defaultConfig),
546
- getMiniLifecycleImpl: TaroHook(exports.HOOK_TYPE.SINGLE, function () {
547
- return this.call('getMiniLifecycle', defaultMiniLifecycle);
548
- }),
549
- getLifecycle: TaroHook(exports.HOOK_TYPE.SINGLE, (instance, lifecycle) => instance[lifecycle]),
550
- getPathIndex: TaroHook(exports.HOOK_TYPE.SINGLE, indexOfNode => `[${indexOfNode}]`),
551
- getEventCenter: TaroHook(exports.HOOK_TYPE.SINGLE, Events => new Events()),
552
- isBubbleEvents: TaroHook(exports.HOOK_TYPE.SINGLE, eventName => {
553
- /**
554
- * 支持冒泡的事件, 除 支付宝小程序外,其余的可冒泡事件都和微信保持一致
555
- * 详见 见 https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxml/event.html
556
- */
557
- const BUBBLE_EVENTS = new Set([
558
- 'touchstart',
559
- 'touchmove',
560
- 'touchcancel',
561
- 'touchend',
562
- 'touchforcechange',
563
- 'tap',
564
- 'longpress',
565
- 'longtap',
566
- 'transitionend',
567
- 'animationstart',
568
- 'animationiteration',
569
- 'animationend'
570
- ]);
571
- return BUBBLE_EVENTS.has(eventName);
572
- }),
573
- getSpecialNodes: TaroHook(exports.HOOK_TYPE.SINGLE, () => ['view', 'text', 'image']),
574
- onRemoveAttribute: TaroHook(exports.HOOK_TYPE.SINGLE),
575
- batchedEventUpdates: TaroHook(exports.HOOK_TYPE.SINGLE),
576
- mergePageInstance: TaroHook(exports.HOOK_TYPE.SINGLE),
577
- modifyPageObject: TaroHook(exports.HOOK_TYPE.SINGLE),
578
- createPullDownComponent: TaroHook(exports.HOOK_TYPE.SINGLE),
579
- getDOMNode: TaroHook(exports.HOOK_TYPE.SINGLE),
580
- modifyHydrateData: TaroHook(exports.HOOK_TYPE.SINGLE),
581
- modifySetAttrPayload: TaroHook(exports.HOOK_TYPE.SINGLE),
582
- modifyRmAttrPayload: TaroHook(exports.HOOK_TYPE.SINGLE),
583
- onAddEvent: TaroHook(exports.HOOK_TYPE.SINGLE),
584
- modifyMpEvent: TaroHook(exports.HOOK_TYPE.MULTI),
585
- modifyMpEventImpl: TaroHook(exports.HOOK_TYPE.SINGLE, function (e) {
586
- try {
587
- // 有些小程序的事件对象的某些属性只读
588
- this.call('modifyMpEvent', e);
589
- }
590
- catch (error) {
591
- console.warn('[Taro modifyMpEvent hook Error]: ', error);
592
- }
593
- }),
594
- modifyTaroEvent: TaroHook(exports.HOOK_TYPE.MULTI),
595
- modifyDispatchEvent: TaroHook(exports.HOOK_TYPE.MULTI),
596
- initNativeApi: TaroHook(exports.HOOK_TYPE.MULTI),
597
- patchElement: TaroHook(exports.HOOK_TYPE.MULTI)
448
+ exports.HOOK_TYPE = void 0;
449
+ (function (HOOK_TYPE) {
450
+ HOOK_TYPE[HOOK_TYPE["SINGLE"] = 0] = "SINGLE";
451
+ HOOK_TYPE[HOOK_TYPE["MULTI"] = 1] = "MULTI";
452
+ HOOK_TYPE[HOOK_TYPE["WATERFALL"] = 2] = "WATERFALL";
453
+ })(exports.HOOK_TYPE || (exports.HOOK_TYPE = {}));
454
+ const defaultMiniLifecycle = {
455
+ app: [
456
+ 'onLaunch',
457
+ 'onShow',
458
+ 'onHide'
459
+ ],
460
+ page: [
461
+ 'onLoad',
462
+ 'onUnload',
463
+ 'onReady',
464
+ 'onShow',
465
+ 'onHide',
466
+ [
467
+ 'onPullDownRefresh',
468
+ 'onReachBottom',
469
+ 'onPageScroll',
470
+ 'onResize',
471
+ 'onTabItemTap',
472
+ 'onTitleClick',
473
+ 'onOptionMenuClick',
474
+ 'onPopMenuClick',
475
+ 'onPullIntercept',
476
+ 'onAddToFavorites'
477
+ ]
478
+ ]
479
+ };
480
+ function TaroHook(type, initial) {
481
+ return {
482
+ type,
483
+ initial: initial || null
484
+ };
485
+ }
486
+ class TaroHooks extends Events {
487
+ constructor(hooks, opts) {
488
+ super(opts);
489
+ this.hooks = hooks;
490
+ for (const hookName in hooks) {
491
+ const { initial } = hooks[hookName];
492
+ if (isFunction(initial)) {
493
+ this.on(hookName, initial);
494
+ }
495
+ }
496
+ }
497
+ tapOneOrMany(hookName, callback) {
498
+ const list = isFunction(callback) ? [callback] : callback;
499
+ list.forEach(cb => this.on(hookName, cb));
500
+ }
501
+ tap(hookName, callback) {
502
+ const hooks = this.hooks;
503
+ const { type, initial } = hooks[hookName];
504
+ if (type === exports.HOOK_TYPE.SINGLE) {
505
+ this.off(hookName);
506
+ this.on(hookName, isFunction(callback) ? callback : callback[callback.length - 1]);
507
+ }
508
+ else {
509
+ initial && this.off(hookName, initial);
510
+ this.tapOneOrMany(hookName, callback);
511
+ }
512
+ }
513
+ call(hookName, ...rest) {
514
+ var _a;
515
+ const hook = this.hooks[hookName];
516
+ if (!hook)
517
+ return;
518
+ const { type } = hook;
519
+ const calls = this.callbacks;
520
+ if (!calls)
521
+ return;
522
+ const list = calls[hookName];
523
+ if (list) {
524
+ const tail = list.tail;
525
+ let node = list.next;
526
+ let args = rest;
527
+ let res;
528
+ while (node !== tail) {
529
+ res = (_a = node.callback) === null || _a === void 0 ? void 0 : _a.apply(node.context || this, args);
530
+ if (type === exports.HOOK_TYPE.WATERFALL) {
531
+ const params = [res];
532
+ args = params;
533
+ }
534
+ node = node.next;
535
+ }
536
+ return res;
537
+ }
538
+ }
539
+ isExist(hookName) {
540
+ var _a;
541
+ return Boolean((_a = this.callbacks) === null || _a === void 0 ? void 0 : _a[hookName]);
542
+ }
543
+ }
544
+ const hooks = new TaroHooks({
545
+ getMiniLifecycle: TaroHook(exports.HOOK_TYPE.SINGLE, defaultConfig => defaultConfig),
546
+ getMiniLifecycleImpl: TaroHook(exports.HOOK_TYPE.SINGLE, function () {
547
+ return this.call('getMiniLifecycle', defaultMiniLifecycle);
548
+ }),
549
+ getLifecycle: TaroHook(exports.HOOK_TYPE.SINGLE, (instance, lifecycle) => instance[lifecycle]),
550
+ getPathIndex: TaroHook(exports.HOOK_TYPE.SINGLE, indexOfNode => `[${indexOfNode}]`),
551
+ getEventCenter: TaroHook(exports.HOOK_TYPE.SINGLE, Events => new Events()),
552
+ isBubbleEvents: TaroHook(exports.HOOK_TYPE.SINGLE, eventName => {
553
+ /**
554
+ * 支持冒泡的事件, 除 支付宝小程序外,其余的可冒泡事件都和微信保持一致
555
+ * 详见 见 https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxml/event.html
556
+ */
557
+ const BUBBLE_EVENTS = new Set([
558
+ 'touchstart',
559
+ 'touchmove',
560
+ 'touchcancel',
561
+ 'touchend',
562
+ 'touchforcechange',
563
+ 'tap',
564
+ 'longpress',
565
+ 'longtap',
566
+ 'transitionend',
567
+ 'animationstart',
568
+ 'animationiteration',
569
+ 'animationend'
570
+ ]);
571
+ return BUBBLE_EVENTS.has(eventName);
572
+ }),
573
+ getSpecialNodes: TaroHook(exports.HOOK_TYPE.SINGLE, () => ['view', 'text', 'image']),
574
+ onRemoveAttribute: TaroHook(exports.HOOK_TYPE.SINGLE),
575
+ batchedEventUpdates: TaroHook(exports.HOOK_TYPE.SINGLE),
576
+ mergePageInstance: TaroHook(exports.HOOK_TYPE.SINGLE),
577
+ modifyPageObject: TaroHook(exports.HOOK_TYPE.SINGLE),
578
+ createPullDownComponent: TaroHook(exports.HOOK_TYPE.SINGLE),
579
+ getDOMNode: TaroHook(exports.HOOK_TYPE.SINGLE),
580
+ modifyHydrateData: TaroHook(exports.HOOK_TYPE.SINGLE),
581
+ modifySetAttrPayload: TaroHook(exports.HOOK_TYPE.SINGLE),
582
+ modifyRmAttrPayload: TaroHook(exports.HOOK_TYPE.SINGLE),
583
+ onAddEvent: TaroHook(exports.HOOK_TYPE.SINGLE),
584
+ modifyMpEvent: TaroHook(exports.HOOK_TYPE.MULTI),
585
+ modifyMpEventImpl: TaroHook(exports.HOOK_TYPE.SINGLE, function (e) {
586
+ try {
587
+ // 有些小程序的事件对象的某些属性只读
588
+ this.call('modifyMpEvent', e);
589
+ }
590
+ catch (error) {
591
+ console.warn('[Taro modifyMpEvent hook Error]: ', error);
592
+ }
593
+ }),
594
+ modifyTaroEvent: TaroHook(exports.HOOK_TYPE.MULTI),
595
+ modifyDispatchEvent: TaroHook(exports.HOOK_TYPE.MULTI),
596
+ initNativeApi: TaroHook(exports.HOOK_TYPE.MULTI),
597
+ patchElement: TaroHook(exports.HOOK_TYPE.MULTI)
598
598
  });
599
599
 
600
- const EMPTY_OBJ = {};
601
- const EMPTY_ARR = [];
602
- const noop = (..._) => { };
603
- /**
604
- * box creates a boxed value.
605
- *
606
- * @typeparam T Value type.
607
- * @param v Value.
608
- * @returns Boxed value.
609
- */
610
- const box = (v) => ({ v });
611
- /**
612
- * box creates a boxed value.
613
- *
614
- * @typeparam T Value type.
615
- * @param b Boxed value.
616
- * @returns Value.
617
- */
618
- const unbox = (b) => b.v;
619
- function toDashed(s) {
620
- return s.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
621
- }
622
- function toCamelCase(s) {
623
- let camel = '';
624
- let nextCap = false;
625
- for (let i = 0; i < s.length; i++) {
626
- if (s[i] !== '-') {
627
- camel += nextCap ? s[i].toUpperCase() : s[i];
628
- nextCap = false;
629
- }
630
- else {
631
- nextCap = true;
632
- }
633
- }
634
- return camel;
635
- }
636
- const toKebabCase = function (string) {
637
- return string.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
638
- };
639
- function capitalize(s) {
640
- return s.charAt(0).toUpperCase() + s.slice(1);
641
- }
642
- const hasOwnProperty = Object.prototype.hasOwnProperty;
643
- const hasOwn = (val, key) => hasOwnProperty.call(val, key);
644
- /**
645
- * ensure takes a condition and throw a error if the condition fails,
646
- * like failure::ensure: https://docs.rs/failure/0.1.1/failure/macro.ensure.html
647
- * @param condition condition.
648
- * @param msg error message.
649
- */
650
- function ensure(condition, msg) {
651
- if (!condition) {
652
- if (process.env.NODE_ENV !== 'production') {
653
- const reportIssue = '\n如有疑问,请提交 issue 至:https://github.com/nervjs/taro/issues';
654
- throw new Error(msg + reportIssue);
655
- }
656
- else {
657
- throw new Error(msg);
658
- }
659
- }
660
- }
661
- function warn(condition, msg) {
662
- if (process.env.NODE_ENV !== 'production') {
663
- if (condition) {
664
- console.warn(`[taro warn] ${msg}`);
665
- }
666
- }
667
- }
668
- function queryToJson(str) {
669
- const dec = decodeURIComponent;
670
- const qp = str.split('&');
671
- const ret = {};
672
- let name;
673
- let val;
674
- for (let i = 0, l = qp.length, item; i < l; ++i) {
675
- item = qp[i];
676
- if (item.length) {
677
- const s = item.indexOf('=');
678
- if (s < 0) {
679
- name = dec(item);
680
- val = '';
681
- }
682
- else {
683
- name = dec(item.slice(0, s));
684
- val = dec(item.slice(s + 1));
685
- }
686
- if (typeof ret[name] === 'string') { // inline'd type check
687
- ret[name] = [ret[name]];
688
- }
689
- if (Array.isArray(ret[name])) {
690
- ret[name].push(val);
691
- }
692
- else {
693
- ret[name] = val;
694
- }
695
- }
696
- }
697
- return ret; // Object
698
- }
699
- let _uniqueId = 1;
700
- const _loadTime = (new Date()).getTime().toString();
701
- function getUniqueKey() {
702
- return _loadTime + (_uniqueId++);
703
- }
704
- const cacheData = {};
705
- function cacheDataSet(key, val) {
706
- cacheData[key] = val;
707
- }
708
- function cacheDataGet(key, delelteAfterGet) {
709
- const temp = cacheData[key];
710
- delelteAfterGet && delete cacheData[key];
711
- return temp;
712
- }
713
- function cacheDataHas(key) {
714
- return key in cacheData;
715
- }
716
- function mergeInternalComponents(components) {
717
- Object.keys(components).forEach(name => {
718
- if (name in internalComponents) {
719
- Object.assign(internalComponents[name], components[name]);
720
- }
721
- else {
722
- internalComponents[name] = components[name];
723
- }
724
- });
725
- }
726
- function mergeReconciler(hostConfig, hooksForTest) {
727
- const obj = hooksForTest || hooks;
728
- const keys = Object.keys(hostConfig);
729
- keys.forEach(key => {
730
- obj.tap(key, hostConfig[key]);
731
- });
732
- }
733
- function unsupport(api) {
734
- return function () {
735
- console.warn(`小程序暂不支持 ${api}`);
736
- };
737
- }
738
- function setUniqueKeyToRoute(key, obj) {
739
- const routerParamsPrivateKey = '__key_';
740
- const useDataCacheApis = [
741
- 'navigateTo',
742
- 'redirectTo',
743
- 'reLaunch',
744
- 'switchTab'
745
- ];
746
- if (useDataCacheApis.indexOf(key) > -1) {
747
- const url = obj.url = obj.url || '';
748
- const hasMark = url.indexOf('?') > -1;
749
- const cacheKey = getUniqueKey();
750
- obj.url += (hasMark ? '&' : '?') + `${routerParamsPrivateKey}=${cacheKey}`;
751
- }
752
- }
753
- function indent(str, size) {
754
- return str.split('\n')
755
- .map((line, index) => {
756
- const indent = index === 0 ? '' : Array(size).fill(' ').join('');
757
- return indent + line;
758
- })
759
- .join('\n');
600
+ const EMPTY_OBJ = {};
601
+ const EMPTY_ARR = [];
602
+ const noop = (..._) => { };
603
+ /**
604
+ * box creates a boxed value.
605
+ *
606
+ * @typeparam T Value type.
607
+ * @param v Value.
608
+ * @returns Boxed value.
609
+ */
610
+ const box = (v) => ({ v });
611
+ /**
612
+ * box creates a boxed value.
613
+ *
614
+ * @typeparam T Value type.
615
+ * @param b Boxed value.
616
+ * @returns Value.
617
+ */
618
+ const unbox = (b) => b.v;
619
+ function toDashed(s) {
620
+ return s.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
760
621
  }
761
-
762
- const needPromiseApis = new Set([
763
- 'addPhoneContact',
764
- 'authorize',
765
- 'canvasGetImageData',
766
- 'canvasPutImageData',
767
- 'canvasToTempFilePath',
768
- 'checkSession',
769
- 'chooseAddress',
770
- 'chooseImage',
771
- 'chooseInvoiceTitle',
772
- 'chooseLocation',
773
- 'chooseVideo',
774
- 'clearStorage',
775
- 'closeBLEConnection',
776
- 'closeBluetoothAdapter',
777
- 'closeSocket',
778
- 'compressImage',
779
- 'connectSocket',
780
- 'createBLEConnection',
781
- 'downloadFile',
782
- 'exitMiniProgram',
783
- 'getAvailableAudioSources',
784
- 'getBLEDeviceCharacteristics',
785
- 'getBLEDeviceServices',
786
- 'getBatteryInfo',
787
- 'getBeacons',
788
- 'getBluetoothAdapterState',
789
- 'getBluetoothDevices',
790
- 'getClipboardData',
791
- 'getConnectedBluetoothDevices',
792
- 'getConnectedWifi',
793
- 'getExtConfig',
794
- 'getFileInfo',
795
- 'getImageInfo',
796
- 'getLocation',
797
- 'getNetworkType',
798
- 'getSavedFileInfo',
799
- 'getSavedFileList',
800
- 'getScreenBrightness',
801
- 'getSetting',
802
- 'getStorage',
803
- 'getStorageInfo',
804
- 'getSystemInfo',
805
- 'getUserInfo',
806
- 'getWifiList',
807
- 'hideHomeButton',
808
- 'hideShareMenu',
809
- 'hideTabBar',
810
- 'hideTabBarRedDot',
811
- 'loadFontFace',
812
- 'login',
813
- 'makePhoneCall',
814
- 'navigateBack',
815
- 'navigateBackMiniProgram',
816
- 'navigateTo',
817
- 'navigateToBookshelf',
818
- 'navigateToMiniProgram',
819
- 'notifyBLECharacteristicValueChange',
820
- 'hideKeyboard',
821
- 'hideLoading',
822
- 'hideNavigationBarLoading',
823
- 'hideToast',
824
- 'openBluetoothAdapter',
825
- 'openDocument',
826
- 'openLocation',
827
- 'openSetting',
828
- 'pageScrollTo',
829
- 'previewImage',
830
- 'queryBookshelf',
831
- 'reLaunch',
832
- 'readBLECharacteristicValue',
833
- 'redirectTo',
834
- 'removeSavedFile',
835
- 'removeStorage',
836
- 'removeTabBarBadge',
837
- 'requestSubscribeMessage',
838
- 'saveFile',
839
- 'saveImageToPhotosAlbum',
840
- 'saveVideoToPhotosAlbum',
841
- 'scanCode',
842
- 'sendSocketMessage',
843
- 'setBackgroundColor',
844
- 'setBackgroundTextStyle',
845
- 'setClipboardData',
846
- 'setEnableDebug',
847
- 'setInnerAudioOption',
848
- 'setKeepScreenOn',
849
- 'setNavigationBarColor',
850
- 'setNavigationBarTitle',
851
- 'setScreenBrightness',
852
- 'setStorage',
853
- 'setTabBarBadge',
854
- 'setTabBarItem',
855
- 'setTabBarStyle',
856
- 'showActionSheet',
857
- 'showFavoriteGuide',
858
- 'showLoading',
859
- 'showModal',
860
- 'showShareMenu',
861
- 'showTabBar',
862
- 'showTabBarRedDot',
863
- 'showToast',
864
- 'startBeaconDiscovery',
865
- 'startBluetoothDevicesDiscovery',
866
- 'startDeviceMotionListening',
867
- 'startPullDownRefresh',
868
- 'stopBeaconDiscovery',
869
- 'stopBluetoothDevicesDiscovery',
870
- 'stopCompass',
871
- 'startCompass',
872
- 'startAccelerometer',
873
- 'stopAccelerometer',
874
- 'showNavigationBarLoading',
875
- 'stopDeviceMotionListening',
876
- 'stopPullDownRefresh',
877
- 'switchTab',
878
- 'uploadFile',
879
- 'vibrateLong',
880
- 'vibrateShort',
881
- 'writeBLECharacteristicValue'
882
- ]);
883
- function getCanIUseWebp(taro) {
884
- return function () {
885
- var _a;
886
- const res = (_a = taro.getSystemInfoSync) === null || _a === void 0 ? void 0 : _a.call(taro);
887
- if (!res) {
888
- if (process.env.NODE_ENV !== 'production') {
889
- console.error('不支持 API canIUseWebp');
890
- }
891
- return false;
892
- }
893
- const { platform } = res;
894
- const platformLower = platform.toLowerCase();
895
- if (platformLower === 'android' || platformLower === 'devtools') {
896
- return true;
897
- }
898
- return false;
899
- };
900
- }
901
- function getNormalRequest(global) {
902
- return function request(options) {
903
- options = options
904
- ? (isString(options)
905
- ? { url: options }
906
- : options)
907
- : {};
908
- const originSuccess = options.success;
909
- const originFail = options.fail;
910
- const originComplete = options.complete;
911
- let requestTask;
912
- const p = new Promise((resolve, reject) => {
913
- options.success = res => {
914
- originSuccess && originSuccess(res);
915
- resolve(res);
916
- };
917
- options.fail = res => {
918
- originFail && originFail(res);
919
- reject(res);
920
- };
921
- options.complete = res => {
922
- originComplete && originComplete(res);
923
- };
924
- requestTask = global.request(options);
925
- });
926
- p.abort = (cb) => {
927
- cb && cb();
928
- if (requestTask) {
929
- requestTask.abort();
930
- }
931
- return p;
932
- };
933
- return p;
934
- };
935
- }
936
- function processApis(taro, global, config = {}) {
937
- const patchNeedPromiseApis = config.needPromiseApis || [];
938
- const _needPromiseApis = new Set([...patchNeedPromiseApis, ...needPromiseApis]);
939
- const preserved = [
940
- 'getEnv',
941
- 'interceptors',
942
- 'Current',
943
- 'getCurrentInstance',
944
- 'options',
945
- 'nextTick',
946
- 'eventCenter',
947
- 'Events',
948
- 'preload',
949
- 'webpackJsonp'
950
- ];
951
- const apis = new Set(!config.isOnlyPromisify
952
- ? Object.keys(global).filter(api => preserved.indexOf(api) === -1)
953
- : patchNeedPromiseApis);
954
- if (config.modifyApis) {
955
- config.modifyApis(apis);
956
- }
957
- apis.forEach(key => {
958
- if (_needPromiseApis.has(key)) {
959
- const originKey = key;
960
- taro[originKey] = (options = {}, ...args) => {
961
- let key = originKey;
962
- // 第一个参数 options 为字符串,单独处理
963
- if (typeof options === 'string') {
964
- if (args.length) {
965
- return global[key](options, ...args);
966
- }
967
- return global[key](options);
968
- }
969
- // 改变 key 或 option 字段,如需要把支付宝标准的字段对齐微信标准的字段
970
- if (config.transformMeta) {
971
- const transformResult = config.transformMeta(key, options);
972
- key = transformResult.key;
973
- options = transformResult.options;
974
- // 新 key 可能不存在
975
- if (!global.hasOwnProperty(key)) {
976
- return unsupport(key)();
977
- }
978
- }
979
- let task = null;
980
- const obj = Object.assign({}, options);
981
- // 为页面跳转相关的 API 设置一个随机数作为路由参数。为了给 runtime 区分页面。
982
- setUniqueKeyToRoute(key, options);
983
- // Promise 化
984
- const p = new Promise((resolve, reject) => {
985
- obj.success = res => {
986
- var _a, _b;
987
- (_a = config.modifyAsyncResult) === null || _a === void 0 ? void 0 : _a.call(config, key, res);
988
- (_b = options.success) === null || _b === void 0 ? void 0 : _b.call(options, res);
989
- if (key === 'connectSocket') {
990
- resolve(Promise.resolve().then(() => task ? Object.assign(task, res) : res));
991
- }
992
- else {
993
- resolve(res);
994
- }
995
- };
996
- obj.fail = res => {
997
- var _a;
998
- (_a = options.fail) === null || _a === void 0 ? void 0 : _a.call(options, res);
999
- reject(res);
1000
- };
1001
- obj.complete = res => {
1002
- var _a;
1003
- (_a = options.complete) === null || _a === void 0 ? void 0 : _a.call(options, res);
1004
- };
1005
- if (args.length) {
1006
- task = global[key](obj, ...args);
1007
- }
1008
- else {
1009
- task = global[key](obj);
1010
- }
1011
- });
1012
- // 给 promise 对象挂载属性
1013
- if (['request', 'uploadFile', 'downloadFile'].includes(key)) {
1014
- const taskMethods = ['abort', 'onHeadersReceived', 'offHeadersReceived', 'onProgressUpdate', 'offProgressUpdate', 'onChunkReceived', 'offChunkReceived'];
1015
- task && taskMethods.forEach(method => {
1016
- if (method in task) {
1017
- p[method] = task[method].bind(task);
1018
- }
1019
- });
1020
- p.progress = cb => {
1021
- task === null || task === void 0 ? void 0 : task.onProgressUpdate(cb);
1022
- return p;
1023
- };
1024
- p.abort = cb => {
1025
- cb === null || cb === void 0 ? void 0 : cb();
1026
- task === null || task === void 0 ? void 0 : task.abort();
1027
- return p;
1028
- };
1029
- }
1030
- return p;
1031
- };
1032
- }
1033
- else {
1034
- let platformKey = key;
1035
- // 改变 key 或 option 字段,如需要把支付宝标准的字段对齐微信标准的字段
1036
- if (config.transformMeta) {
1037
- platformKey = config.transformMeta(key, {}).key;
1038
- }
1039
- // API 不存在
1040
- if (!global.hasOwnProperty(platformKey)) {
1041
- taro[key] = unsupport(key);
1042
- return;
1043
- }
1044
- if (isFunction(global[key])) {
1045
- taro[key] = (...args) => {
1046
- if (config.handleSyncApis) {
1047
- return config.handleSyncApis(key, global, args);
1048
- }
1049
- else {
1050
- return global[platformKey].apply(global, args);
1051
- }
1052
- };
1053
- }
1054
- else {
1055
- taro[key] = global[platformKey];
1056
- }
1057
- }
1058
- });
1059
- !config.isOnlyPromisify && equipCommonApis(taro, global, config);
1060
- }
1061
- /**
1062
- * 挂载常用 API
1063
- * @param taro Taro 对象
1064
- * @param global 小程序全局对象,如微信的 wx,支付宝的 my
1065
- */
1066
- function equipCommonApis(taro, global, apis = {}) {
1067
- taro.canIUseWebp = getCanIUseWebp(taro);
1068
- taro.getCurrentPages = getCurrentPages || unsupport('getCurrentPages');
1069
- taro.getApp = getApp || unsupport('getApp');
1070
- taro.env = global.env || {};
1071
- try {
1072
- taro.requirePlugin = requirePlugin || unsupport('requirePlugin');
1073
- }
1074
- catch (error) {
1075
- taro.requirePlugin = unsupport('requirePlugin');
1076
- }
1077
- // request & interceptors
1078
- const request = apis.request || getNormalRequest(global);
1079
- function taroInterceptor(chain) {
1080
- return request(chain.requestParams);
1081
- }
1082
- const link = new taro.Link(taroInterceptor);
1083
- taro.request = link.request.bind(link);
1084
- taro.addInterceptor = link.addInterceptor.bind(link);
1085
- taro.cleanInterceptors = link.cleanInterceptors.bind(link);
1086
- taro.miniGlobal = taro.options.miniGlobal = global;
622
+ function toCamelCase(s) {
623
+ let camel = '';
624
+ let nextCap = false;
625
+ for (let i = 0; i < s.length; i++) {
626
+ if (s[i] !== '-') {
627
+ camel += nextCap ? s[i].toUpperCase() : s[i];
628
+ nextCap = false;
629
+ }
630
+ else {
631
+ nextCap = true;
632
+ }
633
+ }
634
+ return camel;
635
+ }
636
+ const toKebabCase = function (string) {
637
+ return string.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
638
+ };
639
+ function capitalize(s) {
640
+ return s.charAt(0).toUpperCase() + s.slice(1);
641
+ }
642
+ const hasOwnProperty = Object.prototype.hasOwnProperty;
643
+ const hasOwn = (val, key) => hasOwnProperty.call(val, key);
644
+ /**
645
+ * ensure takes a condition and throw a error if the condition fails,
646
+ * like failure::ensure: https://docs.rs/failure/0.1.1/failure/macro.ensure.html
647
+ * @param condition condition.
648
+ * @param msg error message.
649
+ */
650
+ function ensure(condition, msg) {
651
+ if (!condition) {
652
+ if (process.env.NODE_ENV !== 'production') {
653
+ const reportIssue = '\n如有疑问,请提交 issue 至:https://github.com/nervjs/taro/issues';
654
+ throw new Error(msg + reportIssue);
655
+ }
656
+ else {
657
+ throw new Error(msg);
658
+ }
659
+ }
660
+ }
661
+ function warn(condition, msg) {
662
+ if (process.env.NODE_ENV !== 'production') {
663
+ if (condition) {
664
+ console.warn(`[taro warn] ${msg}`);
665
+ }
666
+ }
667
+ }
668
+ function queryToJson(str) {
669
+ const dec = decodeURIComponent;
670
+ const qp = str.split('&');
671
+ const ret = {};
672
+ let name;
673
+ let val;
674
+ for (let i = 0, l = qp.length, item; i < l; ++i) {
675
+ item = qp[i];
676
+ if (item.length) {
677
+ const s = item.indexOf('=');
678
+ if (s < 0) {
679
+ name = dec(item);
680
+ val = '';
681
+ }
682
+ else {
683
+ name = dec(item.slice(0, s));
684
+ val = dec(item.slice(s + 1));
685
+ }
686
+ if (typeof ret[name] === 'string') { // inline'd type check
687
+ ret[name] = [ret[name]];
688
+ }
689
+ if (Array.isArray(ret[name])) {
690
+ ret[name].push(val);
691
+ }
692
+ else {
693
+ ret[name] = val;
694
+ }
695
+ }
696
+ }
697
+ return ret; // Object
698
+ }
699
+ let _uniqueId = 1;
700
+ const _loadTime = (new Date()).getTime().toString();
701
+ function getUniqueKey() {
702
+ return _loadTime + (_uniqueId++);
703
+ }
704
+ const cacheData = {};
705
+ function cacheDataSet(key, val) {
706
+ cacheData[key] = val;
707
+ }
708
+ function cacheDataGet(key, delelteAfterGet) {
709
+ const temp = cacheData[key];
710
+ delelteAfterGet && delete cacheData[key];
711
+ return temp;
712
+ }
713
+ function cacheDataHas(key) {
714
+ return key in cacheData;
715
+ }
716
+ function mergeInternalComponents(components) {
717
+ Object.keys(components).forEach(name => {
718
+ if (name in internalComponents) {
719
+ Object.assign(internalComponents[name], components[name]);
720
+ }
721
+ else {
722
+ internalComponents[name] = components[name];
723
+ }
724
+ });
725
+ return internalComponents;
726
+ }
727
+ function getComponentsAlias(origin) {
728
+ const mapping = {};
729
+ const viewAttrs = origin.View;
730
+ const extraList = {
731
+ '#text': {},
732
+ StaticView: viewAttrs,
733
+ StaticImage: origin.Image,
734
+ StaticText: origin.Text,
735
+ PureView: viewAttrs,
736
+ CatchView: viewAttrs
737
+ };
738
+ origin = Object.assign(Object.assign({}, origin), extraList);
739
+ Object.keys(origin)
740
+ .sort((a, b) => {
741
+ const reg = /^(Static|Pure|Catch)*(View|Image|Text)$/;
742
+ if (reg.test(a)) {
743
+ return -1;
744
+ }
745
+ else if (reg.test(b)) {
746
+ return 1;
747
+ }
748
+ else {
749
+ return a >= b ? 1 : -1;
750
+ }
751
+ })
752
+ .forEach((key, num) => {
753
+ const obj = {
754
+ _num: String(num)
755
+ };
756
+ Object.keys(origin[key])
757
+ .filter(attr => !(/^bind/.test(attr)) && !['focus', 'blur'].includes(attr))
758
+ .sort()
759
+ .forEach((attr, index) => {
760
+ obj[toCamelCase(attr)] = 'p' + index;
761
+ });
762
+ mapping[toDashed(key)] = obj;
763
+ });
764
+ return mapping;
765
+ }
766
+ function mergeReconciler(hostConfig, hooksForTest) {
767
+ const obj = hooksForTest || hooks;
768
+ const keys = Object.keys(hostConfig);
769
+ keys.forEach(key => {
770
+ obj.tap(key, hostConfig[key]);
771
+ });
772
+ }
773
+ function nonsupport(api) {
774
+ return function () {
775
+ console.warn(`小程序暂不支持 ${api}`);
776
+ };
777
+ }
778
+ function setUniqueKeyToRoute(key, obj) {
779
+ const routerParamsPrivateKey = '__key_';
780
+ const useDataCacheApis = [
781
+ 'navigateTo',
782
+ 'redirectTo',
783
+ 'reLaunch',
784
+ 'switchTab'
785
+ ];
786
+ if (useDataCacheApis.indexOf(key) > -1) {
787
+ const url = obj.url = obj.url || '';
788
+ const hasMark = url.indexOf('?') > -1;
789
+ const cacheKey = getUniqueKey();
790
+ obj.url += (hasMark ? '&' : '?') + `${routerParamsPrivateKey}=${cacheKey}`;
791
+ }
792
+ }
793
+ function indent(str, size) {
794
+ return str.split('\n')
795
+ .map((line, index) => {
796
+ const indent = index === 0 ? '' : Array(size).fill(' ').join('');
797
+ return indent + line;
798
+ })
799
+ .join('\n');
1087
800
  }
1088
801
 
1089
- // 字符串简写
1090
- exports.Shortcuts = void 0;
1091
- (function (Shortcuts) {
1092
- Shortcuts["Container"] = "container";
1093
- Shortcuts["Childnodes"] = "cn";
1094
- Shortcuts["Text"] = "v";
1095
- Shortcuts["NodeType"] = "nt";
1096
- Shortcuts["NodeName"] = "nn";
1097
- // Attrtibutes
1098
- Shortcuts["Style"] = "st";
1099
- Shortcuts["Class"] = "cl";
1100
- Shortcuts["Src"] = "src";
1101
- })(exports.Shortcuts || (exports.Shortcuts = {}));
802
+ const needPromiseApis = new Set([
803
+ 'addPhoneContact',
804
+ 'authorize',
805
+ 'canvasGetImageData',
806
+ 'canvasPutImageData',
807
+ 'canvasToTempFilePath',
808
+ 'checkSession',
809
+ 'chooseAddress',
810
+ 'chooseImage',
811
+ 'chooseInvoiceTitle',
812
+ 'chooseLocation',
813
+ 'chooseVideo',
814
+ 'clearStorage',
815
+ 'closeBLEConnection',
816
+ 'closeBluetoothAdapter',
817
+ 'closeSocket',
818
+ 'compressImage',
819
+ 'connectSocket',
820
+ 'createBLEConnection',
821
+ 'downloadFile',
822
+ 'exitMiniProgram',
823
+ 'getAvailableAudioSources',
824
+ 'getBLEDeviceCharacteristics',
825
+ 'getBLEDeviceServices',
826
+ 'getBatteryInfo',
827
+ 'getBeacons',
828
+ 'getBluetoothAdapterState',
829
+ 'getBluetoothDevices',
830
+ 'getClipboardData',
831
+ 'getConnectedBluetoothDevices',
832
+ 'getConnectedWifi',
833
+ 'getExtConfig',
834
+ 'getFileInfo',
835
+ 'getImageInfo',
836
+ 'getLocation',
837
+ 'getNetworkType',
838
+ 'getSavedFileInfo',
839
+ 'getSavedFileList',
840
+ 'getScreenBrightness',
841
+ 'getSetting',
842
+ 'getStorage',
843
+ 'getStorageInfo',
844
+ 'getSystemInfo',
845
+ 'getUserInfo',
846
+ 'getWifiList',
847
+ 'hideHomeButton',
848
+ 'hideShareMenu',
849
+ 'hideTabBar',
850
+ 'hideTabBarRedDot',
851
+ 'loadFontFace',
852
+ 'login',
853
+ 'makePhoneCall',
854
+ 'navigateBack',
855
+ 'navigateBackMiniProgram',
856
+ 'navigateTo',
857
+ 'navigateToBookshelf',
858
+ 'navigateToMiniProgram',
859
+ 'notifyBLECharacteristicValueChange',
860
+ 'hideKeyboard',
861
+ 'hideLoading',
862
+ 'hideNavigationBarLoading',
863
+ 'hideToast',
864
+ 'openBluetoothAdapter',
865
+ 'openDocument',
866
+ 'openLocation',
867
+ 'openSetting',
868
+ 'pageScrollTo',
869
+ 'previewImage',
870
+ 'queryBookshelf',
871
+ 'reLaunch',
872
+ 'readBLECharacteristicValue',
873
+ 'redirectTo',
874
+ 'removeSavedFile',
875
+ 'removeStorage',
876
+ 'removeTabBarBadge',
877
+ 'requestSubscribeMessage',
878
+ 'saveFile',
879
+ 'saveImageToPhotosAlbum',
880
+ 'saveVideoToPhotosAlbum',
881
+ 'scanCode',
882
+ 'sendSocketMessage',
883
+ 'setBackgroundColor',
884
+ 'setBackgroundTextStyle',
885
+ 'setClipboardData',
886
+ 'setEnableDebug',
887
+ 'setInnerAudioOption',
888
+ 'setKeepScreenOn',
889
+ 'setNavigationBarColor',
890
+ 'setNavigationBarTitle',
891
+ 'setScreenBrightness',
892
+ 'setStorage',
893
+ 'setTabBarBadge',
894
+ 'setTabBarItem',
895
+ 'setTabBarStyle',
896
+ 'showActionSheet',
897
+ 'showFavoriteGuide',
898
+ 'showLoading',
899
+ 'showModal',
900
+ 'showShareMenu',
901
+ 'showTabBar',
902
+ 'showTabBarRedDot',
903
+ 'showToast',
904
+ 'startBeaconDiscovery',
905
+ 'startBluetoothDevicesDiscovery',
906
+ 'startDeviceMotionListening',
907
+ 'startPullDownRefresh',
908
+ 'stopBeaconDiscovery',
909
+ 'stopBluetoothDevicesDiscovery',
910
+ 'stopCompass',
911
+ 'startCompass',
912
+ 'startAccelerometer',
913
+ 'stopAccelerometer',
914
+ 'showNavigationBarLoading',
915
+ 'stopDeviceMotionListening',
916
+ 'stopPullDownRefresh',
917
+ 'switchTab',
918
+ 'uploadFile',
919
+ 'vibrateLong',
920
+ 'vibrateShort',
921
+ 'writeBLECharacteristicValue'
922
+ ]);
923
+ function getCanIUseWebp(taro) {
924
+ return function () {
925
+ var _a;
926
+ const res = (_a = taro.getSystemInfoSync) === null || _a === void 0 ? void 0 : _a.call(taro);
927
+ if (!res) {
928
+ if (process.env.NODE_ENV !== 'production') {
929
+ console.error('不支持 API canIUseWebp');
930
+ }
931
+ return false;
932
+ }
933
+ const { platform } = res;
934
+ const platformLower = platform.toLowerCase();
935
+ if (platformLower === 'android' || platformLower === 'devtools') {
936
+ return true;
937
+ }
938
+ return false;
939
+ };
940
+ }
941
+ function getNormalRequest(global) {
942
+ return function request(options) {
943
+ options = options
944
+ ? (isString(options)
945
+ ? { url: options }
946
+ : options)
947
+ : {};
948
+ const originSuccess = options.success;
949
+ const originFail = options.fail;
950
+ const originComplete = options.complete;
951
+ let requestTask;
952
+ const p = new Promise((resolve, reject) => {
953
+ options.success = res => {
954
+ originSuccess && originSuccess(res);
955
+ resolve(res);
956
+ };
957
+ options.fail = res => {
958
+ originFail && originFail(res);
959
+ reject(res);
960
+ };
961
+ options.complete = res => {
962
+ originComplete && originComplete(res);
963
+ };
964
+ requestTask = global.request(options);
965
+ });
966
+ equipTaskMethodsIntoPromise(requestTask, p);
967
+ p.abort = (cb) => {
968
+ cb && cb();
969
+ if (requestTask) {
970
+ requestTask.abort();
971
+ }
972
+ return p;
973
+ };
974
+ return p;
975
+ };
976
+ }
977
+ function processApis(taro, global, config = {}) {
978
+ const patchNeedPromiseApis = config.needPromiseApis || [];
979
+ const _needPromiseApis = new Set([...patchNeedPromiseApis, ...needPromiseApis]);
980
+ const preserved = [
981
+ 'getEnv',
982
+ 'interceptors',
983
+ 'Current',
984
+ 'getCurrentInstance',
985
+ 'options',
986
+ 'nextTick',
987
+ 'eventCenter',
988
+ 'Events',
989
+ 'preload',
990
+ 'webpackJsonp'
991
+ ];
992
+ const apis = new Set(!config.isOnlyPromisify
993
+ ? Object.keys(global).filter(api => preserved.indexOf(api) === -1)
994
+ : patchNeedPromiseApis);
995
+ if (config.modifyApis) {
996
+ config.modifyApis(apis);
997
+ }
998
+ apis.forEach(key => {
999
+ if (_needPromiseApis.has(key)) {
1000
+ const originKey = key;
1001
+ taro[originKey] = (options = {}, ...args) => {
1002
+ let key = originKey;
1003
+ // 第一个参数 options 为字符串,单独处理
1004
+ if (typeof options === 'string') {
1005
+ if (args.length) {
1006
+ return global[key](options, ...args);
1007
+ }
1008
+ return global[key](options);
1009
+ }
1010
+ // 改变 key 或 option 字段,如需要把支付宝标准的字段对齐微信标准的字段
1011
+ if (config.transformMeta) {
1012
+ const transformResult = config.transformMeta(key, options);
1013
+ key = transformResult.key;
1014
+ options = transformResult.options;
1015
+ // 新 key 可能不存在
1016
+ if (!global.hasOwnProperty(key)) {
1017
+ return nonsupport(key)();
1018
+ }
1019
+ }
1020
+ let task = null;
1021
+ const obj = Object.assign({}, options);
1022
+ // 为页面跳转相关的 API 设置一个随机数作为路由参数。为了给 runtime 区分页面。
1023
+ setUniqueKeyToRoute(key, options);
1024
+ // Promise 化
1025
+ const p = new Promise((resolve, reject) => {
1026
+ obj.success = res => {
1027
+ var _a, _b;
1028
+ (_a = config.modifyAsyncResult) === null || _a === void 0 ? void 0 : _a.call(config, key, res);
1029
+ (_b = options.success) === null || _b === void 0 ? void 0 : _b.call(options, res);
1030
+ if (key === 'connectSocket') {
1031
+ resolve(Promise.resolve().then(() => task ? Object.assign(task, res) : res));
1032
+ }
1033
+ else {
1034
+ resolve(res);
1035
+ }
1036
+ };
1037
+ obj.fail = res => {
1038
+ var _a;
1039
+ (_a = options.fail) === null || _a === void 0 ? void 0 : _a.call(options, res);
1040
+ reject(res);
1041
+ };
1042
+ obj.complete = res => {
1043
+ var _a;
1044
+ (_a = options.complete) === null || _a === void 0 ? void 0 : _a.call(options, res);
1045
+ };
1046
+ if (args.length) {
1047
+ task = global[key](obj, ...args);
1048
+ }
1049
+ else {
1050
+ task = global[key](obj);
1051
+ }
1052
+ });
1053
+ // 给 promise 对象挂载属性
1054
+ if (['uploadFile', 'downloadFile'].includes(key)) {
1055
+ equipTaskMethodsIntoPromise(task, p);
1056
+ p.progress = cb => {
1057
+ task === null || task === void 0 ? void 0 : task.onProgressUpdate(cb);
1058
+ return p;
1059
+ };
1060
+ p.abort = cb => {
1061
+ cb === null || cb === void 0 ? void 0 : cb();
1062
+ task === null || task === void 0 ? void 0 : task.abort();
1063
+ return p;
1064
+ };
1065
+ }
1066
+ return p;
1067
+ };
1068
+ }
1069
+ else {
1070
+ let platformKey = key;
1071
+ // 改变 key 或 option 字段,如需要把支付宝标准的字段对齐微信标准的字段
1072
+ if (config.transformMeta) {
1073
+ platformKey = config.transformMeta(key, {}).key;
1074
+ }
1075
+ // API 不存在
1076
+ if (!global.hasOwnProperty(platformKey)) {
1077
+ taro[key] = nonsupport(key);
1078
+ return;
1079
+ }
1080
+ if (isFunction(global[key])) {
1081
+ taro[key] = (...args) => {
1082
+ if (config.handleSyncApis) {
1083
+ return config.handleSyncApis(key, global, args);
1084
+ }
1085
+ else {
1086
+ return global[platformKey].apply(global, args);
1087
+ }
1088
+ };
1089
+ }
1090
+ else {
1091
+ taro[key] = global[platformKey];
1092
+ }
1093
+ }
1094
+ });
1095
+ !config.isOnlyPromisify && equipCommonApis(taro, global, config);
1096
+ }
1097
+ /**
1098
+ * 挂载常用 API
1099
+ * @param taro Taro 对象
1100
+ * @param global 小程序全局对象,如微信的 wx,支付宝的 my
1101
+ */
1102
+ function equipCommonApis(taro, global, apis = {}) {
1103
+ taro.canIUseWebp = getCanIUseWebp(taro);
1104
+ taro.getCurrentPages = getCurrentPages || nonsupport('getCurrentPages');
1105
+ taro.getApp = getApp || nonsupport('getApp');
1106
+ taro.env = global.env || {};
1107
+ try {
1108
+ taro.requirePlugin = requirePlugin || nonsupport('requirePlugin');
1109
+ }
1110
+ catch (error) {
1111
+ taro.requirePlugin = nonsupport('requirePlugin');
1112
+ }
1113
+ // request & interceptors
1114
+ const request = apis.request || getNormalRequest(global);
1115
+ function taroInterceptor(chain) {
1116
+ return request(chain.requestParams);
1117
+ }
1118
+ const link = new taro.Link(taroInterceptor);
1119
+ taro.request = link.request.bind(link);
1120
+ taro.addInterceptor = link.addInterceptor.bind(link);
1121
+ taro.cleanInterceptors = link.cleanInterceptors.bind(link);
1122
+ taro.miniGlobal = taro.options.miniGlobal = global;
1123
+ }
1124
+ /**
1125
+ * 将Task对象中的方法挂载到promise对象中,适配小程序api原生返回结果
1126
+ * @param task Task对象 {RequestTask | DownloadTask | UploadTask}
1127
+ * @param promise Promise
1128
+ */
1129
+ function equipTaskMethodsIntoPromise(task, promise) {
1130
+ if (!task || !promise)
1131
+ return;
1132
+ const taskMethods = ['abort', 'onHeadersReceived', 'offHeadersReceived', 'onProgressUpdate', 'offProgressUpdate', 'onChunkReceived', 'offChunkReceived'];
1133
+ task && taskMethods.forEach(method => {
1134
+ if (method in task) {
1135
+ promise[method] = task[method].bind(task);
1136
+ }
1137
+ });
1138
+ }
1102
1139
 
1103
1140
  exports.EMPTY_ARR = EMPTY_ARR;
1104
1141
  exports.EMPTY_OBJ = EMPTY_OBJ;
@@ -1114,6 +1151,7 @@ exports.capitalize = capitalize;
1114
1151
  exports.controlledComponent = controlledComponent;
1115
1152
  exports.ensure = ensure;
1116
1153
  exports.focusComponents = focusComponents;
1154
+ exports.getComponentsAlias = getComponentsAlias;
1117
1155
  exports.getUniqueKey = getUniqueKey;
1118
1156
  exports.hasOwn = hasOwn;
1119
1157
  exports.hooks = hooks;
@@ -1131,6 +1169,7 @@ exports.isUndefined = isUndefined;
1131
1169
  exports.mergeInternalComponents = mergeInternalComponents;
1132
1170
  exports.mergeReconciler = mergeReconciler;
1133
1171
  exports.nestElements = nestElements;
1172
+ exports.nonsupport = nonsupport;
1134
1173
  exports.noop = noop;
1135
1174
  exports.processApis = processApis;
1136
1175
  exports.queryToJson = queryToJson;
@@ -1141,7 +1180,6 @@ exports.toDashed = toDashed;
1141
1180
  exports.toKebabCase = toKebabCase;
1142
1181
  exports.touchEvents = touchEvents;
1143
1182
  exports.unbox = unbox;
1144
- exports.unsupport = unsupport;
1145
1183
  exports.voidElements = voidElements;
1146
1184
  exports.warn = warn;
1147
1185
  //# sourceMappingURL=index.js.map