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