@tarojs/shared 3.5.0-canary.1 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2,872 +2,1146 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- function isString(o) {
6
- return typeof o === 'string';
7
- }
8
- function isUndefined(o) {
9
- return typeof o === 'undefined';
10
- }
11
- function isNull(o) {
12
- return o === null;
13
- }
14
- function isObject(o) {
15
- return o !== null && typeof o === 'object';
16
- }
17
- function isBoolean(o) {
18
- return o === true || o === false;
19
- }
20
- function isFunction(o) {
21
- return typeof o === 'function';
22
- }
23
- function isNumber(o) {
24
- return typeof o === 'number';
25
- }
26
- function isBooleanStringLiteral(o) {
27
- return o === 'true' || o === 'false';
28
- }
29
- const isArray = Array.isArray;
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
+ ]);
30
340
 
31
- // 字符串简写
32
- exports.Shortcuts = void 0;
33
- (function (Shortcuts) {
34
- Shortcuts["Container"] = "container";
35
- Shortcuts["Childnodes"] = "cn";
36
- Shortcuts["Text"] = "v";
37
- Shortcuts["NodeType"] = "nt";
38
- Shortcuts["NodeName"] = "nn";
39
- // Attrtibutes
40
- Shortcuts["Style"] = "st";
41
- Shortcuts["Class"] = "cl";
42
- Shortcuts["Src"] = "src";
43
- })(exports.Shortcuts || (exports.Shortcuts = {}));
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
+ Events.eventSplitter = /\s+/;
44
421
 
