@tarojs/plugin-platform-harmony-ets 4.0.0-beta.2 → 4.0.0-beta.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 (87) hide show
  1. package/dist/apis/base/system.ts +53 -20
  2. package/dist/apis/framework/index.ts +1 -5
  3. package/dist/apis/index.ts +3 -1
  4. package/dist/apis/network/request.ts +5 -5
  5. package/dist/apis/route/index.ts +15 -0
  6. package/dist/apis/storage/index.ts +124 -60
  7. package/dist/apis/wxml/IntersectionObserver.ts +5 -3
  8. package/dist/apis/wxml/index.ts +2 -0
  9. package/dist/components-harmony-ets/button.ets +41 -78
  10. package/dist/components-harmony-ets/checkbox.ets +19 -209
  11. package/dist/components-harmony-ets/form.ets +38 -160
  12. package/dist/components-harmony-ets/icon.ets +31 -83
  13. package/dist/components-harmony-ets/image.ets +22 -78
  14. package/dist/components-harmony-ets/innerHtml.ets +11 -6
  15. package/dist/components-harmony-ets/input.ets +10 -67
  16. package/dist/components-harmony-ets/label.ets +52 -173
  17. package/dist/components-harmony-ets/movableArea.ets +89 -0
  18. package/dist/components-harmony-ets/movableView.ets +67 -0
  19. package/dist/components-harmony-ets/picker.ets +32 -147
  20. package/dist/components-harmony-ets/progress.ets +47 -0
  21. package/dist/components-harmony-ets/pseudo.ets +80 -0
  22. package/dist/components-harmony-ets/radio.ets +19 -210
  23. package/dist/components-harmony-ets/richText.ets +22 -102
  24. package/dist/components-harmony-ets/scrollView.ets +66 -169
  25. package/dist/components-harmony-ets/slider.ets +10 -72
  26. package/dist/components-harmony-ets/style.ets +244 -0
  27. package/dist/components-harmony-ets/swiper.ets +30 -87
  28. package/dist/components-harmony-ets/switch.ets +9 -71
  29. package/dist/components-harmony-ets/text.ets +38 -89
  30. package/dist/components-harmony-ets/textArea.ets +10 -67
  31. package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
  32. package/dist/components-harmony-ets/utils/DynamicCenter.ts +1 -1
  33. package/dist/components-harmony-ets/utils/flexManager.ets +8 -7
  34. package/dist/components-harmony-ets/utils/helper.ets +5 -4
  35. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  36. package/dist/components-harmony-ets/utils/index.ts +55 -2
  37. package/dist/components-harmony-ets/utils/styles.ets +45 -85
  38. package/dist/components-harmony-ets/video.ets +33 -88
  39. package/dist/components-harmony-ets/view.ets +47 -160
  40. package/dist/components-harmony-ets/webView.ets +44 -99
  41. package/dist/index.d.ts +151 -0
  42. package/dist/index.js +58 -29
  43. package/dist/index.js.map +1 -1
  44. package/dist/runtime-ets/bom/window.ts +4 -2
  45. package/dist/runtime-ets/current.ts +2 -0
  46. package/dist/runtime-ets/dom/bind.ts +0 -1
  47. package/dist/runtime-ets/dom/cssNesting.ts +311 -0
  48. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +15 -40
  49. package/dist/runtime-ets/dom/document.ts +21 -8
  50. package/dist/runtime-ets/dom/element/element.ts +53 -9
  51. package/dist/runtime-ets/dom/element/form.ts +11 -4
  52. package/dist/runtime-ets/dom/element/index.ts +12 -1
  53. package/dist/runtime-ets/dom/element/movableArea.ts +12 -0
  54. package/dist/runtime-ets/dom/element/movableView.ts +193 -0
  55. package/dist/runtime-ets/dom/element/normal.ts +8 -3
  56. package/dist/runtime-ets/dom/element/progress.ts +13 -0
  57. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  58. package/dist/runtime-ets/dom/element/text.ts +1 -0
  59. package/dist/runtime-ets/dom/element/video.ts +1 -0
  60. package/dist/runtime-ets/dom/element/webView.ts +8 -0
  61. package/dist/runtime-ets/dom/event.ts +0 -1
  62. package/dist/runtime-ets/dom/eventTarget.ts +0 -3
  63. package/dist/runtime-ets/dom/node.ts +18 -17
  64. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +184 -207
  65. package/dist/runtime-ets/dom/stylesheet/index.ts +28 -308
  66. package/dist/runtime-ets/dom/stylesheet/type.ts +18 -6
  67. package/dist/runtime-ets/dom/stylesheet/util.ts +19 -15
  68. package/dist/runtime-ets/index.ts +2 -2
  69. package/dist/runtime-ets/interface/event.ts +1 -1
  70. package/dist/runtime-ets/utils/index.ts +24 -9
  71. package/dist/runtime-framework/react/app.ts +5 -1
  72. package/dist/runtime-framework/react/hooks.ts +3 -3
  73. package/dist/runtime-framework/react/native-page.ts +14 -9
  74. package/dist/runtime-framework/react/page.ts +1 -0
  75. package/dist/runtime-framework/solid/hooks.ts +3 -3
  76. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  77. package/dist/runtime-framework/solid/utils/index.ts +0 -2
  78. package/dist/runtime-utils.d.ts +825 -0
  79. package/dist/runtime-utils.js +185 -91
  80. package/dist/runtime-utils.js.map +1 -1
  81. package/dist/runtime.d.ts +1 -0
  82. package/dist/runtime.js +185 -91
  83. package/dist/runtime.js.map +1 -1
  84. package/index.js +3 -1
  85. package/package.json +10 -10
  86. package/types/index.d.ts +4 -0
  87. package/dist/runtime-ets/utils/bind.ts +0 -24
