@tarojs/plugin-platform-harmony-ets 4.0.0-alpha.0 → 4.0.0-alpha.10

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.
Files changed (139) hide show
  1. package/dist/apis/base/system.ts +73 -20
  2. package/dist/apis/canvas/index.ts +10 -1
  3. package/dist/apis/device/clipboard.ts +16 -8
  4. package/dist/apis/device/memory.ts +10 -3
  5. package/dist/apis/framework/index.ts +1 -5
  6. package/dist/apis/index.ts +27 -17
  7. package/dist/apis/media/image/index.ts +1 -1
  8. package/dist/apis/media/video/VideoContext.ts +56 -7
  9. package/dist/apis/media/video/index.ts +3 -2
  10. package/dist/apis/network/request.ts +5 -5
  11. package/dist/apis/route/index.ts +15 -0
  12. package/dist/apis/storage/index.ts +146 -78
  13. package/dist/apis/ui/animation/animation.ts +71 -29
  14. package/dist/apis/ui/background.ts +2 -1
  15. package/dist/apis/ui/interaction/index.ts +42 -59
  16. package/dist/apis/ui/navigation-bar/index.ts +1 -1
  17. package/dist/apis/ui/pull-down-refresh.ts +9 -3
  18. package/dist/apis/ui/scroll/index.ts +5 -5
  19. package/dist/apis/ui/tab-bar.ts +3 -3
  20. package/dist/apis/utils/index.ts +1 -1
  21. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  22. package/dist/apis/wxml/index.ts +2 -0
  23. package/dist/apis/wxml/selectorQuery.ts +26 -13
  24. package/dist/components-harmony-ets/button.ets +68 -68
  25. package/dist/components-harmony-ets/canvas.ets +51 -0
  26. package/dist/components-harmony-ets/checkbox.ets +81 -102
  27. package/dist/components-harmony-ets/form.ets +54 -45
  28. package/dist/components-harmony-ets/icon.ets +34 -50
  29. package/dist/components-harmony-ets/image.ets +35 -45
  30. package/dist/components-harmony-ets/index.ets +92 -0
  31. package/dist/components-harmony-ets/innerHtml.ets +11 -6
  32. package/dist/components-harmony-ets/input.ets +51 -67
  33. package/dist/components-harmony-ets/label.ets +73 -53
  34. package/dist/components-harmony-ets/listView.ets +26 -0
  35. package/dist/components-harmony-ets/movableArea.ets +124 -0
  36. package/dist/components-harmony-ets/movableView.ets +93 -0
  37. package/dist/components-harmony-ets/navigationBar.ets +65 -0
  38. package/dist/components-harmony-ets/pageMeta.ets +94 -0
  39. package/dist/components-harmony-ets/picker.ets +74 -77
  40. package/dist/components-harmony-ets/progress.ets +52 -0
  41. package/dist/components-harmony-ets/pseudo.ets +80 -0
  42. package/dist/components-harmony-ets/radio.ets +82 -104
  43. package/dist/components-harmony-ets/richText.ets +20 -68
  44. package/dist/components-harmony-ets/scrollList.ets +94 -0
  45. package/dist/components-harmony-ets/scrollView.ets +67 -103
  46. package/dist/components-harmony-ets/slider.ets +23 -47
  47. package/dist/components-harmony-ets/stickySection.ets +42 -0
  48. package/dist/components-harmony-ets/style.ets +396 -0
  49. package/dist/components-harmony-ets/swiper.ets +64 -53
  50. package/dist/components-harmony-ets/switch.ets +44 -55
  51. package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
  52. package/dist/components-harmony-ets/text.ets +134 -75
  53. package/dist/components-harmony-ets/textArea.ets +54 -62
  54. package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
  55. package/dist/components-harmony-ets/utils/DynamicCenter.ts +4 -13
  56. package/dist/components-harmony-ets/utils/flexManager.ets +76 -8
  57. package/dist/components-harmony-ets/utils/helper.ets +20 -7
  58. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  59. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  60. package/dist/components-harmony-ets/utils/index.ts +54 -50
  61. package/dist/components-harmony-ets/utils/styles.ets +178 -63
  62. package/dist/components-harmony-ets/video.ets +37 -54
  63. package/dist/components-harmony-ets/view.ets +63 -94
  64. package/dist/components-harmony-ets/webView.ets +56 -0
  65. package/dist/index.d.ts +152 -0
  66. package/dist/index.js +199 -58
  67. package/dist/index.js.map +1 -1
  68. package/dist/runtime-ets/bom/document.ts +6 -4
  69. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
  70. package/dist/runtime-ets/bom/window.ts +9 -2
  71. package/dist/runtime-ets/current.ts +3 -0
  72. package/dist/runtime-ets/dom/bind.ts +28 -12
  73. package/dist/runtime-ets/dom/class-list.ts +2 -2
  74. package/dist/runtime-ets/dom/cssNesting.ts +409 -0
  75. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +29 -19
  76. package/dist/runtime-ets/dom/document.ts +22 -8
  77. package/dist/runtime-ets/dom/element/canvas.ts +136 -0
  78. package/dist/runtime-ets/dom/element/element.ts +334 -57
  79. package/dist/runtime-ets/dom/element/form.ts +32 -26
  80. package/dist/runtime-ets/dom/element/index.ts +33 -2
  81. package/dist/runtime-ets/dom/element/movableArea.ts +11 -0
  82. package/dist/runtime-ets/dom/element/movableView.ts +242 -0
  83. package/dist/runtime-ets/dom/element/normal.ts +36 -8
  84. package/dist/runtime-ets/dom/element/progress.ts +11 -0
  85. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  86. package/dist/runtime-ets/dom/element/text.ts +1 -8
  87. package/dist/runtime-ets/dom/element/video.ts +5 -4
  88. package/dist/runtime-ets/dom/element/webView.ts +68 -0
  89. package/dist/runtime-ets/dom/event.ts +2 -4
  90. package/dist/runtime-ets/dom/eventTarget.ts +2 -3
  91. package/dist/runtime-ets/dom/node.ts +62 -27
  92. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +805 -0
  93. package/dist/runtime-ets/dom/stylesheet/index.ts +98 -518
  94. package/dist/runtime-ets/dom/stylesheet/type.ts +92 -17
  95. package/dist/runtime-ets/dom/stylesheet/util.ts +74 -16
  96. package/dist/runtime-ets/index.ts +2 -2
  97. package/dist/runtime-ets/interface/event.ts +3 -2
  98. package/dist/runtime-ets/utils/index.ts +77 -12
  99. package/dist/runtime-ets/utils/info.ts +4 -2
  100. package/dist/runtime-framework/react/app.ts +17 -22
  101. package/dist/runtime-framework/react/hooks.ts +3 -4
  102. package/dist/runtime-framework/react/index.ts +1 -2
  103. package/dist/runtime-framework/react/native-page.ts +421 -0
  104. package/dist/runtime-framework/react/page.ts +4 -9
  105. package/dist/runtime-framework/solid/app.ts +25 -45
  106. package/dist/runtime-framework/solid/connect.ts +21 -3
  107. package/dist/runtime-framework/solid/hooks.ts +17 -12
  108. package/dist/runtime-framework/solid/index.ts +6 -2
  109. package/dist/runtime-framework/solid/page.ts +84 -30
  110. package/dist/runtime-framework/solid/reconciler/props.ts +70 -25
  111. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  112. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  113. package/dist/runtime-framework/solid/utils/index.ts +0 -2
  114. package/dist/runtime-utils.d.ts +827 -0
  115. package/dist/runtime-utils.js +510 -237
  116. package/dist/runtime-utils.js.map +1 -1
  117. package/dist/runtime.d.ts +1 -0
  118. package/dist/runtime.js +510 -237
  119. package/dist/runtime.js.map +1 -1
  120. package/index.js +3 -1
  121. package/package.json +14 -15
  122. package/static/media/cancel.svg +1 -0
  123. package/static/media/circle.svg +1 -0
  124. package/static/media/clear.svg +1 -0
  125. package/static/media/download.svg +1 -0
  126. package/static/media/info.svg +1 -0
  127. package/static/media/info_circle.svg +1 -0
  128. package/static/media/search.svg +1 -0
  129. package/static/media/success.svg +1 -0
  130. package/static/media/success_no_circle.svg +1 -0
  131. package/static/media/taro_arrow_left.svg +1 -0
  132. package/static/media/taro_home.svg +1 -0
  133. package/static/media/waiting.svg +1 -0
  134. package/static/media/warn.svg +1 -0
  135. package/types/harmony.d.ts +4 -0
  136. package/types/index.d.ts +4 -0
  137. package/types/runtime.d.ts +3 -1
  138. package/dist/runtime-ets/utils/bind.ts +0 -24
  139. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
