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

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