45
- const DEFAULT_EMPTY_ARRAY = '[]';
46
- const NO_DEFAULT_VALUE = '';
47
- const DEFAULT_TRUE = 'true';
48
- const DEFAULT_FALSE = 'false';
49
- const touchEvents = {
50
- bindTouchStart: NO_DEFAULT_VALUE,
51
- bindTouchMove: NO_DEFAULT_VALUE,
52
- bindTouchEnd: NO_DEFAULT_VALUE,
53
- bindTouchCancel: NO_DEFAULT_VALUE,
54
- bindLongTap: NO_DEFAULT_VALUE
55
- };
56
- const animation = {
57
- animation: NO_DEFAULT_VALUE,
58
- bindAnimationStart: NO_DEFAULT_VALUE,
59
- bindAnimationIteration: NO_DEFAULT_VALUE,
60
- bindAnimationEnd: NO_DEFAULT_VALUE,
61
- bindTransitionEnd: NO_DEFAULT_VALUE
62
- };
63
- function singleQuote(s) {
64
- return `'${s}'`;
65
- }
66
- 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);
67
- const Icon = {
68
- type: NO_DEFAULT_VALUE,
69
- size: '23',
70
- color: NO_DEFAULT_VALUE
71
- };
72
- 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);
73
- const Progress = {
74
- percent: NO_DEFAULT_VALUE,
75
- 'stroke-width': '6',
76
- color: singleQuote('#09BB07'),
77
- activeColor: singleQuote('#09BB07'),
78
- backgroundColor: singleQuote('#EBEBEB'),
79
- active: DEFAULT_FALSE,
80
- 'active-mode': singleQuote('backwards'),
81
- 'show-info': DEFAULT_FALSE
82
- };
83
- const RichText = {
84
- nodes: DEFAULT_EMPTY_ARRAY
85
- };
86
- const Text = {
87
- selectable: DEFAULT_FALSE,
88
- space: NO_DEFAULT_VALUE,
89
- decode: DEFAULT_FALSE
90
- };
91
- 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);
92
- const Checkbox = {
93
- value: NO_DEFAULT_VALUE,
94
- disabled: NO_DEFAULT_VALUE,
95
- checked: DEFAULT_FALSE,
96
- color: singleQuote('#09BB07'),
97
- name: NO_DEFAULT_VALUE
98
- };
99
- const CheckboxGroup = {
100
- bindChange: NO_DEFAULT_VALUE,
101
- name: NO_DEFAULT_VALUE
102
- };
103
- const Form = {
104
- 'report-submit': DEFAULT_FALSE,
105
- bindSubmit: NO_DEFAULT_VALUE,
106
- bindReset: NO_DEFAULT_VALUE,
107
- name: NO_DEFAULT_VALUE
108
- };
109
- const Input = {
110
- value: NO_DEFAULT_VALUE,
111
- type: singleQuote(NO_DEFAULT_VALUE),
112
- password: DEFAULT_FALSE,
113
- placeholder: NO_DEFAULT_VALUE,
114
- 'placeholder-style': NO_DEFAULT_VALUE,
115
- 'placeholder-class': singleQuote('input-placeholder'),
116
- disabled: NO_DEFAULT_VALUE,
117
- maxlength: '140',
118
- 'cursor-spacing': '0',
119
- focus: DEFAULT_FALSE,
120
- 'confirm-type': singleQuote('done'),
121
- 'confirm-hold': DEFAULT_FALSE,
122
- cursor: 'i.value.length',
123
- 'selection-start': '-1',
124
- 'selection-end': '-1',
125
- bindInput: NO_DEFAULT_VALUE,
126
- bindFocus: NO_DEFAULT_VALUE,
127
- bindBlur: NO_DEFAULT_VALUE,
128
- bindConfirm: NO_DEFAULT_VALUE,
129
- name: NO_DEFAULT_VALUE
130
- };
131
- const Label = {
132
- for: NO_DEFAULT_VALUE,
133
- name: NO_DEFAULT_VALUE
134
- };
135
- const Picker = {
136
- mode: singleQuote('selector'),
137
- disabled: NO_DEFAULT_VALUE,
138
- range: NO_DEFAULT_VALUE,
139
- 'range-key': NO_DEFAULT_VALUE,
140
- value: NO_DEFAULT_VALUE,
141
- start: NO_DEFAULT_VALUE,
142
- end: NO_DEFAULT_VALUE,
143
- fields: singleQuote('day'),
144
- 'custom-item': NO_DEFAULT_VALUE,
145
- name: NO_DEFAULT_VALUE,
146
- bindCancel: NO_DEFAULT_VALUE,
147
- bindChange: NO_DEFAULT_VALUE,
148
- bindColumnChange: NO_DEFAULT_VALUE
149
- };
150
- const PickerView = {
151
- value: NO_DEFAULT_VALUE,
152
- 'indicator-style': NO_DEFAULT_VALUE,
153
- 'indicator-class': NO_DEFAULT_VALUE,
154
- 'mask-style': NO_DEFAULT_VALUE,
155
- 'mask-class': NO_DEFAULT_VALUE,
156
- bindChange: NO_DEFAULT_VALUE,
157
- name: NO_DEFAULT_VALUE
158
- };
159
- const PickerViewColumn = {
160
- name: NO_DEFAULT_VALUE
161
- };
162
- const Radio = {
163
- value: NO_DEFAULT_VALUE,
164
- checked: DEFAULT_FALSE,
165
- disabled: NO_DEFAULT_VALUE,
166
- color: singleQuote('#09BB07'),
167
- name: NO_DEFAULT_VALUE
168
- };
169
- const RadioGroup = {
170
- bindChange: NO_DEFAULT_VALUE,
171
- name: NO_DEFAULT_VALUE
172
- };
173
- const Slider = {
174
- min: '0',
175
- max: '100',
176
- step: '1',
177
- disabled: NO_DEFAULT_VALUE,
178
- value: '0',
179
- activeColor: singleQuote('#1aad19'),
180
- backgroundColor: singleQuote('#e9e9e9'),
181
- 'block-size': '28',
182
- 'block-color': singleQuote('#ffffff'),
183
- 'show-value': DEFAULT_FALSE,
184
- bindChange: NO_DEFAULT_VALUE,
185
- bindChanging: NO_DEFAULT_VALUE,
186
- name: NO_DEFAULT_VALUE
187
- };
188
- const Switch = {
189
- checked: DEFAULT_FALSE,
190
- disabled: NO_DEFAULT_VALUE,
191
- type: singleQuote('switch'),
192
- color: singleQuote('#04BE02'),
193
- bindChange: NO_DEFAULT_VALUE,
194
- name: NO_DEFAULT_VALUE
195
- };
196
- const Textarea = {
197
- value: NO_DEFAULT_VALUE,
198
- placeholder: NO_DEFAULT_VALUE,
199
- 'placeholder-style': NO_DEFAULT_VALUE,
200
- 'placeholder-class': singleQuote('textarea-placeholder'),
201
- disabled: NO_DEFAULT_VALUE,
202
- maxlength: '140',
203
- 'auto-focus': DEFAULT_FALSE,
204
- focus: DEFAULT_FALSE,
205
- 'auto-height': DEFAULT_FALSE,
206
- fixed: DEFAULT_FALSE,
207
- 'cursor-spacing': '0',
208
- cursor: '-1',
209
- 'selection-start': '-1',
210
- 'selection-end': '-1',
211
- bindFocus: NO_DEFAULT_VALUE,
212
- bindBlur: NO_DEFAULT_VALUE,
213
- bindLineChange: NO_DEFAULT_VALUE,
214
- bindInput: NO_DEFAULT_VALUE,
215
- bindConfirm: NO_DEFAULT_VALUE,
216
- name: NO_DEFAULT_VALUE
217
- };
218
- const CoverImage = {
219
- src: NO_DEFAULT_VALUE,
220
- bindLoad: 'eh',
221
- bindError: 'eh'
222
- };
223
- const CoverView = Object.assign({ 'scroll-top': DEFAULT_FALSE }, touchEvents);
224
- const MovableArea = {
225
- 'scale-area': DEFAULT_FALSE
226
- };
227
- 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);
228
- 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);
229
- 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);
230
- const SwiperItem = {
231
- 'item-id': NO_DEFAULT_VALUE
232
- };
233
- const Navigator = {
234
- url: NO_DEFAULT_VALUE,
235
- 'open-type': singleQuote('navigate'),
236
- delta: '1',
237
- 'hover-class': singleQuote('navigator-hover'),
238
- 'hover-stop-propagation': DEFAULT_FALSE,
239
- 'hover-start-time': '50',
240
- 'hover-stay-time': '600',
241
- bindSuccess: NO_DEFAULT_VALUE,
242
- bindFail: NO_DEFAULT_VALUE,
243
- bindComplete: NO_DEFAULT_VALUE
244
- };
245
- const Audio = {
246
- id: NO_DEFAULT_VALUE,
247
- src: NO_DEFAULT_VALUE,
248
- loop: DEFAULT_FALSE,
249
- controls: DEFAULT_FALSE,
250
- poster: NO_DEFAULT_VALUE,
251
- name: NO_DEFAULT_VALUE,
252
- author: NO_DEFAULT_VALUE,
253
- bindError: NO_DEFAULT_VALUE,
254
- bindPlay: NO_DEFAULT_VALUE,
255
- bindPause: NO_DEFAULT_VALUE,
256
- bindTimeUpdate: NO_DEFAULT_VALUE,
257
- bindEnded: NO_DEFAULT_VALUE
258
- };
259
- const Camera = {
260
- 'device-position': singleQuote('back'),
261
- flash: singleQuote('auto'),
262
- bindStop: NO_DEFAULT_VALUE,
263
- bindError: NO_DEFAULT_VALUE
264
- };
265
- const Image = Object.assign({ src: NO_DEFAULT_VALUE, mode: singleQuote('scaleToFill'), 'lazy-load': DEFAULT_FALSE, bindError: NO_DEFAULT_VALUE, bindLoad: NO_DEFAULT_VALUE }, touchEvents);
266
- 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);
267
- 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);
268
- const Canvas = Object.assign({ 'canvas-id': NO_DEFAULT_VALUE, 'disable-scroll': DEFAULT_FALSE, bindError: NO_DEFAULT_VALUE }, touchEvents);
269
- const Ad = {
270
- 'unit-id': NO_DEFAULT_VALUE,
271
- 'ad-intervals': NO_DEFAULT_VALUE,
272
- bindLoad: NO_DEFAULT_VALUE,
273
- bindError: NO_DEFAULT_VALUE,
274
- bindClose: NO_DEFAULT_VALUE
275
- };
276
- const WebView = {
277
- src: NO_DEFAULT_VALUE,
278
- bindMessage: NO_DEFAULT_VALUE,
279
- bindLoad: NO_DEFAULT_VALUE,
280
- bindError: NO_DEFAULT_VALUE
281
- };
282
- const Block = {};
283
- // For Vue,因为 slot 标签被 vue 占用了
284
- const SlotView = {
285
- name: NO_DEFAULT_VALUE
286
- };
287
- // For React
288
- // Slot 和 SlotView 最终都会编译成 <view slot={{ i.name }} />
289
- // 因为 <slot name="{{ i.name }}" /> 适用性没有前者高(无法添加类和样式)
290
- // 不给 View 直接加 slot 属性的原因是性能损耗
291
- const Slot = {
292
- name: NO_DEFAULT_VALUE
293
- };
294
- const internalComponents = {
295
- View,
296
- Icon,
297
- Progress,
298
- RichText,
299
- Text,
300
- Button,
301
- Checkbox,
302
- CheckboxGroup,
303
- Form,
304
- Input,
305
- Label,
306
- Picker,
307
- PickerView,
308
- PickerViewColumn,
309
- Radio,
310
- RadioGroup,
311
- Slider,
312
- Switch,
313
- CoverImage,
314
- Textarea,
315
- CoverView,
316
- MovableArea,
317
- MovableView,
318
- ScrollView,
319
- Swiper,
320
- SwiperItem,
321
- Navigator,
322
- Audio,
323
- Camera,
324
- Image,
325
- LivePlayer,
326
- Video,
327
- Canvas,
328
- Ad,
329
- WebView,
330
- Block,
331
- Map: MapComp,
332
- Slot,
333
- SlotView
334
- };
335
- const controlledComponent = new Set([
336
- 'input',
337
- 'checkbox',
338
- 'picker',
339
- 'picker-view',
340
- 'radio',
341
- 'slider',
342
- 'switch',
343
- 'textarea'
344
- ]);
345
- const focusComponents = new Set([
346
- 'input',
347
- 'textarea'
348
- ]);
349
- const voidElements = new Set([
350
- 'progress',
351
- 'icon',
352
- 'rich-text',
353
- 'input',
354
- 'textarea',
355
- 'slider',
356
- 'switch',
357
- 'audio',
358
- 'ad',
359
- 'official-account',
360
- 'open-data',
361
- 'navigation-bar'
362
- ]);
363
- const nestElements = new Map([
364
- ['view', -1],
365
- ['catch-view', -1],
366
- ['cover-view', -1],
367
- ['static-view', -1],
368
- ['pure-view', -1],
369
- ['block', -1],
370
- ['text', -1],
371
- ['static-text', 6],
372
- ['slot', 8],
373
- ['slot-view', 8],
374
- ['label', 6],
375
- ['form', 4],
376
- ['scroll-view', 4],
377
- ['swiper', 4],
378
- ['swiper-item', 4]
379
- ]);
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
+ const isArray = Array.isArray;
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)
598
+ });
380
599
 