@@ -0,0 +1,396 @@
1
+ import type { TaroAny, HarmonyStyle, TaroElement, TaroStyleType, TaroTextElement } from '@tarojs/runtime'
2
+ import { ObjectAssign } from '@tarojs/runtime'
3
+ import { isUndefined } from '@tarojs/shared'
4
+ import { computeBackgroundPosition, convertVp2Px } from './utils'
5
+ import { getNormalAttributes } from './utils/helper'
6
+ import { isMaxWidthView } from './utils/styles'
7
+ import { FlexManager } from './utils/flexManager.ets'
8
+
9
+ class TextStyleModify implements AttributeModifier<TextAttribute> {
10
+ initStyle?: TaroStyleType
11
+ node: TaroTextElement | null = null
12
+ style: HarmonyStyle | null = null
13
+ overwriteStyle: Record<string, TaroAny> = {}
14
+ withNormal: boolean = false
15
+
16
+ setNode (node: TaroTextElement, initStyle?: HarmonyStyle) {
17
+ this.node = node
18
+ this.withNormal = false
19
+ this.overwriteStyle = {}
20
+ this.style = getNormalAttributes(this.node)
21
+ this.initStyle = initStyle
22
+ // 覆盖初始化样式
23
+ if (initStyle) {
24
+ Object.keys(initStyle).forEach(key => {
25
+ if (this.style && !this.style[key]) {
26
+ this.style[key] = initStyle[key]
27
+ }
28
+ })
29
+ }
30
+ return this
31
+ }
32
+
33
+ withNormalStyle () {
34
+ this.withNormal = true
35
+ return this
36
+ }
37
+
38
+ setAnimationStyle (overwriteStyle: Record<string, TaroAny>) {
39
+ this.overwriteStyle = overwriteStyle
40
+ if (this.style && this.overwriteStyle && Object.keys(this.overwriteStyle).length) {
41
+ // 防止污染原始样式
42
+ this.style = ObjectAssign({}, this.style)
43
+ Object.keys(this.overwriteStyle).forEach(key => {
44
+ this.style![key] = this.overwriteStyle[key]
45
+ })
46
+ }
47
+ return this
48
+ }
49
+
50
+ applyNormalAttribute(instance: TextAttribute): void {
51
+ if (this.node && this.style) {
52
+ if (this.withNormal) {
53
+ setNormalAttributeIntoInstance(instance, this.style, this.node)
54
+ setTransformAttributeIntoInstance(instance, this.style || {})
55
+ }
56
+ setNormalTextAttributeIntoInstance(instance, this.style, this.node)
57
+ setSpecialTextAttributeIntoInstance(instance, this.style, this.node)
58
+ }
59
+
60
+ }
61
+ }
62
+
63
+ class CommonStyleModify implements AttributeModifier<CommonAttribute> {
64
+ initStyle?: TaroStyleType
65
+ node: TaroElement | null = null
66
+ style: TaroStyleType | null = null
67
+ overwriteStyle: TaroStyleType = {}
68
+
69
+ setNode (node: TaroElement, initStyle?: TaroStyleType) {
70
+ this.node = node
71
+ this.style = getNormalAttributes(this.node)
72
+ this.initStyle = initStyle
73
+ this.overwriteStyle = {}
74
+ // 覆盖初始化样式
75
+ if (initStyle) {
76
+ Object.keys(initStyle).forEach(key => {
77
+ if (this.style && !this.style[key]) {
78
+ this.style[key] = initStyle[key]
79
+ }
80
+ })
81
+ }
82
+ return this
83
+ }
84
+
85
+ setAnimationStyle (overwriteStyle: Record<string, TaroAny>) {
86
+ this.overwriteStyle = overwriteStyle
87
+ if (this.style && this.overwriteStyle && Object.keys(this.overwriteStyle).length) {
88
+ // 防止污染原始样式
89
+ this.style = ObjectAssign({}, this.style)
90
+ Object.keys(this.overwriteStyle).forEach(key => {
91
+ this.style![key] = this.overwriteStyle[key]
92
+ })
93
+ }
94
+ return this
95
+ }
96
+
97
+ applyNormalAttribute(instance: CommonAttribute): void {
98
+ if (this.node && this.style) {
99
+ setNormalAttributeIntoInstance(instance, this.style, this.node)
100
+ setTransformAttributeIntoInstance(instance, this.style || {})
101
+ }
102
+ }
103
+ }
104
+
105
+ class PseudoStyleModify implements AttributeModifier<CommonAttribute> {
106
+ style: TaroStyleType | null = null
107
+
108
+ setStyle (style: HarmonyStyle) {
109
+ this.style = style
110
+ return this
111
+ }
112
+
113
+ applyNormalAttribute(instance: CommonAttribute): void {
114
+ if (this.style) {
115
+ setNormalAttributeIntoInstance(instance, this.style)
116
+ setTransformAttributeIntoInstance(instance, this.style || {})
117
+ }
118
+ }
119
+ }
120
+
121
+ class RowStyleModify extends CommonStyleModify {
122
+
123
+ applyNormalAttribute(instance: RowAttribute): void {
124
+ if (this.style) {
125
+ setNormalAttributeIntoInstance(instance, this.style, this.node)
126
+ instance.constraintSize({
127
+ minWidth: this.style.minWidth || this.style.width,
128
+ maxWidth: this.style.maxWidth,
129
+ minHeight: this.style.minHeight,
130
+ maxHeight: this.style.maxHeight
131
+ })
132
+ if (this.node) {
133
+ instance.alignItems(FlexManager.alignItems<VerticalAlign>(this.node))
134
+ instance.justifyContent(FlexManager.justifyContent(this.node))
135
+ }
136
+ setTransformAttributeIntoInstance(instance, this.style || {})
137
+ }
138
+
139
+ }
140
+ }
141
+
142
+ class ColumnStyleModify extends CommonStyleModify {
143
+ applyNormalAttribute(instance: ColumnAttribute): void {
144
+ if (this.style) {
145
+ setNormalAttributeIntoInstance(instance, this.style, this.node)
146
+ instance.constraintSize({
147
+ minWidth: this.style.minWidth,
148
+ maxWidth: this.style.maxWidth,
149
+ minHeight: this.style.minHeight || this.style.height,
150
+ maxHeight: this.style.maxHeight
151
+ })
152
+ if (this.node) {
153
+ instance.alignItems(FlexManager.alignItems<HorizontalAlign>(this.node))
154
+ instance.justifyContent(FlexManager.justifyContent(this.node))
155
+ }
156
+ setTransformAttributeIntoInstance(instance, this.style || {})
157
+ }
158
+
159
+ }
160
+ }
161
+
162
+ export function setTransformAttributeIntoInstance(instance: CommonAttribute, style: TaroStyleType) {
163
+ // Animation 需要提前和 @State 变量绑定才能产生动画效果,因此不能做 if else 判断
164
+ instance.translate({
165
+ x: style.transform?.Translate?.x,
166
+ y: style.transform?.Translate?.y,
167
+ z: style.transform?.Translate?.z,
168
+ })
169
+ instance.scale({
170
+ x: style.transform?.Scale?.x,
171
+ y: style.transform?.Scale?.y,
172
+ z: style.transform?.Scale?.z,
173
+ centerX: style.transformOrigin?.x,
174
+ centerY: style.transformOrigin?.y,
175
+ })
176
+ instance.rotate({
177
+ x: style.transform?.Rotate?.x,
178
+ y: style.transform?.Rotate?.y,
179
+ z: style.transform?.Rotate?.z,
180
+ centerX: style.transformOrigin?.x,
181
+ centerY: style.transformOrigin?.y,
182
+ angle: style.transform?.Rotate?.angle || 0,
183
+ })
184
+ }
185
+
186
+ export function setNormalTextAttributeIntoInstance(instance: TextAttribute | SpanAttribute, style: HarmonyStyle, node?: TaroTextElement | null) {
187
+ if (!isUndefined(style.color)) {
188
+ instance.fontColor(style.color)
189
+ }
190
+ if (!isUndefined(style.fontSize)) {
191
+ instance.fontSize(style.fontSize)
192
+ }
193
+ if (!isUndefined(style.fontWeight)) {
194
+ instance.fontWeight(style.fontWeight)
195
+ }
196
+ if (!isUndefined(style.fontStyle)) {
197
+ instance.fontStyle(style.fontStyle)
198
+ }
199
+ if (!isUndefined(style.fontFamily)) {
200
+ instance.fontFamily(style.fontFamily)
201
+ }
202
+ if (!isUndefined(style.textDecoration)) {
203
+ instance.decoration({
204
+ type: style.textDecoration.type,
205
+ color: style.color
206
+ })
207
+ }
208
+ }
209
+
210
+ export function setSpecialTextAttributeIntoInstance(instance: TextAttribute, style: HarmonyStyle, node?: TaroTextElement | null) {
211
+ if (!isUndefined(style.textAlign)) {
212
+ instance.textAlign(style.textAlign)
213
+ }
214
+ if (!isUndefined(style.verticalAlign)) {
215
+ instance.align(style.verticalAlign)
216
+ }
217
+ if (!isUndefined(style.textOverflow)) {
218
+ instance.textOverflow(style.textOverflow)
219
+ }
220
+ if (!isUndefined(style.whiteSpace) && style.whiteSpace === 'nowrap') {
221
+ instance.maxLines(1)
222
+ }
223
+ if (!isUndefined(style.WebkitLineClamp)) {
224
+ instance.maxLines(style.WebkitLineClamp)
225
+ }
226
+ if (!isUndefined(style.letterSpacing)) {
227
+ instance.letterSpacing(style.letterSpacing)
228
+ }
229
+ if (!isUndefined(style.lineHeight)) {
230
+ instance.lineHeight(style.lineHeight)
231
+ }
232
+ }
233
+
234
+ export function setNormalAttributeIntoInstance(instance: CommonAttribute, style: TaroStyleType, node?: TaroElement | null) {
235
+ instance.renderFit(RenderFit.RESIZE_FILL)
236
+ if (!isUndefined(style.id)) {
237
+ instance.id(style.id)
238
+ instance.key(style.id)
239
+ }
240
+ if (!isUndefined(style.display) || !isUndefined(style.visibility)) {
241
+ instance.visibility(style.display === 'none'
242
+ ? Visibility.None :
243
+ !isUndefined(style.visibility)
244
+ ? (style.visibility === 'hidden' ? Visibility.Hidden : Visibility.Visible)
245
+ : Visibility.Visible
246
+ )
247
+ }
248
+ if (!isUndefined(style.flexGrow)) {
249
+ instance.flexGrow(style.flexGrow)
250
+ }
251
+ if (!isUndefined(style.flexShrink)) {
252
+ instance.flexShrink(style.flexShrink)
253
+ }
254
+ if (!isUndefined(style.flexBasis)) {
255
+ instance.flexBasis(style.flexBasis)
256
+ }
257
+ if (!isUndefined(style.alignSelf)) {
258
+ instance.alignSelf(style.alignSelf)
259
+ }
260
+ if (!isUndefined(style.paddingTop) || !isUndefined(style.paddingRight) || !isUndefined(style.paddingBottom) || !isUndefined(style.paddingLeft)) {
261
+ instance.padding({
262
+ top: style.paddingTop,
263
+ right: style.paddingRight,
264
+ bottom: style.paddingBottom,
265
+ left: style.paddingLeft
266
+ })
267
+ }
268
+ if (!isUndefined(style.marginTop) || !isUndefined(style.marginRight) || !isUndefined(style.marginBottom) || !isUndefined(style.marginLeft)) {
269
+ instance.margin({
270
+ top: style.marginTop,
271
+ right: style.marginRight,
272
+ bottom: style.marginBottom,
273
+ left: style.marginLeft
274
+ })
275
+ }
276
+ if (node) {
277
+ instance.width(isMaxWidthView(node as TaroElement) && isUndefined(style.width) ? '100%' : style.width)
278
+ } else {
279
+ if (!isUndefined(style.width)) {
280
+ instance.width(style.width)
281
+ }
282
+ }
283
+ if (!isUndefined(style.height)) {
284
+ instance.height(style.height)
285
+ }
286
+ if (!isUndefined(style.minWidth) || !isUndefined(style.maxWidth) || !isUndefined(style.minHeight) || !isUndefined(style.maxHeight)) {
287
+ instance.constraintSize({
288
+ minWidth: style.minWidth,
289
+ maxWidth: style.maxWidth,
290
+ minHeight: style.minHeight,
291
+ maxHeight: style.maxHeight
292
+ })
293
+ }
294
+ if (!isUndefined(style.backgroundColor)) {
295
+ instance.backgroundColor(style.backgroundColor)
296
+ }
297
+ if (!isUndefined(style.backgroundImage)) {
298
+ if (style.backgroundImage.center) {
299
+ // radialGradient
300
+ instance.radialGradient(style.backgroundImage)
301
+ } else if (style.backgroundImage.colors) {
302
+ // linearGradient
303
+ instance.linearGradient(style.backgroundImage)
304
+ } else {
305
+ instance.backgroundImage(style.backgroundImage?.src, style.backgroundRepeat)
306
+ }
307
+ }
308
+ if (!isUndefined(style.backgroundSize)) {
309
+ instance.backgroundImageSize(style.backgroundSize)
310
+ }
311
+ if (!isUndefined(style.backgroundPosition)) {
312
+ if (typeof style.backgroundPosition !== 'number') {
313
+ let pos = computeBackgroundPosition(style)
314
+ instance.backgroundImagePosition({
315
+ x: pos.offsetX,
316
+ y: pos.offsetY,
317
+ })
318
+ } else {
319
+ instance.backgroundImagePosition(style.backgroundPosition)
320
+ }
321
+ }
322
+ if (!isUndefined(style.borderTopStyle) || !isUndefined(style.borderRightStyle) || !isUndefined(style.borderBottomStyle) || !isUndefined(style.borderLeftStyle)) {
323
+ instance.borderStyle({
324
+ top: style.borderTopStyle,
325
+ right: style.borderRightStyle,
326
+ bottom: style.borderBottomStyle,
327
+ left: style.borderLeftStyle
328
+ })
329
+ }
330
+ if (!isUndefined(style.borderTopWidth) || !isUndefined(style.borderRightWidth) || !isUndefined(style.borderBottomWidth) || !isUndefined(style.borderLeftWidth)) {
331
+ instance.borderWidth({
332
+ top: style.borderTopWidth,
333
+ right: style.borderRightWidth,
334
+ bottom: style.borderBottomWidth,
335
+ left: style.borderLeftWidth
336
+ })
337
+ }
338
+ if (!isUndefined(style.borderTopColor) || !isUndefined(style.borderRightColor) || !isUndefined(style.borderBottomColor) || !isUndefined(style.borderLeftColor)) {
339
+ instance.borderColor({
340
+ top: style.borderTopColor,
341
+ right: style.borderRightColor,
342
+ bottom: style.borderBottomColor,
343
+ left: style.borderLeftColor
344
+ })
345
+ }
346
+ if (!isUndefined(style.borderTopLeftRadius) || !isUndefined(style.borderTopRightRadius) || !isUndefined(style.borderBottomLeftRadius) || !isUndefined(style.borderBottomRightRadius)) {
347
+ instance.borderRadius({
348
+ topLeft: style.borderTopLeftRadius,
349
+ topRight: style.borderTopRightRadius,
350
+ bottomLeft: style.borderBottomLeftRadius,
351
+ bottomRight: style.borderBottomRightRadius
352
+ })
353
+ }
354
+ if (!isUndefined(style.opacity)) {
355
+ instance.opacity(style.opacity)
356
+ }
357
+ if (!isUndefined(style.overflow)) {
358
+ instance.clip(style.overflow === 'hidden')
359
+ }
360
+ if (style.position === 'absolute' || style.position === 'fixed') {
361
+ instance.position({
362
+ x: style.left || 0,
363
+ y: style.top || 0,
364
+ })
365
+ // 绝对定位和固定定位在web上都会脱离文档流,因此需要设置zIndex让它相比正常流的元素更上层
366
+ instance.zIndex(1)
367
+ }
368
+ if (style.position === 'relative') {
369
+ instance.offset({
370
+ x: style.left || 0,
371
+ y: style.top || 0,
372
+ })
373
+ // 绝对定位和固定定位在web上都会脱离文档流,因此需要设置zIndex让它相比正常流的元素更上层
374
+ instance.zIndex(1)
375
+ }
376
+ if (!isUndefined(style.zIndex)) {
377
+ // 为了适应position不设置z-index也能高于同层级组件,估且让设置了z-index的会更高一级
378
+ instance.zIndex(style.zIndex + 1)
379
+ }
380
+ if (!isUndefined(style.boxShadow)) {
381
+ instance.shadow({
382
+ radius: convertVp2Px(style.boxShadow.radius),
383
+ color: style.boxShadow.color,
384
+ offsetX: convertVp2Px(style.boxShadow.offsetX),
385
+ offsetY: convertVp2Px(style.boxShadow.offsetY),
386
+ fill: style.boxShadow.fill,
387
+ })
388
+ }
389
+ }
390
+
391
+ export const pseudoModify = new PseudoStyleModify()
392
+ export const rowModify = new RowStyleModify()
393
+ export const columnModify = new ColumnStyleModify()
394
+ export const textModify = new TextStyleModify()
395
+
396
+ export default new CommonStyleModify()
@@ -1,9 +1,9 @@
1
1
  import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
