@tarojs/plugin-platform-harmony-ets 4.0.0-beta.5 → 4.0.0-beta.50

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