@@ -0,0 +1,244 @@
1
+ import type { HarmonyStyle, TaroElement, TaroStyleType } from '@tarojs/runtime'
2
+ import { isUndefined } from '../shared'
3
+ import { computeBackgroundPosition } from './utils'
4
+ import { getNormalAttributes } from './utils/helper'
5
+ import { isMaxWidthView } from './utils/styles'
6
+
7
+ class CommonStyleModify implements AttributeModifier<CommonAttribute> {
8
+ node: TaroElement | null = null
9
+ style: TaroStyleType | null = null
10
+ initStyle?: TaroStyleType
11
+
12
+ setNode (node: TaroElement, initStyle?: TaroStyleType) {
13
+ this.node = node
14
+ this.style = getNormalAttributes(this.node)
15
+ this.initStyle = initStyle
16
+ // 覆盖初始化样式
17
+ if (initStyle) {
18
+ Object.keys(initStyle).forEach(key => {
19
+ if (this.style && !this.style[key]) {
20
+ this.style[key] = initStyle[key]
21
+ }
22
+ })
23
+ }
24
+ return this
25
+ }
26
+
27
+ applyNormalAttribute(instance: CommonAttribute): void {
28
+ if (this.node && this.style) {
29
+ setNormalAttributeIntoInstance(instance, this.style, this.node)
30
+ }
31
+ }
32
+ }
33
+
34
+ class PseudoStyleModify implements AttributeModifier<CommonAttribute> {
35
+ style: TaroStyleType | null = null
36
+
37
+ setStyle (style: HarmonyStyle) {
38
+ this.style = style
39
+ return this
40
+ }
41
+
42
+ applyNormalAttribute(instance: CommonAttribute): void {
43
+ if (this.style) {
44
+ setNormalAttributeIntoInstance(instance, this.style)
45
+ }
46
+ }
47
+ }
48
+
49
+
50
+ class RowStyleModify extends CommonStyleModify {
51
+
52
+ applyNormalAttribute(instance: CommonAttribute): void {
53
+ if (this.style) {
54
+ setNormalAttributeIntoInstance(instance, this.style, this.node)
55
+ instance.constraintSize({
56
+ minWidth: this.style.minWidth || this.style.width,
57
+ maxWidth: this.style.maxWidth,
58
+ minHeight: this.style.minHeight,
59
+ maxHeight: this.style.maxHeight
60
+ })
61
+ }
62
+ }
63
+ }
64
+
65
+ class ColumnStyleModify extends CommonStyleModify {
66
+ applyNormalAttribute(instance: CommonAttribute): void {
67
+ if (this.style) {
68
+ setNormalAttributeIntoInstance(instance, this.style, this.node)
69
+ instance.constraintSize({
70
+ minWidth: this.style.minWidth,
71
+ maxWidth: this.style.maxWidth,
72
+ minHeight: this.style.minHeight || this.style.height,
73
+ maxHeight: this.style.maxHeight
74
+ })
75
+ }
76
+ }
77
+ }
78
+
79
+
80
+ function setNormalAttributeIntoInstance(instance: CommonAttribute, style: TaroStyleType, node?: TaroElement | null) {
81
+ if (!isUndefined(style.id)) {
82
+ instance.id(style.id)
83
+ instance.key(style.id)
84
+ }
85
+ if (!isUndefined(style.flexGrow)) {
86
+ instance.flexGrow(style.flexGrow)
87
+ }
88
+ if (!isUndefined(style.flexShrink)) {
89
+ instance.flexShrink(style.flexShrink)
90
+ }
91
+ if (!isUndefined(style.flexBasis)) {
92
+ instance.flexBasis(style.flexBasis)
93
+ }
94
+ if (!isUndefined(style.alignSelf)) {
95
+ instance.alignSelf(style.alignSelf)
96
+ }
97
+ if (!isUndefined(style.paddingTop) || !isUndefined(style.paddingRight) || !isUndefined(style.paddingBottom) || !isUndefined(style.paddingLeft)) {
98
+ instance.padding({
99
+ top: style.paddingTop,
100
+ right: style.paddingRight,
101
+ bottom: style.paddingBottom,
102
+ left: style.paddingLeft
103
+ })
104
+ }
105
+ if (!isUndefined(style.marginTop) || !isUndefined(style.marginRight) || !isUndefined(style.marginBottom) || !isUndefined(style.marginLeft)) {
106
+ instance.margin({
107
+ top: style.marginTop,
108
+ right: style.marginRight,
109
+ bottom: style.marginBottom,
110
+ left: style.marginLeft
111
+ })
112
+ }
113
+ if (node) {
114
+ instance.width(isMaxWidthView(node as TaroElement) && isUndefined(style.width) ? '100%' : style.width)
115
+ } else {
116
+ instance.width(style.width)
117
+ }
118
+ if (!isUndefined(style.height)) {
119
+ instance.height(style.height)
120
+ }
121
+ if (!isUndefined(style.minWidth) || !isUndefined(style.maxWidth) || !isUndefined(style.minHeight) || !isUndefined(style.maxHeight)) {
122
+ instance.constraintSize({
123
+ minWidth: style.minWidth,
124
+ maxWidth: style.maxWidth,
125
+ minHeight: style.minHeight,
126
+ maxHeight: style.maxHeight
127
+ })
128
+ }
129
+ if (!isUndefined(style.backgroundColor)) {
130
+ instance.backgroundColor(style.backgroundColor)
131
+ }
132
+ if (!isUndefined(style.backgroundImage)) {
133
+ if (style.backgroundImage.colors) {
134
+ instance.linearGradient(style.backgroundImage)
135
+ } else {
136
+ instance.backgroundImage(style.backgroundImage?.src, style.backgroundRepeat)
137
+ }
138
+ }
139
+ if (!isUndefined(style.backgroundSize)) {
140
+ instance.backgroundImageSize(style.backgroundSize)
141
+ }
142
+ if (!isUndefined(style.backgroundPosition)) {
143
+ if (typeof style.backgroundPosition !== 'number') {
144
+ let pos = computeBackgroundPosition(style)
145
+ instance.backgroundImagePosition({
146
+ x: pos.offsetX,
147
+ y: pos.offsetY,
148
+ })
149
+ } else {
150
+ instance.backgroundImagePosition(style.backgroundPosition)
151
+ }
152
+ }
153
+ if (!isUndefined(style.borderTopStyle) || !isUndefined(style.borderRightStyle) || !isUndefined(style.borderBottomStyle) || !isUndefined(style.borderLeftStyle)) {
154
+ instance.borderStyle({
155
+ top: style.borderTopStyle,
156
+ right: style.borderRightStyle,
157
+ bottom: style.borderBottomStyle,
158
+ left: style.borderLeftStyle
159
+ })
160
+ }
161
+ if (!isUndefined(style.borderTopWidth) || !isUndefined(style.borderRightWidth) || !isUndefined(style.borderBottomWidth) || !isUndefined(style.borderLeftWidth)) {
162
+ instance.borderWidth({
163
+ top: style.borderTopWidth,
164
+ right: style.borderRightWidth,
165
+ bottom: style.borderBottomWidth,
166
+ left: style.borderLeftWidth
167
+ })
168
+ }
169
+ if (!isUndefined(style.borderTopColor) || !isUndefined(style.borderRightColor) || !isUndefined(style.borderBottomColor) || !isUndefined(style.borderLeftColor)) {
170
+ instance.borderColor({
171
+ top: style.borderTopColor,
172
+ right: style.borderRightColor,
173
+ bottom: style.borderBottomColor,
174
+ left: style.borderLeftColor
175
+ })
176
+ }
177
+ if (!isUndefined(style.borderTopLeftRadius) || !isUndefined(style.borderTopRightRadius) || !isUndefined(style.borderBottomLeftRadius) || !isUndefined(style.borderBottomRightRadius)) {
178
+ instance.borderRadius({
179
+ topLeft: style.borderTopLeftRadius,
180
+ topRight: style.borderTopRightRadius,
181
+ bottomLeft: style.borderBottomLeftRadius,
182
+ bottomRight: style.borderBottomRightRadius
183
+ })
184
+ }
185
+ if (!isUndefined(style.zIndex)) {
186
+ instance.zIndex(style.zIndex)
187
+ }
188
+ if (!isUndefined(style.opacity)) {
189
+ instance.opacity(style.opacity)
190
+ }
191
+ if (!isUndefined(style.overflow)) {
192
+ instance.clip(style.overflow === 'hidden')
193
+ }
194
+ // if (!isUndefined(style.transformOrigin)) {
195
+ // instance.rotate({ centerX: style.transformOrigin.x, centerY: style.transformOrigin.y, angle: 0 })
196
+ // instance.scale({ centerX: style.transformOrigin.x, centerY: style.transformOrigin.y })
197
+ // }
198
+ if (!isUndefined(style.transform)) {
199
+ if (style.transform.Translate) {
200
+ instance.translate({
201
+ x: style.transform.Translate.x || 0,
202
+ y: style.transform.Translate.y || 0,
203
+ z: style.transform.Translate.z || 0,
204
+ })
205
+ }
206
+ if (style.transform.Scale) {
207
+ instance.scale({
208
+ x: style.transform.Scale.x || 0,
209
+ y: style.transform.Scale.y || 0,
210
+ z: style.transform.Scale.z || 0,
211
+ centerX: style.transformOrigin?.x || 0,
212
+ centerY: style.transformOrigin?.y || 0,
213
+ })
214
+ }
215
+ if (style.transform.Rotate) {
216
+ instance.rotate({
217
+ x: style.transform.Rotate.x || 0,
218
+ y: style.transform.Rotate.y || 0,
219
+ z: style.transform.Rotate.z || 0,
220
+ centerX: style.transformOrigin?.x || 0,
221
+ centerY: style.transformOrigin?.y || 0,
222
+ angle: 0
223
+ })
224
+ }
225
+ }
226
+ if (style.position === 'absolute' || style.position === 'fixed') {
227
+ instance.position({
228
+ x: style.left || 0,
229
+ y: style.top || 0,
230
+ })
231
+ }
232
+ if (style.position === 'relative') {
233
+ instance.offset({
234
+ x: style.left || 0,
235
+ y: style.top || 0,
236
+ })
237
+ }
238
+ }
239
+
240
+ export const pseudoModify = new PseudoStyleModify()
241
+ export const rowModify = new RowStyleModify()
242
+ export const columnModify = new ColumnStyleModify()
243
+
244
+ export default new CommonStyleModify()
@@ -1,9 +1,9 @@
1
1
  import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