2
2
 
3
- import { createLazyChildren } from './render'
4
- import { getNodeThresholds, getNormalAttributes, shouldBindEvent } from './utils/helper'
3
+ import commonStyleModify from './style'
4
+ import { getNodeThresholds, shouldBindEvent } from './utils/helper'
5
5
 
6
- import type { TaroStyleType, TaroSwiperElement, TaroEvent, TaroAny } from '@tarojs/runtime'
6
+ import type { TaroSwiperElement, TaroEvent, TaroAny } from '@tarojs/runtime'
7
7
 
8
8
  interface SwiperAttrs {
9
9
  index?: number
@@ -13,37 +13,8 @@ interface SwiperAttrs {
13
13
  vertical?: boolean
14
14
  autoPlay?: boolean
15
15
  indicator?: boolean
16
- }
17
-
18
- @Extend(Swiper)
19
- function swiperStyle (style: TaroStyleType) {
20
- .id(style.id)
21
- .key(style.id)
22
- .padding(style.padding)
23
- .margin(style.margin)
24
- .width(style.width)
25
- .height(style.height)
26
- .constraintSize(style.constraintSize)
27
- .flexGrow(style.flexGrow)
28
- .flexShrink(style.flexShrink)
29
- .flexBasis(style.flexBasis)
30
- .alignSelf(style.alignSelf)
31
- .backgroundColor(style.backgroundColor)
32
- .backgroundImage(style.backgroundImage, style.backgroundRepeat)
33
- .backgroundImageSize(style.backgroundImageSize)
34
- .backgroundImagePosition(style.backgroundImagePosition)
35
- .rotate(style.rotate)
36
- .scale(style.scale)
37
- .translate(style.translate)
38
- .transform(style.transform)
39
- .borderStyle(style.borderStyle)
40
- .borderWidth(style.borderWidth)
41
- .borderColor(style.borderColor)
42
- .borderRadius(style.borderRadius)
43
- .linearGradient(style.linearGradient)
44
- .zIndex(style.zIndex)
45
- .opacity(style.opacity)
46
- .clip(style.clip)
16
+ nextMargin?: Length
17
+ prevMargin?: Length
47
18
  }
48
19
 
49
20
  @Extend(Swiper)
@@ -55,6 +26,8 @@ function swiperAttr (attr: SwiperAttrs) {
55
26
  .vertical(attr.vertical)
56
27
  .autoPlay(attr.autoPlay)
57
28
  .indicator(attr.indicator)
29
+ .nextMargin(attr.nextMargin)
30
+ .prevMargin(attr.prevMargin)
58
31
  }
59
32
 
60
33
  function getSwiperAttributes (node: TaroSwiperElement): SwiperAttrs {
@@ -67,27 +40,65 @@ function getSwiperAttributes (node: TaroSwiperElement): SwiperAttrs {
67
40
  swiperAttrs.vertical = _attrs.vertical || false
68
41
  swiperAttrs.autoPlay = _attrs.autoplay || false
69
42
  swiperAttrs.indicator = _attrs.indicatorDots || false
43
+ swiperAttrs.nextMargin = _attrs.nextMargin || 0
44
+ swiperAttrs.prevMargin = _attrs.previousMargin || 0
70
45
  return swiperAttrs
71
46
  }
72
47
 
73
- @Builder
74
- export default function TaroSwiper (node: TaroSwiperElement) {
75
- Swiper(node.controller) {
76
- createLazyChildren(node)
48
+ @Component
49
+ export default struct TaroSwiper {
50
+ @Builder customBuilder() {}
51
+ @BuilderParam createLazyChildren: (node: TaroSwiperElement) => void = this.customBuilder
52
+ @ObjectLink node: TaroSwiperElement
53
+ @State overwriteStyle: Record<string, TaroAny> = {}
54
+
55
+ aboutToAppear(): void {
56
+ if (this.node) {
57
+ this.node._instance = this
58
+ }
59
+ }
60
+
61
+ build () {
62
+ Swiper(this.node.controller) {
63
+ this.createLazyChildren(this.node)
64
+ }
65
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
66
+ .swiperAttr(getSwiperAttributes(this.node))
67
+ .indicatorStyle({
68
+ color: this.node.getAttribute('indicatorColor'),
69
+ selectedColor: this.node.getAttribute('indicatorActiveColor')
70
+ })
71
+ .onChange((index: number) => {
72
+ const event: TaroEvent = createTaroEvent('change', { detail: { current: index } }, this.node)
73
+ eventHandler(event, 'change', this.node)
74
+ })
75
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
76
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
77
+ this.node._nodeInfo.areaInfo = res[1]
78
+ }))
79
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
80
+ .onGestureSwipe(shouldBindEvent((index: number, extraInfo: SwiperAnimationEvent) => {
81
+ const currentOffset = extraInfo.currentOffset || 0
82
+ // 判断设置的滚动方向
83
+ const isVertical = this.node._attrs.vertical || false
84
+ let event: TaroEvent
85
+ if (isVertical) {
86
+ event = createTaroEvent('transition', { detail: { dx: 0, dy: currentOffset } }, this.node)
87
+ } else {
88
+ event = createTaroEvent('transition', { detail: { dx: currentOffset, dy: 0 } }, this.node)
89
+ }
90
+ eventHandler(event, 'transition', this.node)
91
+ }, this.node, ['transition']))
92
+ .onTouch(shouldBindEvent((event: TouchEvent) => {
93
+ if (event.type === TouchType.Down) {
94
+ eventHandler(event, 'touchStart', this.node)
95
+ }
96
+ if (event.type === TouchType.Up) {
97
+ eventHandler(event, 'touchEnd', this.node)
98
+ }
99
+ if (event.type === TouchType.Move) {
100
+ eventHandler(event, 'touchMove', this.node)
101
+ }
102
+ }, this.node, ['touchstart', 'touchmove', 'touchend']))
77
103
  }
78
- .swiperStyle(getNormalAttributes(node))
79
- .swiperAttr(getSwiperAttributes(node))
80
- .indicatorStyle({
81
- color: node.getAttribute('indicatorColor'),
82
- selectedColor: node.getAttribute('indicatorActiveColor')
83
- })
84
- .onChange((index: number) => {
85
- const event: TaroEvent = createTaroEvent('change', { detail: { current: index } }, node)
86
- eventHandler(event, 'change', node)
87
- })
88
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
89
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
90
- node._nodeInfo.areaInfo = res[1]
91
- }))
92
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
93
104
  }
