@tarojs/plugin-platform-harmony-ets 4.0.0-alpha.2 → 4.0.0-alpha.21

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 (129) 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/framework/index.ts +1 -5
  5. package/dist/apis/index.ts +25 -17
  6. package/dist/apis/media/image/index.ts +1 -1
  7. package/dist/apis/storage/index.ts +146 -78
  8. package/dist/apis/ui/animation/animation.ts +71 -29
  9. package/dist/apis/ui/background.ts +2 -1
  10. package/dist/apis/ui/interaction/index.ts +42 -59
  11. package/dist/apis/ui/navigation-bar/index.ts +1 -1
  12. package/dist/apis/ui/pull-down-refresh.ts +9 -3
  13. package/dist/apis/ui/scroll/index.ts +5 -5
  14. package/dist/apis/ui/tab-bar.ts +3 -3
  15. package/dist/apis/utils/index.ts +2 -1
  16. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  17. package/dist/apis/wxml/selectorQuery.ts +26 -13
  18. package/dist/components-harmony-ets/button.ets +64 -34
  19. package/dist/components-harmony-ets/canvas.ets +51 -0
  20. package/dist/components-harmony-ets/checkbox.ets +72 -61
  21. package/dist/components-harmony-ets/form.ets +51 -29
  22. package/dist/components-harmony-ets/icon.ets +31 -19
  23. package/dist/components-harmony-ets/image.ets +34 -14
  24. package/dist/components-harmony-ets/index.ets +92 -0
  25. package/dist/components-harmony-ets/innerHtml.ets +11 -6
  26. package/dist/components-harmony-ets/input.ets +49 -41
  27. package/dist/components-harmony-ets/label.ets +71 -44
  28. package/dist/components-harmony-ets/listView.ets +26 -0
  29. package/dist/components-harmony-ets/movableArea.ets +126 -0
  30. package/dist/components-harmony-ets/movableView.ets +93 -0
  31. package/dist/components-harmony-ets/navigationBar.ets +65 -0
  32. package/dist/components-harmony-ets/pageMeta.ets +94 -0
  33. package/dist/components-harmony-ets/picker.ets +42 -38
  34. package/dist/components-harmony-ets/progress.ets +52 -0
  35. package/dist/components-harmony-ets/pseudo.ets +80 -0
  36. package/dist/components-harmony-ets/radio.ets +74 -64
  37. package/dist/components-harmony-ets/richText.ets +14 -30
  38. package/dist/components-harmony-ets/scrollList.ets +94 -0
  39. package/dist/components-harmony-ets/scrollView.ets +61 -57
  40. package/dist/components-harmony-ets/slider.ets +18 -14
  41. package/dist/components-harmony-ets/stickySection.ets +42 -0
  42. package/dist/components-harmony-ets/style.ets +381 -130
  43. package/dist/components-harmony-ets/swiper.ets +61 -20
  44. package/dist/components-harmony-ets/switch.ets +36 -32
  45. package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
  46. package/dist/components-harmony-ets/text.ets +135 -49
  47. package/dist/components-harmony-ets/textArea.ets +50 -35
  48. package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
  49. package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -2
  50. package/dist/components-harmony-ets/utils/flexManager.ets +49 -19
  51. package/dist/components-harmony-ets/utils/helper.ets +18 -5
  52. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  53. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  54. package/dist/components-harmony-ets/utils/index.ts +54 -50
  55. package/dist/components-harmony-ets/utils/styles.ets +170 -93
  56. package/dist/components-harmony-ets/video.ets +34 -21
  57. package/dist/components-harmony-ets/view.ets +63 -52
  58. package/dist/components-harmony-ets/webView.ets +40 -34
  59. package/dist/index.d.ts +152 -0
  60. package/dist/index.js +99 -55
  61. package/dist/index.js.map +1 -1
  62. package/dist/runtime-ets/bom/document.ts +6 -4
  63. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
  64. package/dist/runtime-ets/bom/window.ts +7 -0
  65. package/dist/runtime-ets/current.ts +3 -0
  66. package/dist/runtime-ets/dom/bind.ts +28 -12
  67. package/dist/runtime-ets/dom/class-list.ts +2 -2
  68. package/dist/runtime-ets/dom/cssNesting.ts +419 -0
  69. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +28 -42
  70. package/dist/runtime-ets/dom/document.ts +8 -11
  71. package/dist/runtime-ets/dom/element/canvas.ts +136 -0
  72. package/dist/runtime-ets/dom/element/element.ts +348 -57
  73. package/dist/runtime-ets/dom/element/form.ts +31 -26
  74. package/dist/runtime-ets/dom/element/index.ts +30 -2
  75. package/dist/runtime-ets/dom/element/movableArea.ts +11 -0
  76. package/dist/runtime-ets/dom/element/movableView.ts +244 -0
  77. package/dist/runtime-ets/dom/element/normal.ts +35 -8
  78. package/dist/runtime-ets/dom/element/progress.ts +11 -0
  79. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  80. package/dist/runtime-ets/dom/element/text.ts +1 -8
  81. package/dist/runtime-ets/dom/element/video.ts +5 -4
  82. package/dist/runtime-ets/dom/element/webView.ts +12 -5
  83. package/dist/runtime-ets/dom/event.ts +2 -4
  84. package/dist/runtime-ets/dom/eventTarget.ts +2 -3
  85. package/dist/runtime-ets/dom/node.ts +54 -29
  86. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +416 -235
  87. package/dist/runtime-ets/dom/stylesheet/index.ts +29 -311
  88. package/dist/runtime-ets/dom/stylesheet/type.ts +51 -9
  89. package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
  90. package/dist/runtime-ets/index.ts +2 -1
  91. package/dist/runtime-ets/interface/event.ts +1 -1
  92. package/dist/runtime-ets/utils/index.ts +73 -13
  93. package/dist/runtime-ets/utils/info.ts +2 -2
  94. package/dist/runtime-framework/react/app.ts +9 -4
  95. package/dist/runtime-framework/react/hooks.ts +0 -1
  96. package/dist/runtime-framework/react/index.ts +0 -2
  97. package/dist/runtime-framework/react/native-page.ts +154 -77
  98. package/dist/runtime-framework/react/page.ts +3 -8
  99. package/dist/runtime-framework/solid/app.ts +25 -45
  100. package/dist/runtime-framework/solid/connect.ts +21 -3
  101. package/dist/runtime-framework/solid/hooks.ts +16 -11
  102. package/dist/runtime-framework/solid/index.ts +6 -2
  103. package/dist/runtime-framework/solid/page.ts +84 -30
  104. package/dist/runtime-framework/solid/reconciler/props.ts +70 -25
  105. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  106. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  107. package/dist/runtime-framework/solid/utils/index.ts +0 -2
  108. package/dist/runtime-utils.d.ts +827 -0
  109. package/dist/runtime-utils.js +435 -218
  110. package/dist/runtime-utils.js.map +1 -1
  111. package/dist/runtime.d.ts +1 -0
  112. package/dist/runtime.js +435 -218
  113. package/dist/runtime.js.map +1 -1
  114. package/index.js +3 -1
  115. package/package.json +14 -15
  116. package/static/media/cancel.svg +1 -1
  117. package/static/media/circle.svg +1 -1
  118. package/static/media/clear.svg +1 -1
  119. package/static/media/download.svg +1 -1
  120. package/static/media/info.svg +1 -1
  121. package/static/media/info_circle.svg +1 -1
  122. package/static/media/search.svg +1 -1
  123. package/static/media/success.svg +1 -1
  124. package/static/media/success_no_circle.svg +1 -1
  125. package/static/media/warn.svg +1 -1
  126. package/types/harmony.d.ts +4 -0
  127. package/types/index.d.ts +4 -0
  128. package/types/runtime.d.ts +1 -1
  129. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