2
2
 
3
- import { createLazyChildren } from './render'
4
- import { getNodeThresholds, getNormalAttributes, shouldBindEvent } from './utils/helper'
3
+ import commonStyleModify from './style'
4
+ import { getNodeThresholds, shouldBindEvent } from './utils/helper'
5
5
 
6
- import type { TaroStyleType, TaroSwiperElement, TaroEvent, TaroAny } from '@tarojs/runtime'
6
+ import type { TaroSwiperElement, TaroEvent, TaroAny } from '@tarojs/runtime'
7
7
 
8
8
  interface SwiperAttrs {
9
9
  index?: number
@@ -15,71 +15,6 @@ interface SwiperAttrs {
15
15
  indicator?: boolean
16
16
  }
17
17
 
18
- @Extend(Swiper)
19
- function swiperStyle (style: TaroStyleType) {
20
- .id(style.id)
21
- .key(style.id)
22
- .flexGrow(style.flexGrow)
23
- .flexShrink(style.flexShrink)
24
- .flexBasis(style.flexBasis)
25
- .alignSelf(style.alignSelf)
26
- .padding({
27
- top: style.paddingTop,
28
- right: style.paddingRight,
29
- bottom: style.paddingBottom,
30
- left: style.paddingLeft
31
- })
32
- .margin({
33
- top: style.marginTop,
34
- right: style.marginRight,
35
- bottom: style.marginBottom,
36
- left: style.marginLeft
37
- })
38
- .width(style.width)
39
- .height(style.height)
40
- .constraintSize({
41
- minWidth: style.minWidth,
42
- maxWidth: style.maxWidth,
43
- minHeight: style.minHeight,
44
- maxHeight: style.maxHeight
45
- })
46
- .backgroundColor(style.backgroundColor)
47
- .backgroundImage(style.backgroundImage?.src, style.backgroundRepeat)
48
- .backgroundImageSize(style.backgroundSize)
49
- .backgroundImagePosition(style.backgroundPosition)
50
- .borderStyle({
51
- top: style.borderTopStyle,
52
- right: style.borderRightStyle,
53
- bottom: style.borderBottomStyle,
54
- left: style.borderLeftStyle
55
- })
56
- .borderWidth({
57
- top: style.borderTopWidth,
58
- right: style.borderRightWidth,
59
- bottom: style.borderBottomWidth,
60
- left: style.borderLeftWidth
61
- })
62
- .borderColor({
63
- top: style.borderTopColor,
64
- right: style.borderRightColor,
65
- bottom: style.borderBottomColor,
66
- left: style.borderLeftColor
67
- })
68
- .borderRadius({
69
- topLeft: style.borderTopLeftRadius,
70
- topRight: style.borderTopRightRadius,
71
- bottomLeft: style.borderBottomLeftRadius,
72
- bottomRight: style.borderBottomRightRadius
73
- })
74
- .zIndex(style.zIndex)
75
- .opacity(style.opacity)
76
- .linearGradient(style.linearGradient)
77
- .clip(style.overflow)
78
- .rotate({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y, angle: 0 })
79
- .scale({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y })
80
- .transform(style.transform)
81
- }
82
-
83
18
  @Extend(Swiper)
84
19
  function swiperAttr (attr: SwiperAttrs) {
85
20
  .index(attr.index)
@@ -104,24 +39,32 @@ function getSwiperAttributes (node: TaroSwiperElement): SwiperAttrs {
104
39
  return swiperAttrs
105
40
  }
106
41
 
107
- @Builder
108
- export default function TaroSwiper (node: TaroSwiperElement) {
109
- Swiper(node.controller) {
110
- 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
+
48
+ build () {
49
+ if (this.node.hmStyle?.display !== 'none') {
50
+ Swiper(this.node.controller) {
51
+ this.createLazyChildren(this.node)
52
+ }
53
+ .attributeModifier(commonStyleModify.setNode(this.node))
54
+ .swiperAttr(getSwiperAttributes(this.node))
55
+ .indicatorStyle({
56
+ color: this.node.getAttribute('indicatorColor'),
57
+ selectedColor: this.node.getAttribute('indicatorActiveColor')
58
+ })
59
+ .onChange((index: number) => {
60
+ const event: TaroEvent = createTaroEvent('change', { detail: { current: index } }, this.node)
61
+ eventHandler(event, 'change', this.node)
62
+ })
63
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
64
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
65
+ this.node._nodeInfo.areaInfo = res[1]
66
+ }))
67
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
68
+ }
111
69
  }
112
- .swiperStyle(getNormalAttributes(node))
113
- .swiperAttr(getSwiperAttributes(node))
114
- .indicatorStyle({
115
- color: node.getAttribute('indicatorColor'),
116
- selectedColor: node.getAttribute('indicatorActiveColor')
117
- })
118
- .onChange((index: number) => {
119
- const event: TaroEvent = createTaroEvent('change', { detail: { current: index } }, node)
120
- eventHandler(event, 'change', node)
121
- })
122
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
123
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
124
- node._nodeInfo.areaInfo = res[1]
125
- }))
126
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
127
70
  }