381
- const EMPTY_OBJ = {};
382
- const EMPTY_ARR = [];
383
- const noop = (..._) => { };
384
- const defaultReconciler = Object.create(null);
385
- /**
386
- * box creates a boxed value.
387
- *
388
- * @typeparam T Value type.
389
- * @param v Value.
390
- * @returns Boxed value.
391
- */
392
- const box = (v) => ({ v });
393
- /**
394
- * box creates a boxed value.
395
- *
396
- * @typeparam T Value type.
397
- * @param b Boxed value.
398
- * @returns Value.
399
- */
400
- const unbox = (b) => b.v;
401
- function toDashed(s) {
402
- return s.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
403
- }
404
- function toCamelCase(s) {
405
- let camel = '';
406
- let nextCap = false;
407
- for (let i = 0; i < s.length; i++) {
408
- if (s[i] !== '-') {
409
- camel += nextCap ? s[i].toUpperCase() : s[i];
410
- nextCap = false;
411
- }
412
- else {
413
- nextCap = true;
414
- }
415
- }
416
- return camel;
417
- }
418
- const toKebabCase = function (string) {
419
- return string.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
420
- };
421
- function capitalize(s) {
422
- return s.charAt(0).toUpperCase() + s.slice(1);
423
- }
424
- const hasOwnProperty = Object.prototype.hasOwnProperty;
425
- const hasOwn = (val, key) => hasOwnProperty.call(val, key);
426
- /**
427
- * ensure takes a condition and throw a error if the condition fails,
428
- * like failure::ensure: https://docs.rs/failure/0.1.1/failure/macro.ensure.html
429
- * @param condition condition.
430
- * @param msg error message.
431
- */
432
- function ensure(condition, msg) {
433
- if (!condition) {
434
- if (process.env.NODE_ENV !== 'production') {
435
- const reportIssue = '\n如有疑问,请提交 issue 至:https://github.com/nervjs/taro/issues';
436
- throw new Error(msg + reportIssue);
437
- }
438
- else {
439
- throw new Error(msg);
440
- }
441
- }
442
- }
443
- function warn(condition, msg) {
444
- if (process.env.NODE_ENV !== 'production') {
445
- if (condition) {
446
- console.warn(`[taro warn] ${msg}`);
447
- }
448
- }
449
- }
450
- function queryToJson(str) {
451
- const dec = decodeURIComponent;
452
- const qp = str.split('&');
453
- const ret = {};
454
- let name;
455
- let val;
456
- for (let i = 0, l = qp.length, item; i < l; ++i) {
457
- item = qp[i];
458
- if (item.length) {
459
- const s = item.indexOf('=');
460
- if (s < 0) {
461
- name = dec(item);
462
- val = '';
463
- }
464
- else {
465
- name = dec(item.slice(0, s));
466
- val = dec(item.slice(s + 1));
467
- }
468
- if (typeof ret[name] === 'string') { // inline'd type check
469
- ret[name] = [ret[name]];
470
- }
471
- if (Array.isArray(ret[name])) {
472
- ret[name].push(val);
473
- }
474
- else {
475
- ret[name] = val;
476
- }
477
- }
478
- }
479
- return ret; // Object
480
- }
481
- let _uniqueId = 1;
482
- const _loadTime = (new Date()).getTime().toString();
483
- function getUniqueKey() {
484
- return _loadTime + (_uniqueId++);
485
- }
486
- const cacheData = {};
487
- function cacheDataSet(key, val) {
488
- cacheData[key] = val;
489
- }
490
- function cacheDataGet(key, delelteAfterGet) {
491
- const temp = cacheData[key];
492
- delelteAfterGet && delete cacheData[key];
493
- return temp;
494
- }
495
- function cacheDataHas(key) {
496
- return key in cacheData;
497
- }
498
- function mergeInternalComponents(components) {
499
- Object.keys(components).forEach(name => {
500
- if (name in internalComponents) {
501
- Object.assign(internalComponents[name], components[name]);
502
- }
503
- else {
504
- internalComponents[name] = components[name];
505
- }
506
- });
507
- }
508
- function mergeReconciler(hostConfig) {
509
- Object.keys(hostConfig).forEach(key => {
510
- const value = hostConfig[key];
511
- const raw = defaultReconciler[key];
512
- defaultReconciler[key] = !raw
513
- ? value
514
- : (isArray(raw)
515
- ? raw.concat(value)
516
- : [raw, value]);
517
- });
518
- }
519
- function unsupport(api) {
520
- return function () {
521
- console.warn(`小程序暂不支持 ${api}`);
522
- };
523
- }
524
- function setUniqueKeyToRoute(key, obj) {
525
- const routerParamsPrivateKey = '__key_';
526
- const useDataCacheApis = [
527
- 'navigateTo',
528
- 'redirectTo',
529
- 'reLaunch',
530
- 'switchTab'
531
- ];
532
- if (useDataCacheApis.indexOf(key) > -1) {
533
- const url = obj.url = obj.url || '';
534
- const hasMark = url.indexOf('?') > -1;
535
- const cacheKey = getUniqueKey();
536
- obj.url += (hasMark ? '&' : '?') + `${routerParamsPrivateKey}=${cacheKey}`;
537
- }
538
- }
539
- function indent(str, size) {
540
- return str.split('\n')
541
- .map((line, index) => {
542
- const indent = index === 0 ? '' : Array(size).fill(' ').join('');
543
- return indent + line;
544
- })
545
- .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();
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
+ 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');
546
800
  }