@@ -1,44 +1,14 @@
1
1
  import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
2
2
 
3
- import { getNodeThresholds, shouldBindEvent, getNormalAttributes } from './utils/helper'
3
+ import commonStyleModify from './style'
4
+ import { getNodeThresholds, shouldBindEvent } from './utils/helper'
4
5
 
5
- import type { TaroAny, TaroStyleType, TaroSwitchElement, TaroEvent } from '@tarojs/runtime'
6
+ import type { TaroAny, TaroSwitchElement, TaroEvent } from '@tarojs/runtime'
6
7
 
7
8
  interface SwitchAttrs {
8
9
  selectedColor?: ResourceColor
9
10
  }
10
11
 
11
- @Extend(Toggle)
12
- function styles (style: TaroStyleType) {
13
- .id(style.id)
14
- .key(style.id)
15
- .padding(style.padding)
16
- .margin(style.margin)
17
- .width(style.width)
18
- .height(style.height)
19
- .constraintSize(style.constraintSize)
20
- .flexGrow(style.flexGrow)
21
- .flexShrink(style.flexShrink)
22
- .flexBasis(style.flexBasis)
23
- .alignSelf(style.alignSelf)
24
- .backgroundColor(style.backgroundColor)
25
- .backgroundImage(style.backgroundImage, style.backgroundRepeat)
26
- .backgroundImageSize(style.backgroundImageSize)
27
- .backgroundImagePosition(style.backgroundImagePosition)
28
- .rotate(style.rotate)
29
- .scale(style.scale)
30
- .translate(style.translate)
31
- .transform(style.transform)
32
- .borderStyle(style.borderStyle)
33
- .borderWidth(style.borderWidth)
34
- .borderColor(style.borderColor)
35
- .borderRadius(style.borderRadius)
36
- .linearGradient(style.linearGradient)
37
- .zIndex(style.zIndex)
38
- .opacity(style.opacity)
39
- .clip(style.clip)
40
- }
41
-
42
12
  @Extend(Toggle)