@@ -1,78 +1,14 @@
1
1
  import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
2
2
 
3
- import { getNodeThresholds, shouldBindEvent, getNormalAttributes } from './utils/helper'
3
+ import commonStyleModify from './style'
4
+ import { getNodeThresholds, shouldBindEvent } from './utils/helper'
4
5
 
5
- import type { TaroAny, TaroStyleType, TaroSwitchElement, TaroEvent } from '@tarojs/runtime'
6
+ import type { TaroAny, TaroSwitchElement, TaroEvent } from '@tarojs/runtime'
6
7
 
7
8
  interface SwitchAttrs {
8
9
  selectedColor?: ResourceColor
9
10
  }
10
11
 
11
- @Extend(Toggle)
12
- function styles (style: TaroStyleType) {
13
- .id(style.id)
14
- .key(style.id)
15
- .flexGrow(style.flexGrow)
16
- .flexShrink(style.flexShrink)
17
- .flexBasis(style.flexBasis)
18
- .alignSelf(style.alignSelf)
19
- .padding({
20
- top: style.paddingTop,
21
- right: style.paddingRight,
22
- bottom: style.paddingBottom,
23
- left: style.paddingLeft
24
- })
25
- .margin({
26
- top: style.marginTop,
27
- right: style.marginRight,
28
- bottom: style.marginBottom,
29
- left: style.marginLeft
30
- })
31
- .width(style.width)
32
- .height(style.height)
33
- .constraintSize({
34
- minWidth: style.minWidth,
35
- maxWidth: style.maxWidth,
36
- minHeight: style.minHeight,
37
- maxHeight: style.maxHeight
38
- })
39
- .backgroundColor(style.backgroundColor)
40
- .backgroundImage(style.backgroundImage?.src, style.backgroundRepeat)
41
- .backgroundImageSize(style.backgroundSize)
42
- .backgroundImagePosition(style.backgroundPosition)
43
- .borderStyle({
44
- top: style.borderTopStyle,
45
- right: style.borderRightStyle,
46
- bottom: style.borderBottomStyle,
47
- left: style.borderLeftStyle
48
- })
49
- .borderWidth({
50
- top: style.borderTopWidth,
51
- right: style.borderRightWidth,
52
- bottom: style.borderBottomWidth,
53
- left: style.borderLeftWidth
54
- })
55
- .borderColor({
56
- top: style.borderTopColor,
57
- right: style.borderRightColor,
58
- bottom: style.borderBottomColor,
59
- left: style.borderLeftColor
60
- })
61
- .borderRadius({
62
- topLeft: style.borderTopLeftRadius,
63
- topRight: style.borderTopRightRadius,
64
- bottomLeft: style.borderBottomLeftRadius,
65
- bottomRight: style.borderBottomRightRadius
66
- })
67
- .zIndex(style.zIndex)
68
- .opacity(style.opacity)
69
- .linearGradient(style.linearGradient)
70
- .clip(style.overflow)
71
- .rotate({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y, angle: 0 })
72
- .scale({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y })
73
- .transform(style.transform)
74
- }
75
-
76
12
  @Extend(Toggle)