547
801
 
548
- const needPromiseApis = new Set([
549
- 'addPhoneContact',
550
- 'authorize',
551
- 'canvasGetImageData',
552
- 'canvasPutImageData',
553
- 'canvasToTempFilePath',
554
- 'checkSession',
555
- 'chooseAddress',
556
- 'chooseImage',
557
- 'chooseInvoiceTitle',
558
- 'chooseLocation',
559
- 'chooseVideo',
560
- 'clearStorage',
561
- 'closeBLEConnection',
562
- 'closeBluetoothAdapter',
563
- 'closeSocket',
564
- 'compressImage',
565
- 'connectSocket',
566
- 'createBLEConnection',
567
- 'downloadFile',
568
- 'exitMiniProgram',
569
- 'getAvailableAudioSources',
570
- 'getBLEDeviceCharacteristics',
571
- 'getBLEDeviceServices',
572
- 'getBatteryInfo',
573
- 'getBeacons',
574
- 'getBluetoothAdapterState',
575
- 'getBluetoothDevices',
576
- 'getClipboardData',
577
- 'getConnectedBluetoothDevices',
578
- 'getConnectedWifi',
579
- 'getExtConfig',
580
- 'getFileInfo',
581
- 'getImageInfo',
582
- 'getLocation',
583
- 'getNetworkType',
584
- 'getSavedFileInfo',
585
- 'getSavedFileList',
586
- 'getScreenBrightness',
587
- 'getSetting',
588
- 'getStorage',
589
- 'getStorageInfo',
590
- 'getSystemInfo',
591
- 'getUserInfo',
592
- 'getWifiList',
593
- 'hideHomeButton',
594
- 'hideShareMenu',
595
- 'hideTabBar',
596
- 'hideTabBarRedDot',
597
- 'loadFontFace',
598
- 'login',
599
- 'makePhoneCall',
600
- 'navigateBack',
601
- 'navigateBackMiniProgram',
602
- 'navigateTo',
603
- 'navigateToBookshelf',
604
- 'navigateToMiniProgram',
605
- 'notifyBLECharacteristicValueChange',
606
- 'hideKeyboard',
607
- 'hideLoading',
608
- 'hideNavigationBarLoading',
609
- 'hideToast',
610
- 'openBluetoothAdapter',
611
- 'openDocument',
612
- 'openLocation',
613
- 'openSetting',
614
- 'pageScrollTo',
615
- 'previewImage',
616
- 'queryBookshelf',
617
- 'reLaunch',
618
- 'readBLECharacteristicValue',
619
- 'redirectTo',
620
- 'removeSavedFile',
621
- 'removeStorage',
622
- 'removeTabBarBadge',
623
- 'requestSubscribeMessage',
624
- 'saveFile',
625
- 'saveImageToPhotosAlbum',
626
- 'saveVideoToPhotosAlbum',
627
- 'scanCode',
628
- 'sendSocketMessage',
629
- 'setBackgroundColor',
630
- 'setBackgroundTextStyle',
631
- 'setClipboardData',
632
- 'setEnableDebug',
633
- 'setInnerAudioOption',
634
- 'setKeepScreenOn',
635
- 'setNavigationBarColor',
636
- 'setNavigationBarTitle',
637
- 'setScreenBrightness',
638
- 'setStorage',
639
- 'setTabBarBadge',
640
- 'setTabBarItem',
641
- 'setTabBarStyle',
642
- 'showActionSheet',
643
- 'showFavoriteGuide',
644
- 'showLoading',
645
- 'showModal',
646
- 'showShareMenu',
647
- 'showTabBar',
648
- 'showTabBarRedDot',
649
- 'showToast',
650
- 'startBeaconDiscovery',
651
- 'startBluetoothDevicesDiscovery',
652
- 'startDeviceMotionListening',
653
- 'startPullDownRefresh',
654
- 'stopBeaconDiscovery',
655
- 'stopBluetoothDevicesDiscovery',
656
- 'stopCompass',
657
- 'startCompass',
658
- 'startAccelerometer',
659
- 'stopAccelerometer',
660
- 'showNavigationBarLoading',
661
- 'stopDeviceMotionListening',
662
- 'stopPullDownRefresh',
663
- 'switchTab',
664
- 'uploadFile',
665
- 'vibrateLong',
666
- 'vibrateShort',
667
- 'writeBLECharacteristicValue'
668
- ]);
669
- function getCanIUseWebp(taro) {
670
- return function () {
671
- var _a;
672
- const res = (_a = taro.getSystemInfoSync) === null || _a === void 0 ? void 0 : _a.call(taro);
673
- if (!res) {
674
- if (process.env.NODE_ENV !== 'production') {
675
- console.error('不支持 API canIUseWebp');
676
- }
677
- return false;
678
- }
679
- const { platform } = res;
680
- const platformLower = platform.toLowerCase();
681
- if (platformLower === 'android' || platformLower === 'devtools') {
682
- return true;
683
- }
684
- return false;
685
- };
686
- }
687
- function getNormalRequest(global) {
688
- return function request(options) {
689
- options = options
690
- ? (isString(options)
691
- ? { url: options }
692
- : options)
693
- : {};
694
- const originSuccess = options.success;
695
- const originFail = options.fail;
696
- const originComplete = options.complete;
697
- let requestTask;
698
- const p = new Promise((resolve, reject) => {
699
- options.success = res => {
700
- originSuccess && originSuccess(res);
701
- resolve(res);
702
- };
703
- options.fail = res => {
704
- originFail && originFail(res);
705
- reject(res);
706
- };
707
- options.complete = res => {
708
- originComplete && originComplete(res);
709
- };
710
- requestTask = global.request(options);
711
- });
712
- p.abort = (cb) => {
713
- cb && cb();
714
- if (requestTask) {
715
- requestTask.abort();
716
- }
717
- return p;
718
- };
719
- return p;
720
- };
721
- }
722
- function processApis(taro, global, config = {}) {
723
- const patchNeedPromiseApis = config.needPromiseApis || [];
724
- const _needPromiseApis = new Set([...patchNeedPromiseApis, ...needPromiseApis]);
725
- const preserved = [
726
- 'getEnv',
727
- 'interceptors',
728
- 'Current',
729
- 'getCurrentInstance',
730
- 'options',
731
- 'nextTick',
732
- 'eventCenter',
733
- 'Events',
734
- 'preload',
735
- 'webpackJsonp'
736
- ];
737
- const apis = new Set(!config.isOnlyPromisify
738
- ? Object.keys(global).filter(api => preserved.indexOf(api) === -1)
739
- : patchNeedPromiseApis);
740
- if (config.modifyApis) {
741
- config.modifyApis(apis);
742
- }
743
- apis.forEach(key => {
744
- if (_needPromiseApis.has(key)) {
745
- const originKey = key;
746
- taro[originKey] = (options = {}, ...args) => {
747
- let key = originKey;
748
- // 第一个参数 options 为字符串,单独处理
749
- if (typeof options === 'string') {
750
- if (args.length) {
751
- return global[key](options, ...args);
752
- }
753
- return global[key](options);
754
- }
755
- // 改变 key 或 option 字段,如需要把支付宝标准的字段对齐微信标准的字段
756
- if (config.transformMeta) {
757
- const transformResult = config.transformMeta(key, options);
758
- key = transformResult.key;
759
- options = transformResult.options;
760
- // key 可能不存在
761
- if (!global.hasOwnProperty(key)) {
762
- return unsupport(key)();
763
- }
764
- }
765
- let task = null;
766
- const obj = Object.assign({}, options);
767
- // 为页面跳转相关的 API 设置一个随机数作为路由参数。为了给 runtime 区分页面。
768
- setUniqueKeyToRoute(key, options);
769
- // Promise 化
770
- const p = new Promise((resolve, reject) => {
771
- obj.success = res => {
772
- var _a, _b;
773
- (_a = config.modifyAsyncResult) === null || _a === void 0 ? void 0 : _a.call(config, key, res);
774
- (_b = options.success) === null || _b === void 0 ? void 0 : _b.call(options, res);
775
- if (key === 'connectSocket') {
776
- resolve(Promise.resolve().then(() => task ? Object.assign(task, res) : res));
777
- }
778
- else {
779
- resolve(res);
780
- }
781
- };
782
- obj.fail = res => {
783
- var _a;
784
- (_a = options.fail) === null || _a === void 0 ? void 0 : _a.call(options, res);
785
- reject(res);
786
- };
787
- obj.complete = res => {
788
- var _a;
789
- (_a = options.complete) === null || _a === void 0 ? void 0 : _a.call(options, res);
790
- };
791
- if (args.length) {
792
- task = global[key](obj, ...args);
793
- }
794
- else {
795
- task = global[key](obj);
796
- }
797
- });
798
- // 给 promise 对象挂载属性
799
- if (key === 'uploadFile' || key === 'downloadFile') {
800
- p.progress = cb => {
801
- task === null || task === void 0 ? void 0 : task.onProgressUpdate(cb);
802
- return p;
803
- };
804
- p.abort = cb => {
805
- cb === null || cb === void 0 ? void 0 : cb();
806
- task === null || task === void 0 ? void 0 : task.abort();
807
- return p;
808
- };
809
- }
810
- return p;
811
- };
812
- }
813
- else {
814
- let platformKey = key;
815
- // 改变 key 或 option 字段,如需要把支付宝标准的字段对齐微信标准的字段
816
- if (config.transformMeta) {
817
- platformKey = config.transformMeta(key, {}).key;
818
- }
819
- // API 不存在
820
- if (!global.hasOwnProperty(platformKey)) {
821
- taro[key] = unsupport(key);
822
- return;
823
- }
824
- if (isFunction(global[key])) {
825
- taro[key] = (...args) => {
826
- if (config.handleSyncApis) {
827
- return config.handleSyncApis(key, global, args);
828
- }
829
- else {
830
- return global[platformKey].apply(global, args);
831
- }
832
- };
833
- }
834
- else {
835
- taro[key] = global[platformKey];
836
- }
837
- }
838
- });
839
- !config.isOnlyPromisify && equipCommonApis(taro, global, config);
840
- }
841
- /**
842
- * 挂载常用 API
843
- * @param taro Taro 对象
844
- * @param global 小程序全局对象,如微信的 wx,支付宝的 my
845
- */
846
- function equipCommonApis(taro, global, apis = {}) {
847
- taro.canIUseWebp = getCanIUseWebp(taro);
848
- taro.getCurrentPages = getCurrentPages || unsupport('getCurrentPages');
849
- taro.getApp = getApp || unsupport('getApp');
850
- taro.env = global.env || {};
851
- try {
852
- taro.requirePlugin = requirePlugin || unsupport('requirePlugin');
853
- }
854
- catch (error) {
855
- taro.requirePlugin = unsupport('requirePlugin');
856
- }
857
- // request & interceptors
858
- const request = apis.request || getNormalRequest(global);
859
- function taroInterceptor(chain) {
860
- return request(chain.requestParams);
861
- }
862
- const link = new taro.Link(taroInterceptor);
863
- taro.request = link.request.bind(link);
864
- taro.addInterceptor = link.addInterceptor.bind(link);
865
- taro.cleanInterceptors = link.cleanInterceptors.bind(link);
866
- taro.miniGlobal = taro.options.miniGlobal = global;
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
+ });
867
1138
  }