43
13
  function attrs(attr: SwitchAttrs) {
44
14
  .selectedColor(attr.selectedColor)
@@ -56,28 +26,47 @@ function themeStyles(isDisabled: boolean) {
56
26
  .opacity(isDisabled ? 0.4 : 1)
57
27
  }
58
28
 
59
- @Builder
60
- export default function TaroSwitch (node: TaroSwitchElement) {
61
- Toggle({
62
- type: node._attrs.type !== 'checkbox' ? ToggleType.Switch : ToggleType.Checkbox,
63
- isOn: node.checked,
64
- })
65
- .styles(getNormalAttributes(node))
66
- .attrs(getAttributes(node))
67
- .themeStyles(!!node._attrs.disabled)
68
- .onChange((isOn: boolean) => {
69
- if (!node?._attrs.disabled) {
70
- const event: TaroEvent = createTaroEvent('change', { detail: { value: isOn } }, node)
29
+ @Component
30
+ export default struct TaroSwitch {
31
+ @Builder customBuilder() {}
32
+ @BuilderParam createLazyChildren: (node: TaroSwitchElement) => void = this.customBuilder
33
+ @ObjectLink node: TaroSwitchElement
34
+ @State overwriteStyle: Record<string, TaroAny> = {}
71
35
 
72
- node.updateCheckedValue(isOn)
73
- eventHandler(event, 'change', node)
74
- } else {
75
- node.updateComponent()
76
- }
36
+ aboutToAppear () {
37
+ if (this.node && !this.node._isInit) {
38
+ this.node._isInit = true
39
+ this.node._instance = this
40
+ this.node._reset = this.node.checked || false
41
+ }
42
+ }
43
+
44
+ build () {
45
+ Toggle({
46
+ type: this.node._attrs.type !== 'checkbox' ? ToggleType.Switch : ToggleType.Checkbox,
47
+ isOn: this.node.checked,
77
48
  })
78
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
79
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
80
- node._nodeInfo.areaInfo = res[1]
81
- }))
82
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
49
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
50
+ .attrs(getAttributes(this.node))
51
+ .themeStyles(!!this.node._attrs.disabled)
52
+ .onChange((isOn: boolean) => {
53
+ if (this.node) {
54
+ if (!this.node?._attrs.disabled) {
55
+ const event: TaroEvent = createTaroEvent('change', { detail: { value: isOn } }, this.node)
56
+
57
+ this.node.updateCheckedValue(isOn)
58
+ eventHandler(event, 'change', this.node)
59
+ } else {
60
+ this.node.updateComponent()
61
+ }
62
+ }
63
+ })
64
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
65
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
66
+ if (this.node) {
67
+ this.node._nodeInfo.areaInfo = res[1]
68
+ }
69
+ }))
70
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
71
+ }
83
72
  }
@@ -35,6 +35,8 @@ export const TaroAdTagName = 'ad'
35
35
  export const TaroWebViewTagName = 'web-view'
36
36
  export const TaroBlockTagName = 'block'
37
37
  export const TaroMapTagName = 'map'
38
+ export const TaroPageMetaTagName = 'page-meta'
39
+ export const TaroNavigationBarTagName = 'navigation-bar'
38
40
  export const TaroSlotTagName = 'slot'
39
41
  export const TaroNativeSlotTagName = 'native-slot'
40
42
  export const TaroCustomWrapperTagName = 'custom-wrapper'
@@ -47,3 +49,7 @@ export const TaroListTagName = 'list'
47
49
  export const TaroListItemTagName = 'list-item'
48
50
  export const TaroOpenDataTagName = 'open-data'
49
51
  export const TaroIgnoreTagName = 'ignore'
52
+
53
+ export const TaroStickySectionTagName = 'sticky-section'
54
+ export const TaroStickyHeaderTagName = 'sticky-header'
55
+ export const TaroListViewTagName = 'list-view'