77
13
  function attrs(attr: SwitchAttrs) {
78
14
  .selectedColor(attr.selectedColor)
@@ -92,7 +28,9 @@ function themeStyles(isDisabled: boolean) {
92
28
 
93
29
  @Component
94
30
  export default struct TaroSwitch {
95
- node: TaroSwitchElement | null = null
31
+ @Builder customBuilder() {}
32
+ @BuilderParam createLazyChildren: (node: TaroSwitchElement) => void = this.customBuilder
33
+ @ObjectLink node: TaroSwitchElement
96
34
 
97
35
  aboutToAppear () {
98
36
  if (this.node && !this.node._isInit) {
@@ -102,19 +40,19 @@ export default struct TaroSwitch {
102
40
  }
103
41
 
104
42
  build () {
105
- if (this.node) {
43
+ if (this.node && this.node.hmStyle?.display !== 'none') {
106
44
  Toggle({
107
45
  type: this.node._attrs.type !== 'checkbox' ? ToggleType.Switch : ToggleType.Checkbox,
108
46
  isOn: this.node.checked,
109
47
  })
110
- .styles(getNormalAttributes(this.node))
48
+ .attributeModifier(commonStyleModify.setNode(this.node))
111
49
  .attrs(getAttributes(this.node))
112
50
  .themeStyles(!!this.node._attrs.disabled)
113
51
  .onChange((isOn: boolean) => {
114
52
  if (this.node) {
115
53
  if (!this.node?._attrs.disabled) {
116
54
  const event: TaroEvent = createTaroEvent('change', { detail: { value: isOn } }, this.node)
117
-
55
+
118
56
  this.node.updateCheckedValue(isOn)
119
57
  eventHandler(event, 'change', this.node)
120
58
  } else {
@@ -1,76 +1,12 @@
1
1
  import { eventHandler, convertNumber2VP, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, NodeType } from '@tarojs/runtime'
2
2
 
3
+ import commonStyleModify from './style'
3
4
  import { getButtonColor } from './button'
4
5
  import { BUTTON_THEME_COLOR } from './utils/constant/style'
5
- import { getNodeThresholds, getNormalAttributes, getFontAttributes, shouldBindEvent } from './utils/helper'
6
+ import { getNodeThresholds, getStyleAttr, getFontAttributes, shouldBindEvent } from './utils/helper'
6
7
 
7
8
  import type { TaroButtonElement, TaroElement, TaroTextElement, TaroAny, TaroTextStyleType, TaroStyleType } from '@tarojs/runtime'
8
9
 
9
- @Extend(Text)
10
- function textNormalStyle (style: TaroStyleType) {
11
- .id(style.id)
12
- .key(style.id)
13
- .flexGrow(style.flexGrow)
14
- .flexShrink(style.flexShrink)
15
- .flexBasis(style.flexBasis)
16
- .alignSelf(style.alignSelf)
17
- .padding({
18
- top: style.paddingTop,
19
- right: style.paddingRight,
20
- bottom: style.paddingBottom,
21
- left: style.paddingLeft
22
- })
23
- .margin({
24
- top: style.marginTop,
25
- right: style.marginRight,
26
- bottom: style.marginBottom,
27
- left: style.marginLeft
28
- })
29
- .width(style.width)
30
- .height(style.height)
31
- .constraintSize({
32
- minWidth: style.minWidth,
33
- maxWidth: style.maxWidth,
34
- minHeight: style.minHeight,
35
- maxHeight: style.maxHeight
36
- })
37
- .backgroundColor(style.backgroundColor)
38
- .backgroundImage(style.backgroundImage?.src, style.backgroundRepeat)
39
- .backgroundImageSize(style.backgroundSize)
40
- .backgroundImagePosition(style.backgroundPosition)
41
- .borderStyle({
42
- top: style.borderTopStyle,
43
- right: style.borderRightStyle,
44
- bottom: style.borderBottomStyle,
45
- left: style.borderLeftStyle
46
- })
47
- .borderWidth({
48
- top: style.borderTopWidth,
49
- right: style.borderRightWidth,
50
- bottom: style.borderBottomWidth,
51
- left: style.borderLeftWidth
52
- })
53
- .borderColor({
54
- top: style.borderTopColor,
55
- right: style.borderRightColor,
56
- bottom: style.borderBottomColor,
57
- left: style.borderLeftColor
58
- })
59
- .borderRadius({
60
- topLeft: style.borderTopLeftRadius,
61
- topRight: style.borderTopRightRadius,
62
- bottomLeft: style.borderBottomLeftRadius,
63
- bottomRight: style.borderBottomRightRadius
64
- })
65
- .zIndex(style.zIndex)
66
- .opacity(style.opacity)
67
- .linearGradient(style.linearGradient)
68
- .clip(style.overflow)
69
- .rotate({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y, angle: 0 })
70
- .scale({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y })
71
- .transform(style.transform)
72
- }
73
-
74
10
  @Extend(Text)
75
11
  function textNormalFontStyle (style: TaroStyleType) {
76
12
  .id(style.id)
@@ -81,7 +17,6 @@ function textNormalFontStyle (style: TaroStyleType) {
81
17
  .fontWeight(style.fontWeight)
82
18
  .fontStyle(style.fontStyle)
83
19
  .fontFamily(style.fontFamily)
84
- .lineHeight(style.lineHeight)
85
20
  .decoration({
86
21
  type: style.textDecoration,
87
22
  color: style.color
@@ -91,9 +26,11 @@ function textNormalFontStyle (style: TaroStyleType) {
91
26
  @Extend(Text)
92
27
  function textSpecialFontStyle(attr: TaroTextStyleType) {
93
28
  .textAlign(attr.textAlign)
29
+ .align(attr.verticalAlign)
94
30
  .textOverflow(attr.textOverflow)
95
31
  .maxLines(attr.WebkitLineClamp)
96
32
  .letterSpacing(attr.letterSpacing)
33
+ .lineHeight(attr.lineHeight)
97
34
  }
98
35
 
99
36
  function getButtonFontSize (node: TaroButtonElement) {
@@ -102,29 +39,41 @@ function getButtonFontSize (node: TaroButtonElement) {
102
39
  return isMini ? convertNumber2VP(26) : convertNumber2VP(36)
103
40
  }
104
41
 
105
- @Builder
106
- export default function TaroText (node: TaroTextElement) {
107
- if (node.nodeType === NodeType.TEXT_NODE && node.parentNode) {
108
- if ((node.parentNode as TaroElement).tagName === 'BUTTON') {
109
- Text(node.textContent)
110
- .textNormalFontStyle(getNormalAttributes(node.parentNode as TaroElement))
111
- .textSpecialFontStyle(getFontAttributes(node.parentNode as TaroElement))
112
- .fontSize((node.parentNode as TaroButtonElement).hmStyle.fontSize || getButtonFontSize((node.parentNode as TaroButtonElement)))
113
- .fontColor((node.parentNode as TaroButtonElement).hmStyle.color || getButtonColor(node.parentNode as TaroButtonElement, BUTTON_THEME_COLOR.get((node.parentNode as TaroButtonElement)._attrs.type).text))
42
+ @Component
43
+ export default struct TaroText {
44
+ @Builder customBuilder() {}
45
+ @BuilderParam createLazyChildren: (node: TaroTextElement) => void = this.customBuilder
46
+ @ObjectLink node: TaroTextElement
47
+
48
+ build () {
49
+ if (this.node.nodeType === NodeType.TEXT_NODE) {
50
+ if (this.node.parentNode) {
51
+ if ((this.node.parentNode as TaroElement).tagName === 'BUTTON') {
52
+ Text(this.node.textContent)
53
+ .textNormalFontStyle(this.node.parentElement?.hmStyle || {})
54
+ .textSpecialFontStyle(getFontAttributes(this.node.parentElement as TaroElement))
55
+ .fontSize((this.node.parentNode as TaroButtonElement).hmStyle.fontSize || getButtonFontSize(this.node.parentNode as TaroButtonElement))
56
+ .fontColor((this.node.parentNode as TaroButtonElement).hmStyle.color || getButtonColor(this.node.parentNode as TaroButtonElement, BUTTON_THEME_COLOR.get((this.node.parentNode as TaroButtonElement)._attrs.type).text))
57
+ } else {
58
+ Text(this.node.textContent)
59
+ .textNormalFontStyle(this.node.parentElement?.hmStyle || {})
60
+ .textSpecialFontStyle(getFontAttributes(this.node.parentElement as TaroElement))
61
+ .width(getStyleAttr(this.node.parentElement, 'width'))
62
+ .height(getStyleAttr(this.node.parentElement, 'height'))
63
+ }
64
+ }
114
65
  } else {
115
- Text(node.textContent)
116
- .textNormalFontStyle(getNormalAttributes(node.parentNode as TaroElement))
117
- .textSpecialFontStyle(getFontAttributes(node.parentNode as TaroElement))
66
+ if (this.node.hmStyle?.display !== 'none') {
67
+ Text(this.node.textContent)
68
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
69
+ .attributeModifier(commonStyleModify.setNode(this.node))
70
+ .textNormalFontStyle(this.node?.hmStyle)
71
+ .textSpecialFontStyle(getFontAttributes(this.node))
72
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
73
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
74
+ this.node._nodeInfo.areaInfo = res[1]
75
+ }))
76
+ }
118
77
  }
119
- } else {
120
- Text(node.textContent)
121
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
122
- .textNormalStyle(getNormalAttributes(node))
123
- .textNormalFontStyle(getNormalAttributes(node))
124
- .textSpecialFontStyle(getFontAttributes(node))
125
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
126
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
127
- node._nodeInfo.areaInfo = res[1]
128
- }))
129
78
  }
130
79
  }