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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/template.js CHANGED
@@ -2,1128 +2,1185 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const DEFAULT_EMPTY_ARRAY = '[]';
6
- const NO_DEFAULT_VALUE = '';
7
- const DEFAULT_TRUE = 'true';
8
- const DEFAULT_FALSE = 'false';
9
- const touchEvents = {
10
- bindTouchStart: NO_DEFAULT_VALUE,
11
- bindTouchMove: NO_DEFAULT_VALUE,
12
- bindTouchEnd: NO_DEFAULT_VALUE,
13
- bindTouchCancel: NO_DEFAULT_VALUE,
14
- bindLongTap: NO_DEFAULT_VALUE
15
- };
16
- const animation = {
17
- animation: NO_DEFAULT_VALUE,
18
- bindAnimationStart: NO_DEFAULT_VALUE,
19
- bindAnimationIteration: NO_DEFAULT_VALUE,
20
- bindAnimationEnd: NO_DEFAULT_VALUE,
21
- bindTransitionEnd: NO_DEFAULT_VALUE
22
- };
23
- function singleQuote(s) {
24
- return `'${s}'`;
25
- }
26
- const View = Object.assign(Object.assign({ 'hover-class': singleQuote('none'), 'hover-stop-propagation': DEFAULT_FALSE, 'hover-start-time': '50', 'hover-stay-time': '400' }, touchEvents), animation);
27
- const Icon = {
28
- type: NO_DEFAULT_VALUE,
29
- size: '23',
30
- color: NO_DEFAULT_VALUE
31
- };
32
- const MapComp = Object.assign({ longitude: NO_DEFAULT_VALUE, latitude: NO_DEFAULT_VALUE, scale: '16', markers: DEFAULT_EMPTY_ARRAY, covers: NO_DEFAULT_VALUE, polyline: DEFAULT_EMPTY_ARRAY, circles: DEFAULT_EMPTY_ARRAY, controls: DEFAULT_EMPTY_ARRAY, 'include-points': DEFAULT_EMPTY_ARRAY, 'show-location': NO_DEFAULT_VALUE, 'layer-style': '1', bindMarkerTap: NO_DEFAULT_VALUE, bindControlTap: NO_DEFAULT_VALUE, bindCalloutTap: NO_DEFAULT_VALUE, bindUpdated: NO_DEFAULT_VALUE }, touchEvents);
33
- const Progress = {
34
- percent: NO_DEFAULT_VALUE,
35
- 'stroke-width': '6',
36
- color: singleQuote('#09BB07'),
37
- activeColor: singleQuote('#09BB07'),
38
- backgroundColor: singleQuote('#EBEBEB'),
39
- active: DEFAULT_FALSE,
40
- 'active-mode': singleQuote('backwards'),
41
- 'show-info': DEFAULT_FALSE
42
- };
43
- const RichText = {
44
- nodes: DEFAULT_EMPTY_ARRAY
45
- };
46
- const Text = {
47
- selectable: DEFAULT_FALSE,
48
- space: NO_DEFAULT_VALUE,
49
- decode: DEFAULT_FALSE
50
- };
51
- const Button = Object.assign({ size: singleQuote('default'), type: NO_DEFAULT_VALUE, plain: DEFAULT_FALSE, disabled: NO_DEFAULT_VALUE, loading: DEFAULT_FALSE, 'form-type': NO_DEFAULT_VALUE, 'open-type': NO_DEFAULT_VALUE, 'hover-class': singleQuote('button-hover'), 'hover-stop-propagation': DEFAULT_FALSE, 'hover-start-time': '20', 'hover-stay-time': '70', name: NO_DEFAULT_VALUE }, touchEvents);
52
- const Checkbox = {
53
- value: NO_DEFAULT_VALUE,
54
- disabled: NO_DEFAULT_VALUE,
55
- checked: DEFAULT_FALSE,
56
- color: singleQuote('#09BB07'),
57
- name: NO_DEFAULT_VALUE
58
- };
59
- const CheckboxGroup = {
60
- bindChange: NO_DEFAULT_VALUE,
61
- name: NO_DEFAULT_VALUE
62
- };
63
- const Form = {
64
- 'report-submit': DEFAULT_FALSE,
65
- bindSubmit: NO_DEFAULT_VALUE,
66
- bindReset: NO_DEFAULT_VALUE,
67
- name: NO_DEFAULT_VALUE
68
- };
69
- const Input = {
70
- value: NO_DEFAULT_VALUE,
71
- type: singleQuote(NO_DEFAULT_VALUE),
72
- password: DEFAULT_FALSE,
73
- placeholder: NO_DEFAULT_VALUE,
74
- 'placeholder-style': NO_DEFAULT_VALUE,
75
- 'placeholder-class': singleQuote('input-placeholder'),
76
- disabled: NO_DEFAULT_VALUE,
77
- maxlength: '140',
78
- 'cursor-spacing': '0',
79
- focus: DEFAULT_FALSE,
80
- 'confirm-type': singleQuote('done'),
81
- 'confirm-hold': DEFAULT_FALSE,
82
- cursor: 'i.value.length',
83
- 'selection-start': '-1',
84
- 'selection-end': '-1',
85
- bindInput: NO_DEFAULT_VALUE,
86
- bindFocus: NO_DEFAULT_VALUE,
87
- bindBlur: NO_DEFAULT_VALUE,
88
- bindConfirm: NO_DEFAULT_VALUE,
89
- name: NO_DEFAULT_VALUE
90
- };
91
- const Label = {
92
- for: NO_DEFAULT_VALUE,
93
- name: NO_DEFAULT_VALUE
94
- };
95
- const Picker = {
96
- mode: singleQuote('selector'),
97
- disabled: NO_DEFAULT_VALUE,
98
- range: NO_DEFAULT_VALUE,
99
- 'range-key': NO_DEFAULT_VALUE,
100
- value: NO_DEFAULT_VALUE,
101
- start: NO_DEFAULT_VALUE,
102
- end: NO_DEFAULT_VALUE,
103
- fields: singleQuote('day'),
104
- 'custom-item': NO_DEFAULT_VALUE,
105
- name: NO_DEFAULT_VALUE,
106
- bindCancel: NO_DEFAULT_VALUE,
107
- bindChange: NO_DEFAULT_VALUE,
108
- bindColumnChange: NO_DEFAULT_VALUE
109
- };
110
- const PickerView = {
111
- value: NO_DEFAULT_VALUE,
112
- 'indicator-style': NO_DEFAULT_VALUE,
113
- 'indicator-class': NO_DEFAULT_VALUE,
114
- 'mask-style': NO_DEFAULT_VALUE,
115
- 'mask-class': NO_DEFAULT_VALUE,
116
- bindChange: NO_DEFAULT_VALUE,
117
- name: NO_DEFAULT_VALUE
118
- };
119
- const PickerViewColumn = {
120
- name: NO_DEFAULT_VALUE
121
- };
122
- const Radio = {
123
- value: NO_DEFAULT_VALUE,
124
- checked: DEFAULT_FALSE,
125
- disabled: NO_DEFAULT_VALUE,
126
- color: singleQuote('#09BB07'),
127
- name: NO_DEFAULT_VALUE
128
- };
129
- const RadioGroup = {
130
- bindChange: NO_DEFAULT_VALUE,
131
- name: NO_DEFAULT_VALUE
132
- };
133
- const Slider = {
134
- min: '0',
135
- max: '100',
136
- step: '1',
137
- disabled: NO_DEFAULT_VALUE,
138
- value: '0',
139
- activeColor: singleQuote('#1aad19'),
140
- backgroundColor: singleQuote('#e9e9e9'),
141
- 'block-size': '28',
142
- 'block-color': singleQuote('#ffffff'),
143
- 'show-value': DEFAULT_FALSE,
144
- bindChange: NO_DEFAULT_VALUE,
145
- bindChanging: NO_DEFAULT_VALUE,
146
- name: NO_DEFAULT_VALUE
147
- };
148
- const Switch = {
149
- checked: DEFAULT_FALSE,
150
- disabled: NO_DEFAULT_VALUE,
151
- type: singleQuote('switch'),
152
- color: singleQuote('#04BE02'),
153
- bindChange: NO_DEFAULT_VALUE,
154
- name: NO_DEFAULT_VALUE
155
- };
156
- const Textarea = {
157
- value: NO_DEFAULT_VALUE,
158
- placeholder: NO_DEFAULT_VALUE,
159
- 'placeholder-style': NO_DEFAULT_VALUE,
160
- 'placeholder-class': singleQuote('textarea-placeholder'),
161
- disabled: NO_DEFAULT_VALUE,
162
- maxlength: '140',
163
- 'auto-focus': DEFAULT_FALSE,
164
- focus: DEFAULT_FALSE,
165
- 'auto-height': DEFAULT_FALSE,
166
- fixed: DEFAULT_FALSE,
167
- 'cursor-spacing': '0',
168
- cursor: '-1',
169
- 'selection-start': '-1',
170
- 'selection-end': '-1',
171
- bindFocus: NO_DEFAULT_VALUE,
172
- bindBlur: NO_DEFAULT_VALUE,
173
- bindLineChange: NO_DEFAULT_VALUE,
174
- bindInput: NO_DEFAULT_VALUE,
175
- bindConfirm: NO_DEFAULT_VALUE,
176
- name: NO_DEFAULT_VALUE
177
- };
178
- const CoverImage = {
179
- src: NO_DEFAULT_VALUE,
180
- bindLoad: 'eh',
181
- bindError: 'eh'
182
- };
183
- const CoverView = Object.assign({ 'scroll-top': DEFAULT_FALSE }, touchEvents);
184
- const MovableArea = {
185
- 'scale-area': DEFAULT_FALSE
186
- };
187
- const MovableView = Object.assign(Object.assign({ direction: 'none', inertia: DEFAULT_FALSE, 'out-of-bounds': DEFAULT_FALSE, x: NO_DEFAULT_VALUE, y: NO_DEFAULT_VALUE, damping: '20', friction: '2', disabled: NO_DEFAULT_VALUE, scale: DEFAULT_FALSE, 'scale-min': '0.5', 'scale-max': '10', 'scale-value': '1', bindChange: NO_DEFAULT_VALUE, bindScale: NO_DEFAULT_VALUE, bindHTouchMove: NO_DEFAULT_VALUE, bindVTouchMove: NO_DEFAULT_VALUE, width: singleQuote('10px'), height: singleQuote('10px') }, touchEvents), animation);
188
- const ScrollView = Object.assign(Object.assign({ 'scroll-x': DEFAULT_FALSE, 'scroll-y': DEFAULT_FALSE, 'upper-threshold': '50', 'lower-threshold': '50', 'scroll-top': NO_DEFAULT_VALUE, 'scroll-left': NO_DEFAULT_VALUE, 'scroll-into-view': NO_DEFAULT_VALUE, 'scroll-with-animation': DEFAULT_FALSE, 'enable-back-to-top': DEFAULT_FALSE, bindScrollToUpper: NO_DEFAULT_VALUE, bindScrollToLower: NO_DEFAULT_VALUE, bindScroll: NO_DEFAULT_VALUE }, touchEvents), animation);
189
- const Swiper = Object.assign({ 'indicator-dots': DEFAULT_FALSE, 'indicator-color': singleQuote('rgba(0, 0, 0, .3)'), 'indicator-active-color': singleQuote('#000000'), autoplay: DEFAULT_FALSE, current: '0', interval: '5000', duration: '500', circular: DEFAULT_FALSE, vertical: DEFAULT_FALSE, 'previous-margin': singleQuote('0px'), 'next-margin': singleQuote('0px'), 'display-multiple-items': '1', bindChange: NO_DEFAULT_VALUE, bindTransition: NO_DEFAULT_VALUE, bindAnimationFinish: NO_DEFAULT_VALUE }, touchEvents);
190
- const SwiperItem = {
191
- 'item-id': NO_DEFAULT_VALUE
192
- };
193
- const Navigator = {
194
- url: NO_DEFAULT_VALUE,
195
- 'open-type': singleQuote('navigate'),
196
- delta: '1',
197
- 'hover-class': singleQuote('navigator-hover'),
198
- 'hover-stop-propagation': DEFAULT_FALSE,
199
- 'hover-start-time': '50',
200
- 'hover-stay-time': '600',
201
- bindSuccess: NO_DEFAULT_VALUE,
202
- bindFail: NO_DEFAULT_VALUE,
203
- bindComplete: NO_DEFAULT_VALUE
204
- };
205
- const Audio = {
206
- id: NO_DEFAULT_VALUE,
207
- src: NO_DEFAULT_VALUE,
208
- loop: DEFAULT_FALSE,
209
- controls: DEFAULT_FALSE,
210
- poster: NO_DEFAULT_VALUE,
211
- name: NO_DEFAULT_VALUE,
212
- author: NO_DEFAULT_VALUE,
213
- bindError: NO_DEFAULT_VALUE,
214
- bindPlay: NO_DEFAULT_VALUE,
215
- bindPause: NO_DEFAULT_VALUE,
216
- bindTimeUpdate: NO_DEFAULT_VALUE,
217
- bindEnded: NO_DEFAULT_VALUE
218
- };
219
- const Camera = {
220
- 'device-position': singleQuote('back'),
221
- flash: singleQuote('auto'),
222
- bindStop: NO_DEFAULT_VALUE,
223
- bindError: NO_DEFAULT_VALUE
224
- };
225
- const Image = Object.assign({ src: NO_DEFAULT_VALUE, mode: singleQuote('scaleToFill'), 'lazy-load': DEFAULT_FALSE, bindError: NO_DEFAULT_VALUE, bindLoad: NO_DEFAULT_VALUE }, touchEvents);
226
- const LivePlayer = Object.assign({ src: NO_DEFAULT_VALUE, autoplay: DEFAULT_FALSE, muted: DEFAULT_FALSE, orientation: singleQuote('vertical'), 'object-fit': singleQuote('contain'), 'background-mute': DEFAULT_FALSE, 'min-cache': '1', 'max-cache': '3', bindStateChange: NO_DEFAULT_VALUE, bindFullScreenChange: NO_DEFAULT_VALUE, bindNetStatus: NO_DEFAULT_VALUE }, animation);
227
- const Video = Object.assign({ src: NO_DEFAULT_VALUE, duration: NO_DEFAULT_VALUE, controls: DEFAULT_TRUE, 'danmu-list': NO_DEFAULT_VALUE, 'danmu-btn': NO_DEFAULT_VALUE, 'enable-danmu': NO_DEFAULT_VALUE, autoplay: DEFAULT_FALSE, loop: DEFAULT_FALSE, muted: DEFAULT_FALSE, 'initial-time': '0', 'page-gesture': DEFAULT_FALSE, direction: NO_DEFAULT_VALUE, 'show-progress': DEFAULT_TRUE, 'show-fullscreen-btn': DEFAULT_TRUE, 'show-play-btn': DEFAULT_TRUE, 'show-center-play-btn': DEFAULT_TRUE, 'enable-progress-gesture': DEFAULT_TRUE, 'object-fit': singleQuote('contain'), poster: NO_DEFAULT_VALUE, 'show-mute-btn': DEFAULT_FALSE, bindPlay: NO_DEFAULT_VALUE, bindPause: NO_DEFAULT_VALUE, bindEnded: NO_DEFAULT_VALUE, bindTimeUpdate: NO_DEFAULT_VALUE, bindFullScreenChange: NO_DEFAULT_VALUE, bindWaiting: NO_DEFAULT_VALUE, bindError: NO_DEFAULT_VALUE }, animation);
228
- const Canvas = Object.assign({ 'canvas-id': NO_DEFAULT_VALUE, 'disable-scroll': DEFAULT_FALSE, bindError: NO_DEFAULT_VALUE }, touchEvents);
229
- const Ad = {
230
- 'unit-id': NO_DEFAULT_VALUE,
231
- 'ad-intervals': NO_DEFAULT_VALUE,
232
- bindLoad: NO_DEFAULT_VALUE,
233
- bindError: NO_DEFAULT_VALUE,
234
- bindClose: NO_DEFAULT_VALUE
235
- };
236
- const WebView = {
237
- src: NO_DEFAULT_VALUE,
238
- bindMessage: NO_DEFAULT_VALUE,
239
- bindLoad: NO_DEFAULT_VALUE,
240
- bindError: NO_DEFAULT_VALUE
241
- };
242
- const Block = {};
243
- // For Vue,因为 slot 标签被 vue 占用了
244
- const SlotView = {
245
- name: NO_DEFAULT_VALUE
246
- };
247
- // For React
248
- // Slot 和 SlotView 最终都会编译成 <view slot={{ i.name }} />
249
- // 因为 <slot name="{{ i.name }}" /> 适用性没有前者高(无法添加类和样式)
250
- // 不给 View 直接加 slot 属性的原因是性能损耗
251
- const Slot = {
252
- name: NO_DEFAULT_VALUE
253
- };
254
- const internalComponents = {
255
- View,
256
- Icon,
257
- Progress,
258
- RichText,
259
- Text,
260
- Button,
261
- Checkbox,
262
- CheckboxGroup,
263
- Form,
264
- Input,
265
- Label,
266
- Picker,
267
- PickerView,
268
- PickerViewColumn,
269
- Radio,
270
- RadioGroup,
271
- Slider,
272
- Switch,
273
- CoverImage,
274
- Textarea,
275
- CoverView,
276
- MovableArea,
277
- MovableView,
278
- ScrollView,
279
- Swiper,
280
- SwiperItem,
281
- Navigator,
282
- Audio,
283
- Camera,
284
- Image,
285
- LivePlayer,
286
- Video,
287
- Canvas,
288
- Ad,
289
- WebView,
290
- Block,
291
- Map: MapComp,
292
- Slot,
293
- SlotView
294
- };
295
- const focusComponents = new Set([
296
- 'input',
297
- 'textarea'
298
- ]);
299
- const voidElements = new Set([
300
- 'progress',
301
- 'icon',
302
- 'rich-text',
303
- 'input',
304
- 'textarea',
305
- 'slider',
306
- 'switch',
307
- 'audio',
308
- 'ad',
309
- 'official-account',
310
- 'open-data',
311
- 'navigation-bar'
312
- ]);
313
- const nestElements = new Map([
314
- ['view', -1],
315
- ['catch-view', -1],
316
- ['cover-view', -1],
317
- ['static-view', -1],
318
- ['pure-view', -1],
319
- ['block', -1],
320
- ['text', -1],
321
- ['static-text', 6],
322
- ['slot', 8],
323
- ['slot-view', 8],
324
- ['label', 6],
325
- ['form', 4],
326
- ['scroll-view', 4],
327
- ['swiper', 4],
328
- ['swiper-item', 4]
5
+ const DEFAULT_EMPTY_ARRAY = '[]';
6
+ const NO_DEFAULT_VALUE = '';
7
+ const DEFAULT_TRUE = '!0';
8
+ const DEFAULT_FALSE = '!1';
9
+ const touchEvents = {
10
+ bindTouchStart: NO_DEFAULT_VALUE,
11
+ bindTouchMove: NO_DEFAULT_VALUE,
12
+ bindTouchEnd: NO_DEFAULT_VALUE,
13
+ bindTouchCancel: NO_DEFAULT_VALUE,
14
+ bindLongTap: NO_DEFAULT_VALUE
15
+ };
16
+ const animation = {
17
+ animation: NO_DEFAULT_VALUE,
18
+ bindAnimationStart: NO_DEFAULT_VALUE,
19
+ bindAnimationIteration: NO_DEFAULT_VALUE,
20
+ bindAnimationEnd: NO_DEFAULT_VALUE,
21
+ bindTransitionEnd: NO_DEFAULT_VALUE
22
+ };
23
+ function singleQuote(s) {
24
+ return `'${s}'`;
25
+ }
26
+ const View = Object.assign(Object.assign({ 'hover-class': singleQuote('none'), 'hover-stop-propagation': DEFAULT_FALSE, 'hover-start-time': '50', 'hover-stay-time': '400' }, touchEvents), animation);
27
+ const Icon = {
28
+ type: NO_DEFAULT_VALUE,
29
+ size: '23',
30
+ color: NO_DEFAULT_VALUE
31
+ };
32
+ const MapComp = Object.assign({ longitude: NO_DEFAULT_VALUE, latitude: NO_DEFAULT_VALUE, scale: '16', markers: DEFAULT_EMPTY_ARRAY, covers: NO_DEFAULT_VALUE, polyline: DEFAULT_EMPTY_ARRAY, circles: DEFAULT_EMPTY_ARRAY, controls: DEFAULT_EMPTY_ARRAY, 'include-points': DEFAULT_EMPTY_ARRAY, 'show-location': NO_DEFAULT_VALUE, 'layer-style': '1', bindMarkerTap: NO_DEFAULT_VALUE, bindControlTap: NO_DEFAULT_VALUE, bindCalloutTap: NO_DEFAULT_VALUE, bindUpdated: NO_DEFAULT_VALUE }, touchEvents);
33
+ const Progress = {
34
+ percent: NO_DEFAULT_VALUE,
35
+ 'stroke-width': '6',
36
+ color: singleQuote('#09BB07'),
37
+ activeColor: singleQuote('#09BB07'),
38
+ backgroundColor: singleQuote('#EBEBEB'),
39
+ active: DEFAULT_FALSE,
40
+ 'active-mode': singleQuote('backwards'),
41
+ 'show-info': DEFAULT_FALSE
42
+ };
43
+ const RichText = {
44
+ nodes: DEFAULT_EMPTY_ARRAY
45
+ };
46
+ const Text = {
47
+ selectable: DEFAULT_FALSE,
48
+ space: NO_DEFAULT_VALUE,
49
+ decode: DEFAULT_FALSE
50
+ };
51
+ const Button = Object.assign({ size: singleQuote('default'), type: NO_DEFAULT_VALUE, plain: DEFAULT_FALSE, disabled: NO_DEFAULT_VALUE, loading: DEFAULT_FALSE, 'form-type': NO_DEFAULT_VALUE, 'open-type': NO_DEFAULT_VALUE, 'hover-class': singleQuote('button-hover'), 'hover-stop-propagation': DEFAULT_FALSE, 'hover-start-time': '20', 'hover-stay-time': '70', name: NO_DEFAULT_VALUE }, touchEvents);
52
+ const Checkbox = {
53
+ value: NO_DEFAULT_VALUE,
54
+ disabled: NO_DEFAULT_VALUE,
55
+ checked: DEFAULT_FALSE,
56
+ color: singleQuote('#09BB07'),
57
+ name: NO_DEFAULT_VALUE
58
+ };
59
+ const CheckboxGroup = {
60
+ bindChange: NO_DEFAULT_VALUE,
61
+ name: NO_DEFAULT_VALUE
62
+ };
63
+ const Form = {
64
+ 'report-submit': DEFAULT_FALSE,
65
+ bindSubmit: NO_DEFAULT_VALUE,
66
+ bindReset: NO_DEFAULT_VALUE,
67
+ name: NO_DEFAULT_VALUE
68
+ };
69
+ const Input = {
70
+ value: NO_DEFAULT_VALUE,
71
+ type: singleQuote(NO_DEFAULT_VALUE),
72
+ password: DEFAULT_FALSE,
73
+ placeholder: NO_DEFAULT_VALUE,
74
+ 'placeholder-style': NO_DEFAULT_VALUE,
75
+ 'placeholder-class': singleQuote('input-placeholder'),
76
+ disabled: NO_DEFAULT_VALUE,
77
+ maxlength: '140',
78
+ 'cursor-spacing': '0',
79
+ focus: DEFAULT_FALSE,
80
+ 'confirm-type': singleQuote('done'),
81
+ 'confirm-hold': DEFAULT_FALSE,
82
+ cursor: 'i.value.length',
83
+ 'selection-start': '-1',
84
+ 'selection-end': '-1',
85
+ bindInput: NO_DEFAULT_VALUE,
86
+ bindFocus: NO_DEFAULT_VALUE,
87
+ bindBlur: NO_DEFAULT_VALUE,
88
+ bindConfirm: NO_DEFAULT_VALUE,
89
+ name: NO_DEFAULT_VALUE
90
+ };
91
+ const Label = {
92
+ for: NO_DEFAULT_VALUE,
93
+ name: NO_DEFAULT_VALUE
94
+ };
95
+ const Picker = {
96
+ mode: singleQuote('selector'),
97
+ disabled: NO_DEFAULT_VALUE,
98
+ range: NO_DEFAULT_VALUE,
99
+ 'range-key': NO_DEFAULT_VALUE,
100
+ value: NO_DEFAULT_VALUE,
101
+ start: NO_DEFAULT_VALUE,
102
+ end: NO_DEFAULT_VALUE,
103
+ fields: singleQuote('day'),
104
+ 'custom-item': NO_DEFAULT_VALUE,
105
+ name: NO_DEFAULT_VALUE,
106
+ bindCancel: NO_DEFAULT_VALUE,
107
+ bindChange: NO_DEFAULT_VALUE,
108
+ bindColumnChange: NO_DEFAULT_VALUE
109
+ };
110
+ const PickerView = {
111
+ value: NO_DEFAULT_VALUE,
112
+ 'indicator-style': NO_DEFAULT_VALUE,
113
+ 'indicator-class': NO_DEFAULT_VALUE,
114
+ 'mask-style': NO_DEFAULT_VALUE,
115
+ 'mask-class': NO_DEFAULT_VALUE,
116
+ bindChange: NO_DEFAULT_VALUE,
117
+ name: NO_DEFAULT_VALUE
118
+ };
119
+ const PickerViewColumn = {
120
+ name: NO_DEFAULT_VALUE
121
+ };
122
+ const Radio = {
123
+ value: NO_DEFAULT_VALUE,
124
+ checked: DEFAULT_FALSE,
125
+ disabled: NO_DEFAULT_VALUE,
126
+ color: singleQuote('#09BB07'),
127
+ name: NO_DEFAULT_VALUE
128
+ };
129
+ const RadioGroup = {
130
+ bindChange: NO_DEFAULT_VALUE,
131
+ name: NO_DEFAULT_VALUE
132
+ };
133
+ const Slider = {
134
+ min: '0',
135
+ max: '100',
136
+ step: '1',
137
+ disabled: NO_DEFAULT_VALUE,
138
+ value: '0',
139
+ activeColor: singleQuote('#1aad19'),
140
+ backgroundColor: singleQuote('#e9e9e9'),
141
+ 'block-size': '28',
142
+ 'block-color': singleQuote('#ffffff'),
143
+ 'show-value': DEFAULT_FALSE,
144
+ bindChange: NO_DEFAULT_VALUE,
145
+ bindChanging: NO_DEFAULT_VALUE,
146
+ name: NO_DEFAULT_VALUE
147
+ };
148
+ const Switch = {
149
+ checked: DEFAULT_FALSE,
150
+ disabled: NO_DEFAULT_VALUE,
151
+ type: singleQuote('switch'),
152
+ color: singleQuote('#04BE02'),
153
+ bindChange: NO_DEFAULT_VALUE,
154
+ name: NO_DEFAULT_VALUE
155
+ };
156
+ const Textarea = {
157
+ value: NO_DEFAULT_VALUE,
158
+ placeholder: NO_DEFAULT_VALUE,
159
+ 'placeholder-style': NO_DEFAULT_VALUE,
160
+ 'placeholder-class': singleQuote('textarea-placeholder'),
161
+ disabled: NO_DEFAULT_VALUE,
162
+ maxlength: '140',
163
+ 'auto-focus': DEFAULT_FALSE,
164
+ focus: DEFAULT_FALSE,
165
+ 'auto-height': DEFAULT_FALSE,
166
+ fixed: DEFAULT_FALSE,
167
+ 'cursor-spacing': '0',
168
+ cursor: '-1',
169
+ 'selection-start': '-1',
170
+ 'selection-end': '-1',
171
+ bindFocus: NO_DEFAULT_VALUE,
172
+ bindBlur: NO_DEFAULT_VALUE,
173
+ bindLineChange: NO_DEFAULT_VALUE,
174
+ bindInput: NO_DEFAULT_VALUE,
175
+ bindConfirm: NO_DEFAULT_VALUE,
176
+ name: NO_DEFAULT_VALUE
177
+ };
178
+ const CoverImage = {
179
+ src: NO_DEFAULT_VALUE,
180
+ bindLoad: 'eh',
181
+ bindError: 'eh'
182
+ };
183
+ const CoverView = Object.assign({ 'scroll-top': DEFAULT_FALSE }, touchEvents);
184
+ const MovableArea = {
185
+ 'scale-area': DEFAULT_FALSE
186
+ };
187
+ const MovableView = Object.assign(Object.assign({ direction: 'none', inertia: DEFAULT_FALSE, 'out-of-bounds': DEFAULT_FALSE, x: NO_DEFAULT_VALUE, y: NO_DEFAULT_VALUE, damping: '20', friction: '2', disabled: NO_DEFAULT_VALUE, scale: DEFAULT_FALSE, 'scale-min': '0.5', 'scale-max': '10', 'scale-value': '1', bindChange: NO_DEFAULT_VALUE, bindScale: NO_DEFAULT_VALUE, bindHTouchMove: NO_DEFAULT_VALUE, bindVTouchMove: NO_DEFAULT_VALUE, width: singleQuote('10px'), height: singleQuote('10px') }, touchEvents), animation);
188
+ const ScrollView = Object.assign(Object.assign({ 'scroll-x': DEFAULT_FALSE, 'scroll-y': DEFAULT_FALSE, 'upper-threshold': '50', 'lower-threshold': '50', 'scroll-top': NO_DEFAULT_VALUE, 'scroll-left': NO_DEFAULT_VALUE, 'scroll-into-view': NO_DEFAULT_VALUE, 'scroll-with-animation': DEFAULT_FALSE, 'enable-back-to-top': DEFAULT_FALSE, bindScrollToUpper: NO_DEFAULT_VALUE, bindScrollToLower: NO_DEFAULT_VALUE, bindScroll: NO_DEFAULT_VALUE }, touchEvents), animation);
189
+ const Swiper = Object.assign({ 'indicator-dots': DEFAULT_FALSE, 'indicator-color': singleQuote('rgba(0, 0, 0, .3)'), 'indicator-active-color': singleQuote('#000000'), autoplay: DEFAULT_FALSE, current: '0', interval: '5000', duration: '500', circular: DEFAULT_FALSE, vertical: DEFAULT_FALSE, 'previous-margin': singleQuote('0px'), 'next-margin': singleQuote('0px'), 'display-multiple-items': '1', bindChange: NO_DEFAULT_VALUE, bindTransition: NO_DEFAULT_VALUE, bindAnimationFinish: NO_DEFAULT_VALUE }, touchEvents);
190
+ const SwiperItem = {
191
+ 'item-id': NO_DEFAULT_VALUE
192
+ };
193
+ const Navigator = {
194
+ url: NO_DEFAULT_VALUE,
195
+ 'open-type': singleQuote('navigate'),
196
+ delta: '1',
197
+ 'hover-class': singleQuote('navigator-hover'),
198
+ 'hover-stop-propagation': DEFAULT_FALSE,
199
+ 'hover-start-time': '50',
200
+ 'hover-stay-time': '600',
201
+ bindSuccess: NO_DEFAULT_VALUE,
202
+ bindFail: NO_DEFAULT_VALUE,
203
+ bindComplete: NO_DEFAULT_VALUE
204
+ };
205
+ const Audio = {
206
+ id: NO_DEFAULT_VALUE,
207
+ src: NO_DEFAULT_VALUE,
208
+ loop: DEFAULT_FALSE,
209
+ controls: DEFAULT_FALSE,
210
+ poster: NO_DEFAULT_VALUE,
211
+ name: NO_DEFAULT_VALUE,
212
+ author: NO_DEFAULT_VALUE,
213
+ bindError: NO_DEFAULT_VALUE,
214
+ bindPlay: NO_DEFAULT_VALUE,
215
+ bindPause: NO_DEFAULT_VALUE,
216
+ bindTimeUpdate: NO_DEFAULT_VALUE,
217
+ bindEnded: NO_DEFAULT_VALUE
218
+ };
219
+ const Camera = {
220
+ 'device-position': singleQuote('back'),
221
+ flash: singleQuote('auto'),
222
+ bindStop: NO_DEFAULT_VALUE,
223
+ bindError: NO_DEFAULT_VALUE
224
+ };
225
+ const Image = Object.assign({ src: NO_DEFAULT_VALUE, mode: singleQuote('scaleToFill'), 'lazy-load': DEFAULT_FALSE, bindError: NO_DEFAULT_VALUE, bindLoad: NO_DEFAULT_VALUE }, touchEvents);
226
+ const LivePlayer = Object.assign({ src: NO_DEFAULT_VALUE, autoplay: DEFAULT_FALSE, muted: DEFAULT_FALSE, orientation: singleQuote('vertical'), 'object-fit': singleQuote('contain'), 'background-mute': DEFAULT_FALSE, 'min-cache': '1', 'max-cache': '3', bindStateChange: NO_DEFAULT_VALUE, bindFullScreenChange: NO_DEFAULT_VALUE, bindNetStatus: NO_DEFAULT_VALUE }, animation);
227
+ const Video = Object.assign({ src: NO_DEFAULT_VALUE, duration: NO_DEFAULT_VALUE, controls: DEFAULT_TRUE, 'danmu-list': NO_DEFAULT_VALUE, 'danmu-btn': NO_DEFAULT_VALUE, 'enable-danmu': NO_DEFAULT_VALUE, autoplay: DEFAULT_FALSE, loop: DEFAULT_FALSE, muted: DEFAULT_FALSE, 'initial-time': '0', 'page-gesture': DEFAULT_FALSE, direction: NO_DEFAULT_VALUE, 'show-progress': DEFAULT_TRUE, 'show-fullscreen-btn': DEFAULT_TRUE, 'show-play-btn': DEFAULT_TRUE, 'show-center-play-btn': DEFAULT_TRUE, 'enable-progress-gesture': DEFAULT_TRUE, 'object-fit': singleQuote('contain'), poster: NO_DEFAULT_VALUE, 'show-mute-btn': DEFAULT_FALSE, bindPlay: NO_DEFAULT_VALUE, bindPause: NO_DEFAULT_VALUE, bindEnded: NO_DEFAULT_VALUE, bindTimeUpdate: NO_DEFAULT_VALUE, bindFullScreenChange: NO_DEFAULT_VALUE, bindWaiting: NO_DEFAULT_VALUE, bindError: NO_DEFAULT_VALUE }, animation);
228
+ const Canvas = Object.assign({ 'canvas-id': NO_DEFAULT_VALUE, 'disable-scroll': DEFAULT_FALSE, bindError: NO_DEFAULT_VALUE }, touchEvents);
229
+ const Ad = {
230
+ 'unit-id': NO_DEFAULT_VALUE,
231
+ 'ad-intervals': NO_DEFAULT_VALUE,
232
+ bindLoad: NO_DEFAULT_VALUE,
233
+ bindError: NO_DEFAULT_VALUE,
234
+ bindClose: NO_DEFAULT_VALUE
235
+ };
236
+ const WebView = {
237
+ src: NO_DEFAULT_VALUE,
238
+ bindMessage: NO_DEFAULT_VALUE,
239
+ bindLoad: NO_DEFAULT_VALUE,
240
+ bindError: NO_DEFAULT_VALUE
241
+ };
242
+ const Block = {};
243
+ // For Vue,因为 slot 标签被 vue 占用了
244
+ const SlotView = {
245
+ name: NO_DEFAULT_VALUE
246
+ };
247
+ // For React
248
+ // Slot 和 SlotView 最终都会编译成 <view slot={{ i.name }} />
249
+ // 因为 <slot name="{{ i.name }}" /> 适用性没有前者高(无法添加类和样式)
250
+ // 不给 View 直接加 slot 属性的原因是性能损耗
251
+ const Slot = {
252
+ name: NO_DEFAULT_VALUE
253
+ };
254
+ const internalComponents = {
255
+ View,
256
+ Icon,
257
+ Progress,
258
+ RichText,
259
+ Text,
260
+ Button,
261
+ Checkbox,
262
+ CheckboxGroup,
263
+ Form,
264
+ Input,
265
+ Label,
266
+ Picker,
267
+ PickerView,
268
+ PickerViewColumn,
269
+ Radio,
270
+ RadioGroup,
271
+ Slider,
272
+ Switch,
273
+ CoverImage,
274
+ Textarea,
275
+ CoverView,
276
+ MovableArea,
277
+ MovableView,
278
+ ScrollView,
279
+ Swiper,
280
+ SwiperItem,
281
+ Navigator,
282
+ Audio,
283
+ Camera,
284
+ Image,
285
+ LivePlayer,
286
+ Video,
287
+ Canvas,
288
+ Ad,
289
+ WebView,
290
+ Block,
291
+ Map: MapComp,
292
+ Slot,
293
+ SlotView
294
+ };
295
+ const focusComponents = new Set([
296
+ 'input',
297
+ 'textarea'
298
+ ]);
299
+ const voidElements = new Set([
300
+ 'progress',
301
+ 'icon',
302
+ 'rich-text',
303
+ 'input',
304
+ 'textarea',
305
+ 'slider',
306
+ 'switch',
307
+ 'audio',
308
+ 'ad',
309
+ 'official-account',
310
+ 'open-data',
311
+ 'navigation-bar'
312
+ ]);
313
+ const nestElements = new Map([
314
+ ['view', -1],
315
+ ['catch-view', -1],
316
+ ['cover-view', -1],
317
+ ['static-view', -1],
318
+ ['pure-view', -1],
319
+ ['block', -1],
320
+ ['text', -1],
321
+ ['static-text', 6],
322
+ ['slot', 8],
323
+ ['slot-view', 8],
324
+ ['label', 6],
325
+ ['form', 4],
326
+ ['scroll-view', 4],
327
+ ['swiper', 4],
328
+ ['swiper-item', 4]
329
329
  ]);
330
330
 
331
- function isString(o) {
332
- return typeof o === 'string';
333
- }
334
- function isFunction(o) {
335
- return typeof o === 'function';
336
- }
337
- function isNumber(o) {
338
- return typeof o === 'number';
339
- }
340
- function isBooleanStringLiteral(o) {
341
- return o === 'true' || o === 'false';
331
+ function isString(o) {
332
+ return typeof o === 'string';
333
+ }
334
+ function isFunction(o) {
335
+ return typeof o === 'function';
336
+ }
337
+ function isNumber(o) {
338
+ return typeof o === 'number';
339
+ }
340
+ function isBooleanStringLiteral(o) {
341
+ return o === 'true' || o === 'false';
342
342
  }
343
343
 
344
- class Events {
345
- constructor(opts) {
346
- var _a;
347
- this.callbacks = (_a = opts === null || opts === void 0 ? void 0 : opts.callbacks) !== null && _a !== void 0 ? _a : {};
348
- }
349
- on(eventName, callback, context) {
350
- let event, node, tail, list;
351
- if (!callback) {
352
- return this;
353
- }
354
- eventName = eventName.split(Events.eventSplitter);
355
- this.callbacks || (this.callbacks = {});
356
- const calls = this.callbacks;
357
- while ((event = eventName.shift())) {
358
- list = calls[event];
359
- node = list ? list.tail : {};
360
- node.next = tail = {};
361
- node.context = context;
362
- node.callback = callback;
363
- calls[event] = {
364
- tail,
365
- next: list ? list.next : node
366
- };
367
- }
368
- return this;
369
- }
370
- once(events, callback, context) {
371
- const wrapper = (...args) => {
372
- callback.apply(this, args);
373
- this.off(events, wrapper, context);
374
- };
375
- this.on(events, wrapper, context);
376
- return this;
377
- }
378
- off(events, callback, context) {
379
- let event, calls, node, tail, cb, ctx;
380
- if (!(calls = this.callbacks)) {
381
- return this;
382
- }
383
- if (!(events || callback || context)) {
384
- delete this.callbacks;
385
- return this;
386
- }
387
- events = events ? events.split(Events.eventSplitter) : Object.keys(calls);
388
- while ((event = events.shift())) {
389
- node = calls[event];
390
- delete calls[event];
391
- if (!node || !(callback || context)) {
392
- continue;
393
- }
394
- tail = node.tail;
395
- while ((node = node.next) !== tail) {
396
- cb = node.callback;
397
- ctx = node.context;
398
- if ((callback && cb !== callback) || (context && ctx !== context)) {
399
- this.on(event, cb, ctx);
400
- }
401
- }
402
- }
403
- return this;
404
- }
405
- trigger(events) {
406
- let event, node, calls, tail;
407
- if (!(calls = this.callbacks)) {
408
- return this;
409
- }
410
- events = events.split(Events.eventSplitter);
411
- const rest = [].slice.call(arguments, 1);
412
- while ((event = events.shift())) {
413
- if ((node = calls[event])) {
414
- tail = node.tail;
415
- while ((node = node.next) !== tail) {
416
- node.callback.apply(node.context || this, rest);
417
- }
418
- }
419
- }
420
- return this;
421
- }
422
- }
344
+ class Events {
345
+ constructor(opts) {
346
+ var _a;
347
+ this.callbacks = (_a = opts === null || opts === void 0 ? void 0 : opts.callbacks) !== null && _a !== void 0 ? _a : {};
348
+ }
349
+ on(eventName, callback, context) {
350
+ let event, node, tail, list;
351
+ if (!callback) {
352
+ return this;
353
+ }
354
+ eventName = eventName.split(Events.eventSplitter);
355
+ this.callbacks || (this.callbacks = {});
356
+ const calls = this.callbacks;
357
+ while ((event = eventName.shift())) {
358
+ list = calls[event];
359
+ node = list ? list.tail : {};
360
+ node.next = tail = {};
361
+ node.context = context;
362
+ node.callback = callback;
363
+ calls[event] = {
364
+ tail,
365
+ next: list ? list.next : node
366
+ };
367
+ }
368
+ return this;
369
+ }
370
+ once(events, callback, context) {
371
+ const wrapper = (...args) => {
372
+ callback.apply(this, args);
373
+ this.off(events, wrapper, context);
374
+ };
375
+ this.on(events, wrapper, context);
376
+ return this;
377
+ }
378
+ off(events, callback, context) {
379
+ let event, calls, node, tail, cb, ctx;
380
+ if (!(calls = this.callbacks)) {
381
+ return this;
382
+ }
383
+ if (!(events || callback || context)) {
384
+ delete this.callbacks;
385
+ return this;
386
+ }
387
+ events = events ? events.split(Events.eventSplitter) : Object.keys(calls);
388
+ while ((event = events.shift())) {
389
+ node = calls[event];
390
+ delete calls[event];
391
+ if (!node || !(callback || context)) {
392
+ continue;
393
+ }
394
+ tail = node.tail;
395
+ while ((node = node.next) !== tail) {
396
+ cb = node.callback;
397
+ ctx = node.context;
398
+ if ((callback && cb !== callback) || (context && ctx !== context)) {
399
+ this.on(event, cb, ctx);
400
+ }
401
+ }
402
+ }
403
+ return this;
404
+ }
405
+ trigger(events) {
406
+ let event, node, calls, tail;
407
+ if (!(calls = this.callbacks)) {
408
+ return this;
409
+ }
410
+ events = events.split(Events.eventSplitter);
411
+ const rest = [].slice.call(arguments, 1);
412
+ while ((event = events.shift())) {
413
+ if ((node = calls[event])) {
414
+ tail = node.tail;
415
+ while ((node = node.next) !== tail) {
416
+ node.callback.apply(node.context || this, rest);
417
+ }
418
+ }
419
+ }
420
+ return this;
421
+ }
422
+ }
423
423
  Events.eventSplitter = /\s+/;
424
424
 
425
- var HOOK_TYPE;
426
- (function (HOOK_TYPE) {
427
- HOOK_TYPE[HOOK_TYPE["SINGLE"] = 0] = "SINGLE";
428
- HOOK_TYPE[HOOK_TYPE["MULTI"] = 1] = "MULTI";
429
- HOOK_TYPE[HOOK_TYPE["WATERFALL"] = 2] = "WATERFALL";
430
- })(HOOK_TYPE || (HOOK_TYPE = {}));
431
- const defaultMiniLifecycle = {
432
- app: [
433
- 'onLaunch',
434
- 'onShow',
435
- 'onHide'
436
- ],
437
- page: [
438
- 'onLoad',
439
- 'onUnload',
440
- 'onReady',
441
- 'onShow',
442
- 'onHide',
443
- [
444
- 'onPullDownRefresh',
445
- 'onReachBottom',
446
- 'onPageScroll',
447
- 'onResize',
448
- 'onTabItemTap',
449
- 'onTitleClick',
450
- 'onOptionMenuClick',
451
- 'onPopMenuClick',
452
- 'onPullIntercept',
453
- 'onAddToFavorites'
454
- ]
455
- ]
456
- };
457
- function TaroHook(type, initial) {
458
- return {
459
- type,
460
- initial: initial || null
461
- };
462
- }
463
- class TaroHooks extends Events {
464
- constructor(hooks, opts) {
465
- super(opts);
466
- this.hooks = hooks;
467
- for (const hookName in hooks) {
468
- const { initial } = hooks[hookName];
469
- if (isFunction(initial)) {
470
- this.on(hookName, initial);
471
- }
472
- }
473
- }
474
- tapOneOrMany(hookName, callback) {
475
- const list = isFunction(callback) ? [callback] : callback;
476
- list.forEach(cb => this.on(hookName, cb));
477
- }
478
- tap(hookName, callback) {
479
- const hooks = this.hooks;
480
- const { type, initial } = hooks[hookName];
481
- if (type === HOOK_TYPE.SINGLE) {
482
- this.off(hookName);
483
- this.on(hookName, isFunction(callback) ? callback : callback[callback.length - 1]);
484
- }
485
- else {
486
- initial && this.off(hookName, initial);
487
- this.tapOneOrMany(hookName, callback);
488
- }
489
- }
490
- call(hookName, ...rest) {
491
- var _a;
492
- const hook = this.hooks[hookName];
493
- if (!hook)
494
- return;
495
- const { type } = hook;
496
- const calls = this.callbacks;
497
- if (!calls)
498
- return;
499
- const list = calls[hookName];
500
- if (list) {
501
- const tail = list.tail;
502
- let node = list.next;
503
- let args = rest;
504
- let res;
505
- while (node !== tail) {
506
- res = (_a = node.callback) === null || _a === void 0 ? void 0 : _a.apply(node.context || this, args);
507
- if (type === HOOK_TYPE.WATERFALL) {
508
- const params = [res];
509
- args = params;
510
- }
511
- node = node.next;
512
- }
513
- return res;
514
- }
515
- }
516
- isExist(hookName) {
517
- var _a;
518
- return Boolean((_a = this.callbacks) === null || _a === void 0 ? void 0 : _a[hookName]);
519
- }
520
- }
521
- new TaroHooks({
522
- getMiniLifecycle: TaroHook(HOOK_TYPE.SINGLE, defaultConfig => defaultConfig),
523
- getMiniLifecycleImpl: TaroHook(HOOK_TYPE.SINGLE, function () {
524
- return this.call('getMiniLifecycle', defaultMiniLifecycle);
525
- }),
526
- getLifecycle: TaroHook(HOOK_TYPE.SINGLE, (instance, lifecycle) => instance[lifecycle]),
527
- getPathIndex: TaroHook(HOOK_TYPE.SINGLE, indexOfNode => `[${indexOfNode}]`),
528
- getEventCenter: TaroHook(HOOK_TYPE.SINGLE, Events => new Events()),
529
- isBubbleEvents: TaroHook(HOOK_TYPE.SINGLE, eventName => {
530
- /**
531
- * 支持冒泡的事件, 除 支付宝小程序外,其余的可冒泡事件都和微信保持一致
532
- * 详见 见 https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxml/event.html
533
- */
534
- const BUBBLE_EVENTS = new Set([
535
- 'touchstart',
536
- 'touchmove',
537
- 'touchcancel',
538
- 'touchend',
539
- 'touchforcechange',
540
- 'tap',
541
- 'longpress',
542
- 'longtap',
543
- 'transitionend',
544
- 'animationstart',
545
- 'animationiteration',
546
- 'animationend'
547
- ]);
548
- return BUBBLE_EVENTS.has(eventName);
549
- }),
550
- getSpecialNodes: TaroHook(HOOK_TYPE.SINGLE, () => ['view', 'text', 'image']),
551
- onRemoveAttribute: TaroHook(HOOK_TYPE.SINGLE),
552
- batchedEventUpdates: TaroHook(HOOK_TYPE.SINGLE),
553
- mergePageInstance: TaroHook(HOOK_TYPE.SINGLE),
554
- modifyPageObject: TaroHook(HOOK_TYPE.SINGLE),
555
- createPullDownComponent: TaroHook(HOOK_TYPE.SINGLE),
556
- getDOMNode: TaroHook(HOOK_TYPE.SINGLE),
557
- modifyHydrateData: TaroHook(HOOK_TYPE.SINGLE),
558
- modifySetAttrPayload: TaroHook(HOOK_TYPE.SINGLE),
559
- modifyRmAttrPayload: TaroHook(HOOK_TYPE.SINGLE),
560
- onAddEvent: TaroHook(HOOK_TYPE.SINGLE),
561
- modifyMpEvent: TaroHook(HOOK_TYPE.MULTI),
562
- modifyMpEventImpl: TaroHook(HOOK_TYPE.SINGLE, function (e) {
563
- try {
564
- // 有些小程序的事件对象的某些属性只读
565
- this.call('modifyMpEvent', e);
566
- }
567
- catch (error) {
568
- console.warn('[Taro modifyMpEvent hook Error]: ', error);
569
- }
570
- }),
571
- modifyTaroEvent: TaroHook(HOOK_TYPE.MULTI),
572
- modifyDispatchEvent: TaroHook(HOOK_TYPE.MULTI),
573
- initNativeApi: TaroHook(HOOK_TYPE.MULTI),
574
- patchElement: TaroHook(HOOK_TYPE.MULTI)
425
+ var HOOK_TYPE;
426
+ (function (HOOK_TYPE) {
427
+ HOOK_TYPE[HOOK_TYPE["SINGLE"] = 0] = "SINGLE";
428
+ HOOK_TYPE[HOOK_TYPE["MULTI"] = 1] = "MULTI";
429
+ HOOK_TYPE[HOOK_TYPE["WATERFALL"] = 2] = "WATERFALL";
430
+ })(HOOK_TYPE || (HOOK_TYPE = {}));
431
+ const defaultMiniLifecycle = {
432
+ app: [
433
+ 'onLaunch',
434
+ 'onShow',
435
+ 'onHide'
436
+ ],
437
+ page: [
438
+ 'onLoad',
439
+ 'onUnload',
440
+ 'onReady',
441
+ 'onShow',
442
+ 'onHide',
443
+ [
444
+ 'onPullDownRefresh',
445
+ 'onReachBottom',
446
+ 'onPageScroll',
447
+ 'onResize',
448
+ 'onTabItemTap',
449
+ 'onTitleClick',
450
+ 'onOptionMenuClick',
451
+ 'onPopMenuClick',
452
+ 'onPullIntercept',
453
+ 'onAddToFavorites'
454
+ ]
455
+ ]
456
+ };
457
+ function TaroHook(type, initial) {
458
+ return {
459
+ type,
460
+ initial: initial || null
461
+ };
462
+ }
463
+ class TaroHooks extends Events {
464
+ constructor(hooks, opts) {
465
+ super(opts);
466
+ this.hooks = hooks;
467
+ for (const hookName in hooks) {
468
+ const { initial } = hooks[hookName];
469
+ if (isFunction(initial)) {
470
+ this.on(hookName, initial);
471
+ }
472
+ }
473
+ }
474
+ tapOneOrMany(hookName, callback) {
475
+ const list = isFunction(callback) ? [callback] : callback;
476
+ list.forEach(cb => this.on(hookName, cb));
477
+ }
478
+ tap(hookName, callback) {
479
+ const hooks = this.hooks;
480
+ const { type, initial } = hooks[hookName];
481
+ if (type === HOOK_TYPE.SINGLE) {
482
+ this.off(hookName);
483
+ this.on(hookName, isFunction(callback) ? callback : callback[callback.length - 1]);
484
+ }
485
+ else {
486
+ initial && this.off(hookName, initial);
487
+ this.tapOneOrMany(hookName, callback);
488
+ }
489
+ }
490
+ call(hookName, ...rest) {
491
+ var _a;
492
+ const hook = this.hooks[hookName];
493
+ if (!hook)
494
+ return;
495
+ const { type } = hook;
496
+ const calls = this.callbacks;
497
+ if (!calls)
498
+ return;
499
+ const list = calls[hookName];
500
+ if (list) {
501
+ const tail = list.tail;
502
+ let node = list.next;
503
+ let args = rest;
504
+ let res;
505
+ while (node !== tail) {
506
+ res = (_a = node.callback) === null || _a === void 0 ? void 0 : _a.apply(node.context || this, args);
507
+ if (type === HOOK_TYPE.WATERFALL) {
508
+ const params = [res];
509
+ args = params;
510
+ }
511
+ node = node.next;
512
+ }
513
+ return res;
514
+ }
515
+ }
516
+ isExist(hookName) {
517
+ var _a;
518
+ return Boolean((_a = this.callbacks) === null || _a === void 0 ? void 0 : _a[hookName]);
519
+ }
520
+ }
521
+ new TaroHooks({
522
+ getMiniLifecycle: TaroHook(HOOK_TYPE.SINGLE, defaultConfig => defaultConfig),
523
+ getMiniLifecycleImpl: TaroHook(HOOK_TYPE.SINGLE, function () {
524
+ return this.call('getMiniLifecycle', defaultMiniLifecycle);
525
+ }),
526
+ getLifecycle: TaroHook(HOOK_TYPE.SINGLE, (instance, lifecycle) => instance[lifecycle]),
527
+ getPathIndex: TaroHook(HOOK_TYPE.SINGLE, indexOfNode => `[${indexOfNode}]`),
528
+ getEventCenter: TaroHook(HOOK_TYPE.SINGLE, Events => new Events()),
529
+ isBubbleEvents: TaroHook(HOOK_TYPE.SINGLE, eventName => {
530
+ /**
531
+ * 支持冒泡的事件, 除 支付宝小程序外,其余的可冒泡事件都和微信保持一致
532
+ * 详见 见 https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxml/event.html
533
+ */
534
+ const BUBBLE_EVENTS = new Set([
535
+ 'touchstart',
536
+ 'touchmove',
537
+ 'touchcancel',
538
+ 'touchend',
539
+ 'touchforcechange',
540
+ 'tap',
541
+ 'longpress',
542
+ 'longtap',
543
+ 'transitionend',
544
+ 'animationstart',
545
+ 'animationiteration',
546
+ 'animationend'
547
+ ]);
548
+ return BUBBLE_EVENTS.has(eventName);
549
+ }),
550
+ getSpecialNodes: TaroHook(HOOK_TYPE.SINGLE, () => ['view', 'text', 'image']),
551
+ onRemoveAttribute: TaroHook(HOOK_TYPE.SINGLE),
552
+ batchedEventUpdates: TaroHook(HOOK_TYPE.SINGLE),
553
+ mergePageInstance: TaroHook(HOOK_TYPE.SINGLE),
554
+ modifyPageObject: TaroHook(HOOK_TYPE.SINGLE),
555
+ createPullDownComponent: TaroHook(HOOK_TYPE.SINGLE),
556
+ getDOMNode: TaroHook(HOOK_TYPE.SINGLE),
557
+ modifyHydrateData: TaroHook(HOOK_TYPE.SINGLE),
558
+ modifySetAttrPayload: TaroHook(HOOK_TYPE.SINGLE),
559
+ modifyRmAttrPayload: TaroHook(HOOK_TYPE.SINGLE),
560
+ onAddEvent: TaroHook(HOOK_TYPE.SINGLE),
561
+ modifyMpEvent: TaroHook(HOOK_TYPE.MULTI),
562
+ modifyMpEventImpl: TaroHook(HOOK_TYPE.SINGLE, function (e) {
563
+ try {
564
+ // 有些小程序的事件对象的某些属性只读
565
+ this.call('modifyMpEvent', e);
566
+ }
567
+ catch (error) {
568
+ console.warn('[Taro modifyMpEvent hook Error]: ', error);
569
+ }
570
+ }),
571
+ modifyTaroEvent: TaroHook(HOOK_TYPE.MULTI),
572
+ modifyDispatchEvent: TaroHook(HOOK_TYPE.MULTI),
573
+ initNativeApi: TaroHook(HOOK_TYPE.MULTI),
574
+ patchElement: TaroHook(HOOK_TYPE.MULTI)
575
575
  });
576
576
 
577
- function toDashed(s) {
578
- return s.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
579
- }
580
- function toCamelCase(s) {
581
- let camel = '';
582
- let nextCap = false;
583
- for (let i = 0; i < s.length; i++) {
584
- if (s[i] !== '-') {
585
- camel += nextCap ? s[i].toUpperCase() : s[i];
586
- nextCap = false;
587
- }
588
- else {
589
- nextCap = true;
590
- }
591
- }
592
- return camel;
593
- }
594
- const toKebabCase = function (string) {
595
- return string.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
596
- };
597
- function capitalize(s) {
598
- return s.charAt(0).toUpperCase() + s.slice(1);
599
- }
600
- const hasOwnProperty = Object.prototype.hasOwnProperty;
601
- const hasOwn = (val, key) => hasOwnProperty.call(val, key);
602
- (new Date()).getTime().toString();
603
- function indent(str, size) {
604
- return str.split('\n')
605
- .map((line, index) => {
606
- const indent = index === 0 ? '' : Array(size).fill(' ').join('');
607
- return indent + line;
608
- })
609
- .join('\n');
577
+ function toDashed(s) {
578
+ return s.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
579
+ }
580
+ function toCamelCase(s) {
581
+ let camel = '';
582
+ let nextCap = false;
583
+ for (let i = 0; i < s.length; i++) {
584
+ if (s[i] !== '-') {
585
+ camel += nextCap ? s[i].toUpperCase() : s[i];
586
+ nextCap = false;
587
+ }
588
+ else {
589
+ nextCap = true;
590
+ }
591
+ }
592
+ return camel;
593
+ }
594
+ const toKebabCase = function (string) {
595
+ return string.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
596
+ };
597
+ function capitalize(s) {
598
+ return s.charAt(0).toUpperCase() + s.slice(1);
599
+ }
600
+ const hasOwnProperty = Object.prototype.hasOwnProperty;
601
+ const hasOwn = (val, key) => hasOwnProperty.call(val, key);
602
+ (new Date()).getTime().toString();
603
+ function getComponentsAlias(origin) {
604
+ const mapping = {};
605
+ const viewAttrs = origin.View;
606
+ const extraList = {
607
+ '#text': {},
608
+ StaticView: viewAttrs,
609
+ StaticImage: origin.Image,
610
+ StaticText: origin.Text,
611
+ PureView: viewAttrs,
612
+ CatchView: viewAttrs
613
+ };
614
+ origin = Object.assign(Object.assign({}, origin), extraList);
615
+ Object.keys(origin)
616
+ .sort((a, b) => {
617
+ const reg = /^(Static|Pure|Catch)*(View|Image|Text)$/;
618
+ if (reg.test(a)) {
619
+ return -1;
620
+ }
621
+ else if (reg.test(b)) {
622
+ return 1;
623
+ }
624
+ else {
625
+ return a >= b ? 1 : -1;
626
+ }
627
+ })
628
+ .forEach((key, num) => {
629
+ const obj = {
630
+ _num: String(num)
631
+ };
632
+ Object.keys(origin[key])
633
+ .filter(attr => !(/^bind/.test(attr)) && !['focus', 'blur'].includes(attr))
634
+ .sort()
635
+ .forEach((attr, index) => {
636
+ obj[toCamelCase(attr)] = 'p' + index;
637
+ });
638
+ mapping[toDashed(key)] = obj;
639
+ });
640
+ return mapping;
641
+ }
642
+ function indent(str, size) {
643
+ return str.split('\n')
644
+ .map((line, index) => {
645
+ const indent = index === 0 ? '' : Array(size).fill(' ').join('');
646
+ return indent + line;
647
+ })
648
+ .join('\n');
610
649
  }
611
650
 
612
- /**
613
- * 这里我们需要关心的小程序种类有两类:
614
- * 1. 模板递归:
615
- * - 支持:tmpl0 套 tmpl0
616
- * - 不支持:这就使得我们必须生成多级的模板,tmpl0 套 tmpl1,tmpl1 套 tmpl2……
617
- * 直到超过阈值 N (N = config.miniapp.baseLevel) tmplN 会套组件 comp,组件 comp 重新再套 tmpl0。
618
- * 2. 小程序脚本语言(wxs, sjs, etc...):
619
- * - 支持:可以在模板使用函数缩减模板大小或提高性能(存疑),例如判断一个值是不是假值(falsy value)。
620
- * 将来或许会把数据序列化^1 的操作也放到小程序脚本语言里。
621
- * - 不支持:使用纯 *xml 语法
622
- *
623
- * ^1: packages/taro-runtime/src/hydrate.ts
624
- */
625
- const styles = {
626
- style: `i.${"st" /* Style */}`,
627
- class: `i.${"cl" /* Class */}`
628
- };
629
- const events = {
630
- bindtap: 'eh'
631
- };
632
- const weixinAdapter = {
633
- if: 'wx:if',
634
- else: 'wx:else',
635
- elseif: 'wx:elif',
636
- for: 'wx:for',
637
- forItem: 'wx:for-item',
638
- forIndex: 'wx:for-index',
639
- key: 'wx:key',
640
- xs: 'wxs',
641
- type: 'weapp'
642
- };
643
- class BaseTemplate {
644
- constructor() {
645
- this.exportExpr = 'module.exports =';
646
- this.supportXS = false;
647
- this.thirdPartyPatcher = {};
648
- this.Adapter = weixinAdapter;
649
- /** 组件列表 */
650
- this.internalComponents = internalComponents;
651
- /** 可以 focus 聚焦的组件 */
652
- this.focusComponents = focusComponents;
653
- /** 不需要渲染子节点的元素 */
654
- this.voidElements = voidElements;
655
- /** 可以递归调用自身的组件 */
656
- this.nestElements = nestElements;
657
- this.buildPageTemplate = (baseTempPath) => {
651
+ /**
652
+ * 这里我们需要关心的小程序种类有两类:
653
+ * 1. 模板递归:
654
+ * - 支持:tmpl0 套 tmpl0
655
+ * - 不支持:这就使得我们必须生成多级的模板,tmpl0 套 tmpl1,tmpl1 套 tmpl2……
656
+ * 直到超过阈值 N (N = config.miniapp.baseLevel) tmplN 会套组件 comp,组件 comp 重新再套 tmpl0。
657
+ * 2. 小程序脚本语言(wxs, sjs, etc...):
658
+ * - 支持:可以在模板使用函数缩减模板大小或提高性能(存疑),例如判断一个值是不是假值(falsy value)。
659
+ * 将来或许会把数据序列化^1 的操作也放到小程序脚本语言里。
660
+ * - 不支持:使用纯 *xml 语法
661
+ *
662
+ * ^1: packages/taro-runtime/src/hydrate.ts
663
+ */
664
+ const styles = {
665
+ style: `i.${"st" /* Shortcuts.Style */}`,
666
+ class: `i.${"cl" /* Shortcuts.Class */}`
667
+ };
668
+ const events = {
669
+ bindtap: 'eh'
670
+ };
671
+ const weixinAdapter = {
672
+ if: 'wx:if',
673
+ else: 'wx:else',
674
+ elseif: 'wx:elif',
675
+ for: 'wx:for',
676
+ forItem: 'wx:for-item',
677
+ forIndex: 'wx:for-index',
678
+ key: 'wx:key',
679
+ xs: 'wxs',
680
+ type: 'weapp'
681
+ };
682
+ class BaseTemplate {
683
+ constructor() {
684
+ this.exportExpr = 'module.exports =';
685
+ this.supportXS = false;
686
+ this.thirdPartyPatcher = {};
687
+ this.Adapter = weixinAdapter;
688
+ /** 组件列表 */
689
+ this.internalComponents = internalComponents;
690
+ /** 可以 focus 聚焦的组件 */
691
+ this.focusComponents = focusComponents;
692
+ /** 不需要渲染子节点的元素 */
693
+ this.voidElements = voidElements;
694
+ /** 可以递归调用自身的组件 */
695
+ this.nestElements = nestElements;
696
+ this.buildPageTemplate = (baseTempPath) => {
658
697
  const template = `<import src="${baseTempPath}"/>
659
- <template is="taro_tmpl" data="{{${this.dataKeymap('root:root')}}}" />`;
660
- return template;
661
- };
662
- this.buildBaseComponentTemplate = (ext) => {
663
- const data = !this.isSupportRecursive && this.supportXS
664
- ? this.dataKeymap('i:i,l:l')
665
- : this.dataKeymap('i:i');
698
+ <template is="taro_tmpl" data="{{${this.dataKeymap('root:root')}}}" />`;
699
+ return template;
700
+ };
701
+ this.buildBaseComponentTemplate = (ext) => {
702
+ const data = !this.isSupportRecursive && this.supportXS
703
+ ? this.dataKeymap('i:i,l:l')
704
+ : this.dataKeymap('i:i');
666
705
  return `<import src="./base${ext}" />
667
- <template is="tmpl_0_${"container" /* Container */}" data="{{${data}}}" />`;
668
- };
669
- this.buildCustomComponentTemplate = (ext) => {
670
- const Adapter = this.Adapter;
671
- const data = !this.isSupportRecursive && this.supportXS
672
- ? `${this.dataKeymap('i:item,l:\'\'')}`
673
- : this.dataKeymap('i:item');
706
+ <template is="tmpl_0_${"container" /* Shortcuts.Container */}" data="{{${data}}}" />`;
707
+ };
708
+ this.buildCustomComponentTemplate = (ext) => {
709
+ const Adapter = this.Adapter;
710
+ const data = !this.isSupportRecursive && this.supportXS
711
+ ? `${this.dataKeymap('i:item,l:\'\'')}`
712
+ : this.dataKeymap('i:item');
674
713
  return `<import src="./base${ext}" />
675
- <block ${Adapter.for}="{{i.${"cn" /* Childnodes */}}}" ${Adapter.key}="sid">
714
+ <block ${Adapter.for}="{{i.${"cn" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="sid">
676
715
  <template is="tmpl_0_container" data="{{${data}}}" />
677
- </block>`;
678
- };
679
- this.buildXScript = () => {
716
+ </block>`;
717
+ };
718
+ this.buildXScript = () => {
680
719
  return `${this.exportExpr} {
681
720
  a: ${this.buildXSTmplName()},
682
721
  b: function (a, b) {
683
722
  return a === undefined ? b : a
684
723
  },
685
- c: ${this.buildXSTepFocus("nn" /* NodeName */)},
724
+ c: ${this.buildXSTepFocus("nn" /* Shortcuts.NodeName */)},
686
725
  d: function (i, v) {
687
726
  return i === undefined ? v : i
688
727
  },
689
728
  e: function (n) {
690
- return 'tmpl_' + n + '_${"container" /* Container */}'
729
+ return 'tmpl_' + n + '_${"container" /* Shortcuts.Container */}'
691
730
  },
692
731
  ${this.buildXSTmpExtra()}
693
- }`;
694
- };
695
- }
696
- buildAttribute(attrs, nodeName) {
697
- return Object.keys(attrs)
698
- .map(k => `${k}="${k.startsWith('bind') || k.startsWith('on') || k.startsWith('catch') ? attrs[k] : `{${this.getAttrValue(attrs[k], k, nodeName)}}`}" `)
699
- .join('');
700
- }
701
- replacePropName(name, value, _componentName) {
702
- if (value === 'eh')
703
- return name.toLowerCase();
704
- return name;
705
- }
706
- createMiniComponents(components) {
707
- const result = Object.create(null);
708
- for (const key in components) {
709
- if (hasOwn(components, key)) {
710
- let component = components[key];
711
- const compName = toDashed(key);
712
- const newComp = Object.create(null);
713
- if (isFunction(this.modifyCompProps)) {
714
- component = this.modifyCompProps(compName, component);
715
- }
716
- for (let prop in component) {
717
- if (hasOwn(component, prop)) {
718
- let propValue = component[prop];
719
- if (prop.startsWith('bind') || propValue === 'eh') {
720
- propValue = 'eh';
721
- }
722
- else if (propValue === '') {
723
- propValue = `i.${toCamelCase(prop)}`;
724
- }
725
- else if (isBooleanStringLiteral(propValue) || isNumber(+propValue)) {
726
- propValue = this.supportXS
727
- ? `xs.b(i.${toCamelCase(prop)},${propValue})`
728
- : `i.${toCamelCase(prop)}===undefined?${propValue}:i.${toCamelCase(prop)}`;
729
- }
730
- else {
731
- propValue = `i.${toCamelCase(prop)}||${propValue || singleQuote('')}`;
732
- }
733
- prop = this.replacePropName(prop, propValue, compName);
734
- newComp[prop] = propValue;
735
- }
736
- }
737
- if (compName !== 'block') {
738
- Object.assign(newComp, styles, this.getEvents());
739
- }
740
- if (compName === 'swiper-item') {
741
- delete newComp.style;
742
- }
743
- if (compName === 'view') {
744
- const reg = /^(bind|on)(touchmove|TouchMove)$/;
745
- const comp = Object.assign({}, newComp);
746
- Object.keys(comp).forEach(originKey => {
747
- if (!reg.test(originKey))
748
- return;
749
- const key = originKey.replace(reg, 'catch$2');
750
- comp[key] = comp[originKey];
751
- delete comp[originKey];
752
- });
753
- result['catch-view'] = comp;
754
- }
755
- if (compName === 'view' || compName === 'text' || compName === 'image') {
756
- const comp = {};
757
- Object.keys(newComp).forEach(key => {
758
- const value = newComp[key];
759
- if (value !== 'eh')
760
- comp[key] = value;
761
- });
762
- result[`static-${compName}`] = comp;
763
- if (compName === 'view') {
764
- result['pure-view'] = {
765
- style: comp.style,
766
- class: comp.class
767
- };
768
- }
769
- }
770
- if (compName === 'slot' || compName === 'slot-view') {
771
- result[compName] = Object.assign({ slot: 'i.name' }, styles);
772
- }
773
- else {
774
- result[compName] = newComp;
775
- }
776
- }
777
- }
778
- return result;
779
- }
780
- buildBaseTemplate() {
781
- const Adapter = this.Adapter;
782
- const data = !this.isSupportRecursive && this.supportXS
783
- ? `${this.dataKeymap('i:item,l:\'\'')}`
784
- : this.dataKeymap('i:item');
732
+ }`;
733
+ };
734
+ }
735
+ buildAttribute(attrs, nodeName) {
736
+ return Object.keys(attrs)
737
+ .map(k => `${k}="${k.startsWith('bind') || k.startsWith('on') || k.startsWith('catch') ? attrs[k] : `{${this.getAttrValue(attrs[k], k, nodeName)}}`}" `)
738
+ .join('');
739
+ }
740
+ replacePropName(name, value, _componentName, _componentAlias) {
741
+ if (value === 'eh')
742
+ return name.toLowerCase();
743
+ return name;
744
+ }
745
+ createMiniComponents(components) {
746
+ const result = Object.create(null);
747
+ for (const key in components) {
748
+ if (hasOwn(components, key)) {
749
+ let component = components[key];
750
+ const compName = toDashed(key);
751
+ const newComp = Object.create(null);
752
+ const componentAlias = this.componentsAlias[compName];
753
+ if (isFunction(this.modifyCompProps)) {
754
+ component = this.modifyCompProps(compName, component);
755
+ }
756
+ for (let prop in component) {
757
+ if (hasOwn(component, prop)) {
758
+ let propValue = component[prop];
759
+ if (prop.startsWith('bind') || propValue === 'eh') {
760
+ propValue = 'eh';
761
+ }
762
+ else if (propValue === '') {
763
+ const propInCamelCase = toCamelCase(prop);
764
+ const propAlias = componentAlias[propInCamelCase] || propInCamelCase;
765
+ propValue = `i.${propAlias}`;
766
+ }
767
+ else if (isBooleanStringLiteral(propValue) || isNumber(+propValue)) {
768
+ const propInCamelCase = toCamelCase(prop);
769
+ const propAlias = componentAlias[propInCamelCase] || propInCamelCase;
770
+ propValue = this.supportXS
771
+ ? `xs.b(i.${propAlias},${propValue})`
772
+ : `i.${propAlias}===undefined?${propValue}:i.${propAlias}`;
773
+ }
774
+ else {
775
+ const propInCamelCase = toCamelCase(prop);
776
+ const propAlias = componentAlias[propInCamelCase] || propInCamelCase;
777
+ propValue = `i.${propAlias}||${propValue || singleQuote('')}`;
778
+ }
779
+ prop = this.replacePropName(prop, propValue, compName, componentAlias);
780
+ newComp[prop] = propValue;
781
+ }
782
+ }
783
+ if (compName !== 'block') {
784
+ Object.assign(newComp, styles, this.getEvents());
785
+ }
786
+ if (compName === 'swiper-item') {
787
+ delete newComp.style;
788
+ }
789
+ if (compName === 'view') {
790
+ const reg = /^(bind|on)(touchmove|TouchMove)$/;
791
+ const comp = Object.assign({}, newComp);
792
+ Object.keys(comp).forEach(originKey => {
793
+ if (!reg.test(originKey))
794
+ return;
795
+ const key = originKey.replace(reg, 'catch$2');
796
+ comp[key] = comp[originKey];
797
+ delete comp[originKey];
798
+ });
799
+ result['catch-view'] = comp;
800
+ }
801
+ if (compName === 'view' || compName === 'text' || compName === 'image') {
802
+ const comp = {};
803
+ Object.keys(newComp).forEach(key => {
804
+ const value = newComp[key];
805
+ if (value !== 'eh')
806
+ comp[key] = value;
807
+ });
808
+ result[`static-${compName}`] = comp;
809
+ if (compName === 'view') {
810
+ result['pure-view'] = {
811
+ style: comp.style,
812
+ class: comp.class
813
+ };
814
+ }
815
+ }
816
+ if (compName === 'slot' || compName === 'slot-view') {
817
+ result[compName] = Object.assign({ slot: 'i.name' }, styles);
818
+ }
819
+ else {
820
+ result[compName] = newComp;
821
+ }
822
+ }
823
+ }
824
+ return result;
825
+ }
826
+ buildBaseTemplate() {
827
+ const Adapter = this.Adapter;
828
+ const data = !this.isSupportRecursive && this.supportXS
829
+ ? `${this.dataKeymap('i:item,l:\'\'')}`
830
+ : this.dataKeymap('i:item');
785
831
  return `${this.buildXsTemplate()}
786
832
  <template name="taro_tmpl">
787
833
  <block ${Adapter.for}="{{root.cn}}" ${Adapter.key}="sid">
788
- <template is="tmpl_0_${"container" /* Container */}" data="{{${data}}}" />
834
+ <template is="tmpl_0_${"container" /* Shortcuts.Container */}" data="{{${data}}}" />
789
835
  </block>
790
836
  </template>
791
- `;
792
- }
793
- buildThirdPartyAttr(attrs, patcher = {}) {
794
- return Array.from(attrs).reduce((str, attr) => {
795
- if (attr.startsWith('@')) {
796
- // vue2
797
- let value = attr.slice(1);
798
- if (value.indexOf('-') > -1) {
799
- value = `:${value}`;
800
- }
801
- return str + `bind${value}="eh" `;
802
- }
803
- else if (attr.startsWith('bind')) {
804
- return str + `${attr}="eh" `;
805
- }
806
- else if (attr.startsWith('on')) {
807
- // react, vue3
808
- let value = toKebabCase(attr.slice(2));
809
- if (value.indexOf('-') > -1) {
810
- // 兼容如 vant 某些组件的 bind:a-b 这类属性
811
- value = `:${value}`;
812
- }
813
- return str + `bind${value}="eh" `;
814
- }
815
- else if (attr === 'class') {
816
- return str + `class="{{i.${"cl" /* Class */}}}" `;
817
- }
818
- else if (attr === 'style') {
819
- return str + `style="{{i.${"st" /* Style */}}}" `;
820
- }
821
- const patchValue = patcher[attr];
822
- if (isBooleanStringLiteral(patchValue) || isNumber(patchValue) || isString(patchValue)) {
823
- const propValue = this.supportXS
824
- ? `xs.b(i.${toCamelCase(attr)},${patchValue})`
825
- : `i.${toCamelCase(attr)}===undefined?${patchValue}:i.${toCamelCase(attr)}`;
826
- return str + `${attr}="{{${propValue}}}" `;
827
- }
828
- return str + `${attr}="{{i.${toCamelCase(attr)}}}" `;
829
- }, '');
830
- }
831
- buildComponentTemplate(comp, level) {
832
- return this.focusComponents.has(comp.nodeName)
833
- ? this.buildFocusComponentTemplte(comp, level)
834
- : this.buildStandardComponentTemplate(comp, level);
835
- }
836
- getChildren(comp, level) {
837
- const { isSupportRecursive, Adapter, supportXS } = this;
838
- const nextLevel = isSupportRecursive ? 0 : level + 1;
839
- const data = !this.isSupportRecursive && supportXS
840
- ? `${this.dataKeymap('i:item,l:l')}`
841
- : this.dataKeymap('i:item');
842
- let child = supportXS
843
- ? `<template is="{{xs.e(${isSupportRecursive ? 0 : 'cid+1'})}}" data="{{${data}}}" />`
844
- : `<template is="tmpl_${nextLevel}_${"container" /* Container */}" data="{{${data}}}" />`;
845
- if (isFunction(this.modifyLoopBody)) {
846
- child = this.modifyLoopBody(child, comp.nodeName);
847
- }
848
- let children = this.voidElements.has(comp.nodeName)
849
- ? ''
837
+ `;
838
+ }
839
+ buildThirdPartyAttr(attrs, patcher = {}) {
840
+ return Array.from(attrs).reduce((str, attr) => {
841
+ if (attr.startsWith('@')) {
842
+ // vue2
843
+ let value = attr.slice(1);
844
+ if (value.indexOf('-') > -1) {
845
+ value = `:${value}`;
846
+ }
847
+ return str + `bind${value}="eh" `;
848
+ }
849
+ else if (attr.startsWith('bind')) {
850
+ return str + `${attr}="eh" `;
851
+ }
852
+ else if (attr.startsWith('on')) {
853
+ // react, vue3
854
+ let value = toKebabCase(attr.slice(2));
855
+ if (value.indexOf('-') > -1) {
856
+ // 兼容如 vant 某些组件的 bind:a-b 这类属性
857
+ value = `:${value}`;
858
+ }
859
+ return str + `bind${value}="eh" `;
860
+ }
861
+ else if (attr === 'class') {
862
+ return str + `class="{{i.${"cl" /* Shortcuts.Class */}}}" `;
863
+ }
864
+ else if (attr === 'style') {
865
+ return str + `style="{{i.${"st" /* Shortcuts.Style */}}}" `;
866
+ }
867
+ const patchValue = patcher[attr];
868
+ if (isBooleanStringLiteral(patchValue) || isNumber(patchValue) || isString(patchValue)) {
869
+ const propValue = this.supportXS
870
+ ? `xs.b(i.${toCamelCase(attr)},${patchValue})`
871
+ : `i.${toCamelCase(attr)}===undefined?${patchValue}:i.${toCamelCase(attr)}`;
872
+ return str + `${attr}="{{${propValue}}}" `;
873
+ }
874
+ return str + `${attr}="{{i.${toCamelCase(attr)}}}" `;
875
+ }, '');
876
+ }
877
+ buildComponentTemplate(comp, level) {
878
+ return this.focusComponents.has(comp.nodeName)
879
+ ? this.buildFocusComponentTemplte(comp, level)
880
+ : this.buildStandardComponentTemplate(comp, level);
881
+ }
882
+ getChildren(comp, level) {
883
+ const { isSupportRecursive, Adapter, supportXS } = this;
884
+ const nextLevel = isSupportRecursive ? 0 : level + 1;
885
+ const data = !this.isSupportRecursive && supportXS
886
+ ? `${this.dataKeymap('i:item,l:l')}`
887
+ : this.dataKeymap('i:item');
888
+ let child = supportXS
889
+ ? `<template is="{{xs.e(${isSupportRecursive ? 0 : 'cid+1'})}}" data="{{${data}}}" />`
890
+ : `<template is="tmpl_${nextLevel}_${"container" /* Shortcuts.Container */}" data="{{${data}}}" />`;
891
+ if (isFunction(this.modifyLoopBody)) {
892
+ child = this.modifyLoopBody(child, comp.nodeName);
893
+ }
894
+ let children = this.voidElements.has(comp.nodeName)
895
+ ? ''
850
896
  : `
851
- <block ${Adapter.for}="{{i.${"cn" /* Childnodes */}}}" ${Adapter.key}="sid">
897
+ <block ${Adapter.for}="{{i.${"cn" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="sid">
852
898
  ${indent(child, 6)}
853
899
  </block>
854
- `;
855
- if (isFunction(this.modifyLoopContainer)) {
856
- children = this.modifyLoopContainer(children, comp.nodeName);
857
- }
858
- return children;
859
- }
860
- buildFocusComponentTemplte(comp, level) {
861
- const children = this.getChildren(comp, level);
862
- const attrs = Object.assign({}, comp.attributes);
863
- const templateName = this.supportXS
864
- ? `xs.c(i, 'tmpl_${level}_')`
865
- : `i.focus ? 'tmpl_${level}_${comp.nodeName}_focus' : 'tmpl_${level}_${comp.nodeName}_blur'`;
866
- delete attrs.focus;
900
+ `;
901
+ if (isFunction(this.modifyLoopContainer)) {
902
+ children = this.modifyLoopContainer(children, comp.nodeName);
903
+ }
904
+ return children;
905
+ }
906
+ buildFocusComponentTemplte(comp, level) {
907
+ const children = this.getChildren(comp, level);
908
+ const nodeName = comp.nodeName;
909
+ const nodeAlias = comp.nodeAlias;
910
+ const attrs = Object.assign({}, comp.attributes);
911
+ const templateName = this.supportXS
912
+ ? `xs.c(i, 'tmpl_${level}_')`
913
+ : `i.focus ? 'tmpl_${level}_${nodeAlias}_focus' : 'tmpl_${level}_${nodeAlias}_blur'`;
914
+ delete attrs.focus;
867
915
  let res = `
868
- <template name="tmpl_${level}_${comp.nodeName}">
916
+ <template name="tmpl_${level}_${nodeAlias}">
869
917
  <template is="{{${templateName}}}" data="{{${this.dataKeymap('i:i')}${children ? ',cid:cid' : ''}}}" />
870
918
  </template>
871
919
 
872
- <template name="tmpl_${level}_${comp.nodeName}_focus">
873
- <${comp.nodeName} ${this.buildAttribute(comp.attributes, comp.nodeName)} id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">${children}</${comp.nodeName}>
920
+ <template name="tmpl_${level}_${nodeAlias}_focus">
921
+ <${nodeName} ${this.buildAttribute(comp.attributes, nodeName)} id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">${children}</${nodeName}>
874
922
  </template>
875
923
 
876
- <template name="tmpl_${level}_${comp.nodeName}_blur">
877
- <${comp.nodeName} ${this.buildAttribute(attrs, comp.nodeName)} id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">${children}</${comp.nodeName}>
924
+ <template name="tmpl_${level}_${nodeAlias}_blur">
925
+ <${nodeName} ${this.buildAttribute(attrs, nodeName)} id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">${children}</${nodeName}>
878
926
  </template>
879
- `;
880
- if (isFunction(this.modifyTemplateResult)) {
881
- res = this.modifyTemplateResult(res, comp.nodeName, level, children);
882
- }
883
- return res;
884
- }
885
- buildStandardComponentTemplate(comp, level) {
886
- const children = this.getChildren(comp, level);
887
- let nodeName = '';
888
- switch (comp.nodeName) {
889
- case 'slot':
890
- case 'slot-view':
891
- case 'catch-view':
892
- case 'static-view':
893
- case 'pure-view':
894
- nodeName = 'view';
895
- break;
896
- case 'static-text':
897
- nodeName = 'text';
898
- break;
899
- case 'static-image':
900
- nodeName = 'image';
901
- break;
902
- default:
903
- nodeName = comp.nodeName;
904
- break;
905
- }
927
+ `;
928
+ if (isFunction(this.modifyTemplateResult)) {
929
+ res = this.modifyTemplateResult(res, nodeName, level, children);
930
+ }
931
+ return res;
932
+ }
933
+ buildStandardComponentTemplate(comp, level) {
934
+ const children = this.getChildren(comp, level);
935
+ const nodeAlias = comp.nodeAlias;
936
+ let nodeName = '';
937
+ switch (comp.nodeName) {
938
+ case 'slot':
939
+ case 'slot-view':
940
+ case 'catch-view':
941
+ case 'static-view':
942
+ case 'pure-view':
943
+ nodeName = 'view';
944
+ break;
945
+ case 'static-text':
946
+ nodeName = 'text';
947
+ break;
948
+ case 'static-image':
949
+ nodeName = 'image';
950
+ break;
951
+ default:
952
+ nodeName = comp.nodeName;
953
+ break;
954
+ }
906
955
  let res = `
907
- <template name="tmpl_${level}_${comp.nodeName}">
956
+ <template name="tmpl_${level}_${nodeAlias}">
908
957
  <${nodeName} ${this.buildAttribute(comp.attributes, comp.nodeName)} id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">${children}</${nodeName}>
909
958
  </template>
910
- `;
911
- if (isFunction(this.modifyTemplateResult)) {
912
- res = this.modifyTemplateResult(res, comp.nodeName, level, children);
913
- }
914
- return res;
915
- }
916
- buildPlainTextTemplate(level) {
959
+ `;
960
+ if (isFunction(this.modifyTemplateResult)) {
961
+ res = this.modifyTemplateResult(res, comp.nodeName, level, children);
962
+ }
963
+ return res;
964
+ }
965
+ buildPlainTextTemplate(level) {
917
966
  return `
918
- <template name="tmpl_${level}_#text">
919
- <block>{{i.${"v" /* Text */}}}</block>
967
+ <template name="tmpl_${level}_${this.componentsAlias['#text']._num}">
968
+ <block>{{i.${"v" /* Shortcuts.Text */}}}</block>
920
969
  </template>
921
- `;
922
- }
923
- buildThirdPartyTemplate(level, componentConfig) {
924
- const { Adapter, isSupportRecursive, supportXS, nestElements } = this;
925
- const nextLevel = isSupportRecursive ? 0 : level + 1;
926
- let template = '';
927
- const data = !isSupportRecursive && supportXS
928
- ? `${this.dataKeymap('i:item,l:l')}`
929
- : this.dataKeymap('i:item');
930
- componentConfig.thirdPartyComponents.forEach((attrs, compName) => {
931
- if (compName === 'custom-wrapper') {
970
+ `;
971
+ }
972
+ buildThirdPartyTemplate(level, componentConfig) {
973
+ const { Adapter, isSupportRecursive, supportXS, nestElements } = this;
974
+ const nextLevel = isSupportRecursive ? 0 : level + 1;
975
+ let template = '';
976
+ const data = !isSupportRecursive && supportXS
977
+ ? `${this.dataKeymap('i:item,l:l')}`
978
+ : this.dataKeymap('i:item');
979
+ componentConfig.thirdPartyComponents.forEach((attrs, compName) => {
980
+ if (compName === 'custom-wrapper') {
932
981
  template += `
933
982
  <template name="tmpl_${level}_${compName}">
934
983
  <${compName} i="{{i}}" l="{{l}}" id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">
935
984
  </${compName}>
936
985
  </template>
937
- `;
938
- }
939
- else {
940
- if (!isSupportRecursive && supportXS && nestElements.has(compName) && level + 1 > nestElements.get(compName))
941
- return;
942
- let child = supportXS
943
- ? `<template is="{{xs.e(${isSupportRecursive ? 0 : 'cid+1'})}}" data="{{${data}}}" />`
944
- : `<template is="tmpl_${nextLevel}_${"container" /* Container */}" data="{{${data}}}" />`;
945
- if (isFunction(this.modifyThirdPartyLoopBody)) {
946
- child = this.modifyThirdPartyLoopBody(child, compName);
947
- }
986
+ `;
987
+ }
988
+ else {
989
+ if (!isSupportRecursive && supportXS && nestElements.has(compName) && level + 1 > nestElements.get(compName))
990
+ return;
991
+ let child = supportXS
992
+ ? `<template is="{{xs.e(${isSupportRecursive ? 0 : 'cid+1'})}}" data="{{${data}}}" />`
993
+ : `<template is="tmpl_${nextLevel}_${"container" /* Shortcuts.Container */}" data="{{${data}}}" />`;
994
+ if (isFunction(this.modifyThirdPartyLoopBody)) {
995
+ child = this.modifyThirdPartyLoopBody(child, compName);
996
+ }
948
997
  template += `
949
998
  <template name="tmpl_${level}_${compName}">
950
999
  <${compName} ${this.buildThirdPartyAttr(attrs, this.thirdPartyPatcher[compName] || {})} id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">
951
- <block ${Adapter.for}="{{i.${"cn" /* Childnodes */}}}" ${Adapter.key}="sid">
1000
+ <block ${Adapter.for}="{{i.${"cn" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="sid">
952
1001
  ${child}
953
1002
  </block>
954
1003
  </${compName}>
955
1004
  </template>
956
- `;
957
- }
958
- });
959
- return template;
960
- }
961
- buildContainerTemplate(level, restart = false) {
962
- let tmpl = '';
963
- if (restart) {
1005
+ `;
1006
+ }
1007
+ });
1008
+ return template;
1009
+ }
1010
+ buildContainerTemplate(level, restart = false) {
1011
+ let tmpl = '';
1012
+ if (restart) {
964
1013
  tmpl = `<block ${this.Adapter.if}="{{i.nn === '#text'}}">
965
1014
  <template is="tmpl_0_#text" data="{{i:i}}" />
966
1015
  </block>
967
1016
  <block ${this.Adapter.else}>
968
1017
  ${!this.isSupportRecursive && this.supportXS ? '<comp i="{{i}}" l="{{l}}" />' : '<comp i="{{i}}" />'}
969
- </block>`;
970
- }
971
- else {
972
- const xs = !this.isSupportRecursive
973
- ? `xs.a(${level}, i.${"nn" /* NodeName */}, l)`
974
- : `xs.a(${level}, i.${"nn" /* NodeName */})`;
975
- const data = !this.isSupportRecursive
976
- ? `${this.dataKeymap(`i:i,cid:${level},l:xs.f(l,i.${"nn" /* NodeName */})`)}`
977
- : `${this.dataKeymap('i:i')}`;
978
- tmpl = this.supportXS
979
- ? `<template is="{{${xs}}}" data="{{${data}}}" />`
980
- : `<template is="{{'tmpl_${level}_' + i.${"nn" /* NodeName */}}}" data="{{${this.dataKeymap('i:i')}}}" />`;
981
- }
1018
+ </block>`;
1019
+ }
1020
+ else {
1021
+ const xs = !this.isSupportRecursive
1022
+ ? `xs.a(${level}, i.${"nn" /* Shortcuts.NodeName */}, l)`
1023
+ : `xs.a(${level}, i.${"nn" /* Shortcuts.NodeName */})`;
1024
+ const data = !this.isSupportRecursive
1025
+ ? `${this.dataKeymap(`i:i,cid:${level},l:xs.f(l,i.${"nn" /* Shortcuts.NodeName */})`)}`
1026
+ : `${this.dataKeymap('i:i')}`;
1027
+ tmpl = this.supportXS
1028
+ ? `<template is="{{${xs}}}" data="{{${data}}}" />`
1029
+ : `<template is="{{'tmpl_${level}_' + i.${"nn" /* Shortcuts.NodeName */}}}" data="{{${this.dataKeymap('i:i')}}}" />`;
1030
+ }
982
1031
  return `
983
- <template name="tmpl_${level}_${"container" /* Container */}">
1032
+ <template name="tmpl_${level}_${"container" /* Shortcuts.Container */}">
984
1033
  ${tmpl}
985
1034
  </template>
986
- `;
987
- }
988
- dataKeymap(keymap) {
989
- return keymap;
990
- }
991
- getEvents() {
992
- return events;
993
- }
994
- getAttrValue(value, _key, _nodeName) {
995
- return `{${value}}`;
996
- }
997
- buildXsTemplate() {
998
- return '';
999
- }
1000
- mergeComponents(ctx, patch) {
1001
- ctx.helper.recursiveMerge(this.internalComponents, patch);
1002
- }
1003
- mergeThirdPartyComponents(patch) {
1004
- this.thirdPartyPatcher = patch;
1005
- }
1006
- buildXSTmplName() {
1035
+ `;
1036
+ }
1037
+ dataKeymap(keymap) {
1038
+ return keymap;
1039
+ }
1040
+ getEvents() {
1041
+ return events;
1042
+ }
1043
+ getAttrValue(value, _key, _nodeName) {
1044
+ return `{${value}}`;
1045
+ }
1046
+ buildXsTemplate() {
1047
+ return '';
1048
+ }
1049
+ mergeComponents(ctx, patch) {
1050
+ ctx.helper.recursiveMerge(this.internalComponents, patch);
1051
+ }
1052
+ mergeThirdPartyComponents(patch) {
1053
+ this.thirdPartyPatcher = patch;
1054
+ }
1055
+ buildXSTmplName() {
1007
1056
  return `function (l, n) {
1008
1057
  return 'tmpl_' + l + '_' + n
1009
- }`;
1010
- }
1011
- buildXSTepFocus(nn) {
1058
+ }`;
1059
+ }
1060
+ buildXSTepFocus(nn) {
1012
1061
  return `function(i, prefix) {
1013
1062
  var s = i.focus !== undefined ? 'focus' : 'blur'
1014
1063
  return prefix + i.${nn} + '_' + s
1015
- }`;
1016
- }
1017
- buildXSTmpExtra() {
1018
- return '';
1019
- }
1020
- }
1021
- class RecursiveTemplate extends BaseTemplate {
1022
- constructor() {
1023
- super(...arguments);
1024
- this.isSupportRecursive = true;
1025
- this.buildTemplate = (componentConfig) => {
1026
- let template = this.buildBaseTemplate();
1027
- if (!this.miniComponents) {
1028
- this.miniComponents = this.createMiniComponents(this.internalComponents);
1029
- }
1030
- const ZERO_FLOOR = 0;
1031
- const components = Object.keys(this.miniComponents)
1032
- .filter(c => componentConfig.includes.size && !componentConfig.includeAll ? componentConfig.includes.has(c) : true);
1033
- template = components.reduce((current, nodeName) => {
1034
- const attributes = this.miniComponents[nodeName];
1035
- return current + this.buildComponentTemplate({ nodeName, attributes }, ZERO_FLOOR);
1036
- }, template);
1037
- template += this.buildPlainTextTemplate(ZERO_FLOOR);
1038
- template += this.buildThirdPartyTemplate(ZERO_FLOOR, componentConfig);
1039
- template += this.buildContainerTemplate(ZERO_FLOOR);
1040
- return template;
1041
- };
1042
- }
1043
- }
1044
- class UnRecursiveTemplate extends BaseTemplate {
1045
- constructor() {
1046
- super(...arguments);
1047
- this.isSupportRecursive = false;
1048
- this._baseLevel = 16;
1049
- this.buildTemplate = (componentConfig) => {
1050
- this.componentConfig = componentConfig;
1051
- if (!this.miniComponents) {
1052
- this.miniComponents = this.createMiniComponents(this.internalComponents);
1053
- }
1054
- const components = Object.keys(this.miniComponents)
1055
- .filter(c => componentConfig.includes.size && !componentConfig.includeAll ? componentConfig.includes.has(c) : true);
1056
- let template = this.buildBaseTemplate();
1057
- for (let i = 0; i < this.baseLevel; i++) {
1058
- template += this.supportXS
1059
- ? this.buildOptimizeFloor(i, components, this.baseLevel === i + 1)
1060
- : this.buildFloor(i, components, this.baseLevel === i + 1);
1061
- }
1062
- return template;
1063
- };
1064
- }
1065
- set baseLevel(lv) {
1066
- this._baseLevel = lv;
1067
- }
1068
- get baseLevel() {
1069
- return this._baseLevel;
1070
- }
1071
- buildFloor(level, components, restart = false) {
1072
- if (restart)
1073
- return this.buildContainerTemplate(level, restart);
1074
- let template = components.reduce((current, nodeName) => {
1075
- const attributes = this.miniComponents[nodeName];
1076
- return current + this.buildComponentTemplate({ nodeName, attributes }, level);
1077
- }, '');
1078
- template += this.buildPlainTextTemplate(level);
1079
- template += this.buildThirdPartyTemplate(level, this.componentConfig);
1080
- template += this.buildContainerTemplate(level, restart);
1081
- return template;
1082
- }
1083
- buildOptimizeFloor(level, components, restart = false) {
1084
- if (restart)
1085
- return this.buildContainerTemplate(level, restart);
1086
- let template = components.reduce((current, nodeName) => {
1087
- if (level !== 0) {
1088
- if (!this.nestElements.has(nodeName)) {
1089
- // 不可嵌套自身的组件只需输出一层模板
1090
- return current;
1091
- }
1092
- else {
1093
- // 部分可嵌套自身的组件实际上不会嵌套过深,这里按阈值限制层数
1094
- const max = this.nestElements.get(nodeName);
1095
- if (max > 0 && level >= max) {
1096
- return current;
1097
- }
1098
- }
1099
- }
1100
- const attributes = this.miniComponents[nodeName];
1101
- return current + this.buildComponentTemplate({ nodeName, attributes }, level);
1102
- }, '');
1103
- if (level === 0)
1104
- template += this.buildPlainTextTemplate(level);
1105
- template += this.buildThirdPartyTemplate(level, this.componentConfig);
1106
- template += this.buildContainerTemplate(level);
1107
- return template;
1108
- }
1109
- buildXSTmplName() {
1110
- const isLoopComps = [
1111
- ...Array.from(this.nestElements.keys()),
1112
- ...Array.from(this.componentConfig.thirdPartyComponents.keys())
1113
- ];
1114
- const isLoopCompsSet = new Set(isLoopComps);
1115
- const hasMaxComps = [];
1116
- this.nestElements.forEach((max, comp) => {
1117
- if (max > 1) {
1118
- hasMaxComps.push(comp);
1119
- }
1120
- else if (max === 1 && isLoopCompsSet.has(comp)) {
1121
- isLoopCompsSet.delete(comp);
1122
- }
1123
- });
1064
+ }`;
1065
+ }
1066
+ buildXSTmpExtra() {
1067
+ return '';
1068
+ }
1069
+ }
1070
+ class RecursiveTemplate extends BaseTemplate {
1071
+ constructor() {
1072
+ super(...arguments);
1073
+ this.isSupportRecursive = true;
1074
+ this.buildTemplate = (componentConfig) => {
1075
+ let template = this.buildBaseTemplate();
1076
+ if (!this.miniComponents) {
1077
+ this.componentsAlias = getComponentsAlias(this.internalComponents);
1078
+ this.miniComponents = this.createMiniComponents(this.internalComponents);
1079
+ }
1080
+ const ZERO_FLOOR = 0;
1081
+ const components = Object.keys(this.miniComponents)
1082
+ .filter(c => componentConfig.includes.size && !componentConfig.includeAll ? componentConfig.includes.has(c) : true);
1083
+ template = components.reduce((current, nodeName) => {
1084
+ const attributes = this.miniComponents[nodeName];
1085
+ const nodeAlias = this.componentsAlias[nodeName]._num;
1086
+ return current + this.buildComponentTemplate({ nodeName, nodeAlias, attributes }, ZERO_FLOOR);
1087
+ }, template);
1088
+ template += this.buildPlainTextTemplate(ZERO_FLOOR);
1089
+ template += this.buildThirdPartyTemplate(ZERO_FLOOR, componentConfig);
1090
+ template += this.buildContainerTemplate(ZERO_FLOOR);
1091
+ return template;
1092
+ };
1093
+ }
1094
+ }
1095
+ class UnRecursiveTemplate extends BaseTemplate {
1096
+ constructor() {
1097
+ super(...arguments);
1098
+ this.isSupportRecursive = false;
1099
+ this._baseLevel = 16;
1100
+ this.buildTemplate = (componentConfig) => {
1101
+ this.componentConfig = componentConfig;
1102
+ if (!this.miniComponents) {
1103
+ this.componentsAlias = getComponentsAlias(this.internalComponents);
1104
+ this.miniComponents = this.createMiniComponents(this.internalComponents);
1105
+ }
1106
+ const components = Object.keys(this.miniComponents)
1107
+ .filter(c => componentConfig.includes.size && !componentConfig.includeAll ? componentConfig.includes.has(c) : true);
1108
+ let template = this.buildBaseTemplate();
1109
+ for (let i = 0; i < this.baseLevel; i++) {
1110
+ template += this.supportXS
1111
+ ? this.buildOptimizeFloor(i, components, this.baseLevel === i + 1)
1112
+ : this.buildFloor(i, components, this.baseLevel === i + 1);
1113
+ }
1114
+ return template;
1115
+ };
1116
+ }
1117
+ set baseLevel(lv) {
1118
+ this._baseLevel = lv;
1119
+ }
1120
+ get baseLevel() {
1121
+ return this._baseLevel;
1122
+ }
1123
+ buildFloor(level, components, restart = false) {
1124
+ if (restart)
1125
+ return this.buildContainerTemplate(level, restart);
1126
+ let template = components.reduce((current, nodeName) => {
1127
+ const attributes = this.miniComponents[nodeName];
1128
+ const nodeAlias = this.componentsAlias[nodeName]._num;
1129
+ return current + this.buildComponentTemplate({ nodeName, nodeAlias, attributes }, level);
1130
+ }, '');
1131
+ template += this.buildPlainTextTemplate(level);
1132
+ template += this.buildThirdPartyTemplate(level, this.componentConfig);
1133
+ template += this.buildContainerTemplate(level, restart);
1134
+ return template;
1135
+ }
1136
+ buildOptimizeFloor(level, components, restart = false) {
1137
+ if (restart)
1138
+ return this.buildContainerTemplate(level, restart);
1139
+ let template = components.reduce((current, nodeName) => {
1140
+ if (level !== 0) {
1141
+ if (!this.nestElements.has(nodeName)) {
1142
+ // 不可嵌套自身的组件只需输出一层模板
1143
+ return current;
1144
+ }
1145
+ else {
1146
+ // 部分可嵌套自身的组件实际上不会嵌套过深,这里按阈值限制层数
1147
+ const max = this.nestElements.get(nodeName);
1148
+ if (max > 0 && level >= max) {
1149
+ return current;
1150
+ }
1151
+ }
1152
+ }
1153
+ const attributes = this.miniComponents[nodeName];
1154
+ const nodeAlias = this.componentsAlias[nodeName]._num;
1155
+ return current + this.buildComponentTemplate({ nodeName, nodeAlias, attributes }, level);
1156
+ }, '');
1157
+ if (level === 0)
1158
+ template += this.buildPlainTextTemplate(level);
1159
+ template += this.buildThirdPartyTemplate(level, this.componentConfig);
1160
+ template += this.buildContainerTemplate(level);
1161
+ return template;
1162
+ }
1163
+ buildXSTmplName() {
1164
+ const isLoopComps = [
1165
+ ...Array.from(this.nestElements.keys()),
1166
+ ...Array.from(this.componentConfig.thirdPartyComponents.keys())
1167
+ ];
1168
+ const isLoopCompsSet = new Set(isLoopComps);
1169
+ const hasMaxComps = [];
1170
+ this.nestElements.forEach((max, comp) => {
1171
+ if (max > 1) {
1172
+ hasMaxComps.push(comp);
1173
+ }
1174
+ else if (max === 1 && isLoopCompsSet.has(comp)) {
1175
+ isLoopCompsSet.delete(comp);
1176
+ }
1177
+ });
1178
+ const componentsAlias = this.componentsAlias;
1179
+ const listA = Array.from(isLoopCompsSet).map(item => { var _a; return ((_a = componentsAlias[item]) === null || _a === void 0 ? void 0 : _a._num) || item; });
1180
+ const listB = hasMaxComps.map(item => { var _a; return ((_a = componentsAlias[item]) === null || _a === void 0 ? void 0 : _a._num) || item; });
1124
1181
  return `function (l, n, s) {
1125
- var a = ${JSON.stringify(Array.from(isLoopCompsSet))}
1126
- var b = ${JSON.stringify(hasMaxComps)}
1182
+ var a = ${JSON.stringify(listA)}
1183
+ var b = ${JSON.stringify(listB)}
1127
1184
  if (a.indexOf(n) === -1) {
1128
1185
  l = 0
1129
1186
  }
@@ -1136,23 +1193,25 @@ class UnRecursiveTemplate extends BaseTemplate {
1136
1193
  l = depth
1137
1194
  }
1138
1195
  return 'tmpl_' + l + '_' + n
1139
- }`;
1140
- }
1141
- buildXSTmpExtra() {
1142
- const hasMaxComps = [];
1143
- this.nestElements.forEach((max, comp) => {
1144
- if (max > 1)
1145
- hasMaxComps.push(comp);
1146
- });
1196
+ }`;
1197
+ }
1198
+ buildXSTmpExtra() {
1199
+ const hasMaxComps = [];
1200
+ this.nestElements.forEach((max, comp) => {
1201
+ if (max > 1)
1202
+ hasMaxComps.push(comp);
1203
+ });
1204
+ const componentsAlias = this.componentsAlias;
1205
+ const listA = hasMaxComps.map(item => { var _a; return ((_a = componentsAlias[item]) === null || _a === void 0 ? void 0 : _a._num) || item; });
1147
1206
  return `f: function (l, n) {
1148
- var b = ${JSON.stringify(hasMaxComps)}
1207
+ var b = ${JSON.stringify(listA)}
1149
1208
  if (b.indexOf(n) > -1) {
1150
1209
  if (l) l += ','
1151
1210
  l += n
1152
1211
  }
1153
1212
  return l
1154
- }`;
1155
- }
1213
+ }`;
1214
+ }
1156
1215
  }
1157
1216
 
1158
1217
  exports.BaseTemplate = BaseTemplate;