868
1139
 
869
1140
  exports.EMPTY_ARR = EMPTY_ARR;
870
1141
  exports.EMPTY_OBJ = EMPTY_OBJ;
1142
+ exports.Events = Events;
1143
+ exports.TaroHook = TaroHook;
1144
+ exports.TaroHooks = TaroHooks;
871
1145
  exports.animation = animation;
872
1146
  exports.box = box;
873
1147
  exports.cacheDataGet = cacheDataGet;
@@ -875,11 +1149,12 @@ exports.cacheDataHas = cacheDataHas;
875
1149
  exports.cacheDataSet = cacheDataSet;
876
1150
  exports.capitalize = capitalize;
877
1151
  exports.controlledComponent = controlledComponent;
878
- exports.defaultReconciler = defaultReconciler;
879
1152
  exports.ensure = ensure;
880
1153
  exports.focusComponents = focusComponents;
1154
+ exports.getComponentsAlias = getComponentsAlias;
881
1155
  exports.getUniqueKey = getUniqueKey;
882
1156
  exports.hasOwn = hasOwn;
1157
+ exports.hooks = hooks;
883
1158
  exports.indent = indent;
884
1159
  exports.internalComponents = internalComponents;
885
1160
  exports.isArray = isArray;
@@ -894,6 +1169,7 @@ exports.isUndefined = isUndefined;
894
1169
  exports.mergeInternalComponents = mergeInternalComponents;
895
1170
  exports.mergeReconciler = mergeReconciler;
896
1171
  exports.nestElements = nestElements;
1172
+ exports.nonsupport = nonsupport;
897
1173
  exports.noop = noop;
898
1174
  exports.processApis = processApis;
899
1175
  exports.queryToJson = queryToJson;
@@ -904,7 +1180,6 @@ exports.toDashed = toDashed;
904
1180
  exports.toKebabCase = toKebabCase;
905
1181
  exports.touchEvents = touchEvents;
906
1182
  exports.unbox = unbox;
907
- exports.unsupport = unsupport;
908
1183
  exports.voidElements = voidElements;
909
1184
  exports.warn = warn;
910
1185
  //# sourceMappingURL=index.js.map