@@ -1,154 +1,405 @@
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, convertVp2Px } from './utils'
3
5
  import { getNormalAttributes } from './utils/helper'
6
+ import { isMaxWidthView } from './utils/styles'
7
+ import { FlexManager } from './utils/flexManager'
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
+ }
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
+ }
8
59
 
9
- function getLeft (node: TaroElement): Length | number {
10
- return node?.hmStyle?.left || 0
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
+ 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))
141
135
  }
142
- if (this.node.hmStyle?.position === 'relative') {
143
- instance.offset({
144
- x: getLeft(this.node),
145
- y: getTop(this.node)
146
- })
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))
147
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
+ if (!isUndefined(style.wordBreak)) {
233
+ if (style.wordBreak == 'break-all') {
234
+ instance.wordBreak(WordBreak.BREAK_ALL)
235
+ } else if (style.wordBreak == 'break-word') {
236
+ instance.wordBreak(WordBreak.BREAK_WORD)
237
+ } else if (style.wordBreak == 'normal') {
238
+ instance.wordBreak(WordBreak.NORMAL)
148
239
  }
149
240
  }
150
241
  }
151
242
 
152
- const modify = new CommonStyleModify()
243
+ export function setNormalAttributeIntoInstance(instance: CommonAttribute, style: TaroStyleType, node?: TaroElement | null) {
244
+ instance.renderFit(RenderFit.RESIZE_FILL)
245
+ if (!isUndefined(style.id)) {
246
+ instance.id(style.id)
247
+ instance.key(style.id)
248
+ }
249
+ if (!isUndefined(style.display) || !isUndefined(style.visibility)) {
250
+ instance.visibility(style.display === 'none'
251
+ ? Visibility.None :
252
+ !isUndefined(style.visibility)
253
+ ? (style.visibility === 'hidden' ? Visibility.Hidden : Visibility.Visible)
254
+ : Visibility.Visible
255
+ )
256
+ }
257
+ if (!isUndefined(style.flexGrow)) {
258
+ instance.flexGrow(style.flexGrow)
259
+ }
260
+ if (!isUndefined(style.flexShrink)) {
261
+ instance.flexShrink(style.flexShrink)
262
+ }
263
+ if (!isUndefined(style.flexBasis)) {
264
+ instance.flexBasis(style.flexBasis)
265
+ }
266
+ if (!isUndefined(style.alignSelf)) {
267
+ instance.alignSelf(style.alignSelf)
268
+ }
269
+ if (!isUndefined(style.paddingTop) || !isUndefined(style.paddingRight) || !isUndefined(style.paddingBottom) || !isUndefined(style.paddingLeft)) {
270
+ instance.padding({
271
+ top: style.paddingTop,
272
+ right: style.paddingRight,
273
+ bottom: style.paddingBottom,
274
+ left: style.paddingLeft
275
+ })
276
+ }
277
+ if (!isUndefined(style.marginTop) || !isUndefined(style.marginRight) || !isUndefined(style.marginBottom) || !isUndefined(style.marginLeft)) {
278
+ instance.margin({
279
+ top: style.marginTop,
280
+ right: style.marginRight,
281
+ bottom: style.marginBottom,
282
+ left: style.marginLeft
283
+ })
284
+ }
285
+ if (node) {
286
+ instance.width(isMaxWidthView(node as TaroElement) && isUndefined(style.width) ? '100%' : style.width)
287
+ } else {
288
+ if (!isUndefined(style.width)) {
289
+ instance.width(style.width)
290
+ }
291
+ }
292
+ if (!isUndefined(style.height)) {
293
+ instance.height(style.height)
294
+ }
295
+ if (!isUndefined(style.minWidth) || !isUndefined(style.maxWidth) || !isUndefined(style.minHeight) || !isUndefined(style.maxHeight)) {
296
+ instance.constraintSize({
297
+ minWidth: style.minWidth,
298
+ maxWidth: style.maxWidth,
299
+ minHeight: style.minHeight,
300
+ maxHeight: style.maxHeight
301
+ })
302
+ }
303
+ if (!isUndefined(style.backgroundColor)) {
304
+ instance.backgroundColor(style.backgroundColor)
305
+ }
306
+ if (!isUndefined(style.backgroundImage)) {
307
+ if (style.backgroundImage.center) {
308
+ // radialGradient
309
+ instance.radialGradient(style.backgroundImage)
310
+ } else if (style.backgroundImage.colors) {
311
+ // linearGradient
312
+ instance.linearGradient(style.backgroundImage)
313
+ } else {
314
+ instance.backgroundImage(style.backgroundImage?.src, style.backgroundRepeat)
315
+ }
316
+ }
317
+ if (!isUndefined(style.backgroundSize)) {
318
+ instance.backgroundImageSize(style.backgroundSize)
319
+ }
320
+ if (!isUndefined(style.backgroundPosition)) {
321
+ if (typeof style.backgroundPosition !== 'number') {
322
+ let pos = computeBackgroundPosition(style)
323
+ instance.backgroundImagePosition({
324
+ x: pos.offsetX,
325
+ y: pos.offsetY,
326
+ })
327
+ } else {
328
+ instance.backgroundImagePosition(style.backgroundPosition)
329
+ }
330
+ }
331
+ if (!isUndefined(style.borderTopStyle) || !isUndefined(style.borderRightStyle) || !isUndefined(style.borderBottomStyle) || !isUndefined(style.borderLeftStyle)) {
332
+ instance.borderStyle({
333
+ top: style.borderTopStyle,
334
+ right: style.borderRightStyle,
335
+ bottom: style.borderBottomStyle,
336
+ left: style.borderLeftStyle
337
+ })
338
+ }
339
+ if (!isUndefined(style.borderTopWidth) || !isUndefined(style.borderRightWidth) || !isUndefined(style.borderBottomWidth) || !isUndefined(style.borderLeftWidth)) {
340
+ instance.borderWidth({
341
+ top: style.borderTopWidth,
342
+ right: style.borderRightWidth,
343
+ bottom: style.borderBottomWidth,
344
+ left: style.borderLeftWidth
345
+ })
346
+ }
347
+ if (!isUndefined(style.borderTopColor) || !isUndefined(style.borderRightColor) || !isUndefined(style.borderBottomColor) || !isUndefined(style.borderLeftColor)) {
348
+ instance.borderColor({
349
+ top: style.borderTopColor,
350
+ right: style.borderRightColor,
351
+ bottom: style.borderBottomColor,
352
+ left: style.borderLeftColor
353
+ })
354
+ }
355
+ if (!isUndefined(style.borderTopLeftRadius) || !isUndefined(style.borderTopRightRadius) || !isUndefined(style.borderBottomLeftRadius) || !isUndefined(style.borderBottomRightRadius)) {
356
+ instance.borderRadius({
357
+ topLeft: style.borderTopLeftRadius,
358
+ topRight: style.borderTopRightRadius,
359
+ bottomLeft: style.borderBottomLeftRadius,
360
+ bottomRight: style.borderBottomRightRadius
361
+ })
362
+ }
363
+ if (!isUndefined(style.opacity)) {
364
+ instance.opacity(style.opacity)
365
+ }
366
+ if (!isUndefined(style.overflow)) {
367
+ instance.clip(style.overflow === 'hidden')
368
+ }
369
+ if (style.position === 'absolute' || style.position === 'fixed') {
370
+ instance.position({
371
+ x: style.left || 0,
372
+ y: style.top || 0,
373
+ })
374
+ // 绝对定位和固定定位在web上都会脱离文档流,因此需要设置zIndex让它相比正常流的元素更上层
375
+ instance.zIndex(1)
376
+ }
377
+ if (style.position === 'relative') {
378
+ instance.offset({
379
+ x: style.left || 0,
380
+ y: style.top || 0,
381
+ })
382
+ // 绝对定位和固定定位在web上都会脱离文档流,因此需要设置zIndex让它相比正常流的元素更上层
383
+ instance.zIndex(1)
384
+ }
385
+ if (!isUndefined(style.zIndex)) {
386
+ // 为了适应position不设置z-index也能高于同层级组件,估且让设置了z-index的会更高一级
387
+ instance.zIndex(style.zIndex + 1)
388
+ }
389
+ if (!isUndefined(style.boxShadow)) {
390
+ instance.shadow({
391
+ radius: convertVp2Px(style.boxShadow.radius),
392
+ color: style.boxShadow.color,
393
+ offsetX: convertVp2Px(style.boxShadow.offsetX),
394
+ offsetY: convertVp2Px(style.boxShadow.offsetY),
395
+ fill: style.boxShadow.fill,
396
+ })
397
+ }
398
+ }
399
+
400
+ export const pseudoModify = new PseudoStyleModify()
401
+ export const rowModify = new RowStyleModify()
402
+ export const columnModify = new ColumnStyleModify()
403
+ export const textModify = new TextStyleModify()
153
404
 
154
- export default modify
405
+ 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,65 @@ 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))
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: vp2px(currentOffset) } }, this.node)
87
+ } else {
88
+ event = createTaroEvent('transition', { detail: { dx: vp2px(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']))
47
103
  }
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
104
  }