@tarojs/plugin-platform-harmony-ets 4.0.0-beta.4 → 4.0.0-beta.41

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