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

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 (77) hide show
  1. package/dist/apis/device/memory.ts +10 -3
  2. package/dist/apis/index.ts +2 -0
  3. package/dist/apis/media/video/VideoContext.ts +56 -7
  4. package/dist/apis/media/video/index.ts +3 -2
  5. package/dist/apis/network/request.ts +5 -5
  6. package/dist/apis/route/index.ts +15 -0
  7. package/dist/apis/wxml/index.ts +2 -0
  8. package/dist/components-harmony-ets/button.ets +26 -40
  9. package/dist/components-harmony-ets/checkbox.ets +70 -99
  10. package/dist/components-harmony-ets/form.ets +29 -42
  11. package/dist/components-harmony-ets/icon.ets +6 -34
  12. package/dist/components-harmony-ets/image.ets +2 -32
  13. package/dist/components-harmony-ets/innerHtml.ets +2 -2
  14. package/dist/components-harmony-ets/input.ets +7 -27
  15. package/dist/components-harmony-ets/label.ets +40 -47
  16. package/dist/components-harmony-ets/picker.ets +66 -73
  17. package/dist/components-harmony-ets/radio.ets +72 -101
  18. package/dist/components-harmony-ets/richText.ets +4 -36
  19. package/dist/components-harmony-ets/scrollView.ets +34 -74
  20. package/dist/components-harmony-ets/slider.ets +9 -34
  21. package/dist/components-harmony-ets/style.ets +154 -0
  22. package/dist/components-harmony-ets/swiper.ets +4 -34
  23. package/dist/components-harmony-ets/switch.ets +43 -56
  24. package/dist/components-harmony-ets/text.ets +7 -34
  25. package/dist/components-harmony-ets/textArea.ets +8 -28
  26. package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -11
  27. package/dist/components-harmony-ets/utils/flexManager.ets +45 -7
  28. package/dist/components-harmony-ets/utils/helper.ets +2 -2
  29. package/dist/components-harmony-ets/utils/styles.ets +58 -20
  30. package/dist/components-harmony-ets/video.ets +4 -34
  31. package/dist/components-harmony-ets/view.ets +25 -67
  32. package/dist/components-harmony-ets/webView.ets +50 -0
  33. package/dist/index.js +103 -5
  34. package/dist/index.js.map +1 -1
  35. package/dist/runtime-ets/bom/window.ts +2 -2
  36. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +30 -6
  37. package/dist/runtime-ets/dom/document.ts +21 -4
  38. package/dist/runtime-ets/dom/element/element.ts +1 -0
  39. package/dist/runtime-ets/dom/element/form.ts +11 -2
  40. package/dist/runtime-ets/dom/element/index.ts +4 -1
  41. package/dist/runtime-ets/dom/element/normal.ts +1 -0
  42. package/dist/runtime-ets/dom/element/webView.ts +61 -0
  43. package/dist/runtime-ets/dom/node.ts +29 -16
  44. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +624 -0
  45. package/dist/runtime-ets/dom/stylesheet/index.ts +216 -354
  46. package/dist/runtime-ets/dom/stylesheet/type.ts +46 -11
  47. package/dist/runtime-ets/dom/stylesheet/util.ts +58 -6
  48. package/dist/runtime-ets/index.ts +1 -2
  49. package/dist/runtime-ets/interface/event.ts +2 -1
  50. package/dist/runtime-ets/utils/index.ts +6 -1
  51. package/dist/runtime-ets/utils/info.ts +3 -1
  52. package/dist/runtime-framework/react/app.ts +12 -22
  53. package/dist/runtime-framework/react/hooks.ts +3 -3
  54. package/dist/runtime-framework/react/index.ts +1 -0
  55. package/dist/runtime-framework/react/native-page.ts +344 -0
  56. package/dist/runtime-framework/react/page.ts +2 -2
  57. package/dist/runtime-framework/solid/hooks.ts +3 -3
  58. package/dist/runtime-utils.js +76 -20
  59. package/dist/runtime-utils.js.map +1 -1
  60. package/dist/runtime.js +76 -20
  61. package/dist/runtime.js.map +1 -1
  62. package/package.json +12 -11
  63. package/static/media/cancel.svg +1 -0
  64. package/static/media/circle.svg +1 -0
  65. package/static/media/clear.svg +1 -0
  66. package/static/media/download.svg +1 -0
  67. package/static/media/info.svg +1 -0
  68. package/static/media/info_circle.svg +1 -0
  69. package/static/media/search.svg +1 -0
  70. package/static/media/success.svg +1 -0
  71. package/static/media/success_no_circle.svg +1 -0
  72. package/static/media/taro_arrow_left.svg +1 -0
  73. package/static/media/taro_home.svg +1 -0
  74. package/static/media/waiting.svg +1 -0
  75. package/static/media/warn.svg +1 -0
  76. package/types/runtime.d.ts +2 -0
  77. package/dist/runtime-ets/utils/bind.ts +0 -24
@@ -1,6 +1,8 @@
1
1
  import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
2
2
 
3
+ import commonStyleModify from './style'
3
4
  import { createLazyChildren } from './render'
5
+ import { FlexManager } from './utils/FlexManager'
4
6
  import { TOUCH_EVENT_MAP } from './utils/constant/event'
5
7
  import { getNodeThresholds, getNormalAttributes, shouldBindEvent } from './utils/helper'
6
8
 
@@ -22,77 +24,6 @@ interface ScrollViewEvent {
22
24
  scrollHeight: number
23
25
  }
24
26
 
25
- @Extend(Row)
26
- function rowAttrs (style: TaroStyleType) {
27
- .id(style.id)
28
- .key(style.id)
29
- .padding(style.padding)
30
- .margin(style.margin)
31
- .height(style.height)
32
- .constraintSize({
33
- minWidth: style?.constraintSize?.minWidth || style.width,
34
- minHeight: style?.constraintSize?.minHeight,
35
- maxWidth: style?.constraintSize?.maxWidth,
36
- maxHeight: style?.constraintSize?.maxHeight,
37
- })
38
- .flexGrow(style.flexGrow)
39
- .flexShrink(style.flexShrink)
40
- .flexBasis(style.flexBasis)
41
- .alignSelf(style.alignSelf)
42
- .backgroundColor(style.backgroundColor)
43
- .backgroundImage(style.backgroundImage, style.backgroundRepeat)
44
- .backgroundImageSize(style.backgroundImageSize)
45
- .backgroundImagePosition(style.backgroundImagePosition)
46
- .rotate(style.rotate)
47
- .scale(style.scale)
48
- .translate(style.translate)
49
- .transform(style.transform)
50
- .borderStyle(style.borderStyle)
51
- .borderWidth(style.borderWidth)
52
- .borderColor(style.borderColor)
53
- .borderRadius(style.borderRadius)
54
- .linearGradient(style.linearGradient)
55
- .zIndex(style.zIndex)
56
- .opacity(style.opacity)
57
- .clip(style.clip)
58
- }
59
-
60
- @Extend(Column)
61
- function columnAttrs (style: TaroStyleType) {
62
- .id(style.id)
63
- .key(style.id)
64
- .padding(style.padding)
65
- .margin(style.margin)
66
- .width(style.width)
67
- .constraintSize({
68
- minWidth: style?.constraintSize?.minWidth,
69
- minHeight: style?.constraintSize?.minHeight || style.height,
70
- maxWidth: style?.constraintSize?.maxWidth,
71
- maxHeight: style?.constraintSize?.maxHeight,
72
- })
73
- .flexGrow(style.flexGrow)
74
- .flexShrink(style.flexShrink)
75
- .flexBasis(style.flexBasis)
76
- .alignSelf(style.alignSelf)
77
- .backgroundColor(style.backgroundColor)
78
- .backgroundImage(style.backgroundImage, style.backgroundRepeat)
79
- .backgroundImageSize(style.backgroundImageSize)
80
- .backgroundImagePosition(style.backgroundImagePosition)
81
- .rotate(style.rotate)
82
- .scale(style.scale)
83
- .translate(style.translate)
84
- .transform(style.transform)
85
- .borderStyle(style.borderStyle)
86
- .borderWidth(style.borderWidth)
87
- .borderColor(style.borderColor)
88
- .borderRadius(style.borderRadius)
89
- .linearGradient(style.linearGradient)
90
- .zIndex(style.zIndex)
91
- .opacity(style.opacity)
92
- .clip(style.clip)
93
- }
94
-
95
-
96
27
  function getAttributes (node: TaroScrollViewElement): ScrollViewAttrs {
97
28
  const _attrs = node._attrs
98
29
  const scrollAttrs: ScrollViewAttrs = {
@@ -110,7 +41,7 @@ function getScrollable (node: TaroScrollViewElement) {
110
41
  }
111
42
 
112
43
  function handleScrollEvent (node: TaroScrollViewElement, eventName = 'scroll', xOffset?: number, yOffset?: number) {
113
- const currentOffset: ScrollViewCurrentOffset = node.scroller.currentOffset()
44
+ const currentOffset = node.scroller.currentOffset() as ScrollViewCurrentOffset
114
45
  const currentXOffset = currentOffset.xOffset
115
46
  const currentYOffset = currentOffset.yOffset
116
47
  const value: ScrollViewEvent = {
@@ -126,6 +57,26 @@ function handleScrollEvent (node: TaroScrollViewElement, eventName = 'scroll', x
126
57
  eventHandler(event, eventName, node)
127
58
  }
128
59
 
60
+ @Extend(Row)
61
+ function rowAttrs (style: TaroStyleType) {
62
+ .constraintSize({
63
+ minWidth: style.minWidth || style.width,
64
+ maxWidth: style.maxWidth,
65
+ minHeight: style.minHeight,
66
+ maxHeight: style.maxHeight
67
+ })
68
+ }
69
+
70
+ @Extend(Column)
71
+ function columnAttrs (style: TaroStyleType) {
72
+ .constraintSize({
73
+ minWidth: style.minWidth,
74
+ maxWidth: style.maxWidth,
75
+ minHeight: style.minHeight || style.height,
76
+ maxHeight: style.maxHeight
77
+ })
78
+ }
79
+
129
80
  @Builder
130
81
  export default function TaroScrollView (node: TaroScrollViewElement) {
131
82
  Scroll(node.scroller) {
@@ -133,26 +84,35 @@ export default function TaroScrollView (node: TaroScrollViewElement) {
133
84
  Row() {
134
85
  createLazyChildren(node)
135
86
  }
136
- .width(null)
87
+ .attributeModifier(commonStyleModify.setNode(node))
137
88
  .rowAttrs(getNormalAttributes(node))
89
+ .width(null)
138
90
  .onAreaChange(shouldBindEvent((_: Area, areaResult: Area) => {
139
91
  node._scroll = areaResult
140
92
  }, node, ['scroll', 'scrollstart', 'scrollend']))
93
+ .alignItems(FlexManager.flexOptions(node).alignItems as VerticalAlign)
94
+ .justifyContent(FlexManager.flexOptions(node).justifyContent)
95
+ .flexGrow(0).flexShrink(0)
141
96
  } else {
142
97
  Column() {
143
98
  createLazyChildren(node)
144
99
  }
145
- .height(null)
100
+ .attributeModifier(commonStyleModify.setNode(node))
146
101
  .columnAttrs(getNormalAttributes(node))
102
+ .height(null)
147
103
  .alignItems(HorizontalAlign.Start)
148
104
  .onAreaChange(shouldBindEvent((_: Area, areaResult: Area) => {
149
105
  node._scroll = areaResult
150
106
  }, node, ['scroll', 'scrollstart', 'scrollend']))
107
+ .alignItems(FlexManager.flexOptions(node).alignItems as HorizontalAlign)
108
+ .justifyContent(FlexManager.flexOptions(node).justifyContent)
109
+ .flexGrow(0).flexShrink(0)
151
110
  }
152
111
  }
153
112
  .width(getNormalAttributes(node).width)
154
113
  .height(getNormalAttributes(node).height)
155
114
  .flexGrow(getNormalAttributes(node).flexGrow)
115
+ .flexShrink(getNormalAttributes(node).flexShrink)
156
116
  .scrollable(getScrollable(node))
157
117
  .scrollBar(getAttributes(node).scrollBar)
158
118
  .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
@@ -1,8 +1,9 @@
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, TaroSliderElement, TaroStyleType, TaroEvent } from '@tarojs/runtime'
6
+ import type { TaroAny, TaroSliderElement, TaroEvent } from '@tarojs/runtime'
6
7
 
7
8
  interface SliderAttrs {
8
9
  selectedColor?: ResourceColor
@@ -11,37 +12,6 @@ interface SliderAttrs {
11
12
  blockColor?: ResourceColor
12
13
  }
13
14
 
14
- @Extend(Slider)
15
- function style (style: TaroStyleType) {
16
- .id(style.id)
17
- .key(style.id)
18
- .padding(style.padding)
19
- .margin(style.margin)
20
- .width(style.width)
21
- .height(style.height)
22
- .constraintSize(style.constraintSize)
23
- .flexGrow(style.flexGrow)
24
- .flexShrink(style.flexShrink)
25
- .flexBasis(style.flexBasis)
26
- .alignSelf(style.alignSelf)
27
- .backgroundColor(style.backgroundColor)
28
- .backgroundImage(style.backgroundImage, style.backgroundRepeat)
29
- .backgroundImageSize(style.backgroundImageSize)
30
- .backgroundImagePosition(style.backgroundImagePosition)
31
- .rotate(style.rotate)
32
- .scale(style.scale)
33
- .translate(style.translate)
34
- .transform(style.transform)
35
- .borderStyle(style.borderStyle)
36
- .borderWidth(style.borderWidth)
37
- .borderColor(style.borderColor)
38
- .borderRadius(style.borderRadius)
39
- .linearGradient(style.linearGradient)
40
- .zIndex(style.zIndex)
41
- .opacity(style.opacity)
42
- .clip(style.clip)
43
- }
44
-
45
15
  @Extend(Slider)
46
16
  function attrs (attr: SliderAttrs) {
47
17
  .selectedColor(attr.selectedColor)
@@ -75,6 +45,11 @@ export default struct TaroSlider {
75
45
  if (this.node) {
76
46
  this.value = this.node.value
77
47
  this.node._instance = this
48
+
49
+ if (!this.node._isInit) {
50
+ this.node._isInit = true
51
+ this.node._reset = this.node.value || 0
52
+ }
78
53
  }
79
54
  }
80
55
 
@@ -87,7 +62,7 @@ export default struct TaroSlider {
87
62
  style: SliderStyle.OutSet,
88
63
  direction: Axis.Horizontal
89
64
  })
90
- .style(getNormalAttributes(node))
65
+ .attributeModifier(commonStyleModify.setNode(node))
91
66
  .attrs(getAttributes(node))
92
67
  .width(!!node._attrs.showValue ? '90%' : '100%')
93
68
  .themeStyles(!!node._attrs.disabled)
@@ -0,0 +1,154 @@
1
+ import type { TaroElement, TaroStyleType } from '@tarojs/runtime'
2
+ import { isUndefined } from '../shared'
3
+ import { getNormalAttributes } from './utils/helper'
4
+
5
+ function getTop (node: TaroElement): Length | number {
6
+ return node?.hmStyle?.top || 0
7
+ }
8
+
9
+ function getLeft (node: TaroElement): Length | number {
10
+ return node?.hmStyle?.left || 0
11
+ }
12
+
13
+ class CommonStyleModify implements AttributeModifier<CommonAttribute> {
14
+ node: TaroElement | null = null
15
+ style: TaroStyleType | null = null
16
+
17
+ setNode (node: TaroElement) {
18
+ this.node = node
19
+ this.style = getNormalAttributes(this.node)
20
+
21
+ return this
22
+ }
23
+
24
+ applyNormalAttribute(instance: CommonAttribute): void {
25
+ if (this.node && this.style) {
26
+
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
+ })
141
+ }
142
+ if (this.node.hmStyle?.position === 'relative') {
143
+ instance.offset({
144
+ x: getLeft(this.node),
145
+ y: getTop(this.node)
146
+ })
147
+ }
148
+ }
149
+ }
150
+ }
151
+
152
+ const modify = new CommonStyleModify()
153
+
154
+ export default modify
@@ -1,9 +1,10 @@
1
1
  import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
2
2
 
3
+ import commonStyleModify from './style'
3
4
  import { createLazyChildren } from './render'
4
- import { getNodeThresholds, getNormalAttributes, shouldBindEvent } from './utils/helper'
5
+ import { getNodeThresholds, shouldBindEvent } from './utils/helper'
5
6
 
6
- import type { TaroStyleType, TaroSwiperElement, TaroEvent, TaroAny } from '@tarojs/runtime'
7
+ import type { TaroSwiperElement, TaroEvent, TaroAny } from '@tarojs/runtime'
7
8
 
8
9
  interface SwiperAttrs {
9
10
  index?: number
@@ -15,37 +16,6 @@ interface SwiperAttrs {
15
16
  indicator?: boolean
16
17
  }
17
18
 
18
- @Extend(Swiper)
19
- function swiperStyle (style: TaroStyleType) {
20
- .id(style.id)
21
- .key(style.id)
22
- .padding(style.padding)
23
- .margin(style.margin)
24
- .width(style.width)
25
- .height(style.height)
26
- .constraintSize(style.constraintSize)
27
- .flexGrow(style.flexGrow)
28
- .flexShrink(style.flexShrink)
29
- .flexBasis(style.flexBasis)
30
- .alignSelf(style.alignSelf)
31
- .backgroundColor(style.backgroundColor)
32
- .backgroundImage(style.backgroundImage, style.backgroundRepeat)
33
- .backgroundImageSize(style.backgroundImageSize)
34
- .backgroundImagePosition(style.backgroundImagePosition)
35
- .rotate(style.rotate)
36
- .scale(style.scale)
37
- .translate(style.translate)
38
- .transform(style.transform)
39
- .borderStyle(style.borderStyle)
40
- .borderWidth(style.borderWidth)
41
- .borderColor(style.borderColor)
42
- .borderRadius(style.borderRadius)
43
- .linearGradient(style.linearGradient)
44
- .zIndex(style.zIndex)
45
- .opacity(style.opacity)
46
- .clip(style.clip)
47
- }
48
-
49
19
  @Extend(Swiper)
50
20
  function swiperAttr (attr: SwiperAttrs) {
51
21
  .index(attr.index)
@@ -75,7 +45,7 @@ export default function TaroSwiper (node: TaroSwiperElement) {
75
45
  Swiper(node.controller) {
76
46
  createLazyChildren(node)
77
47
  }
78
- .swiperStyle(getNormalAttributes(node))
48
+ .attributeModifier(commonStyleModify.setNode(node))
79
49
  .swiperAttr(getSwiperAttributes(node))
80
50
  .indicatorStyle({
81
51
  color: node.getAttribute('indicatorColor'),
@@ -1,44 +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
- .padding(style.padding)
16
- .margin(style.margin)
17
- .width(style.width)
18
- .height(style.height)
19
- .constraintSize(style.constraintSize)
20
- .flexGrow(style.flexGrow)
21
- .flexShrink(style.flexShrink)
22
- .flexBasis(style.flexBasis)
23
- .alignSelf(style.alignSelf)
24
- .backgroundColor(style.backgroundColor)
25
- .backgroundImage(style.backgroundImage, style.backgroundRepeat)
26
- .backgroundImageSize(style.backgroundImageSize)
27
- .backgroundImagePosition(style.backgroundImagePosition)
28
- .rotate(style.rotate)
29
- .scale(style.scale)
30
- .translate(style.translate)
31
- .transform(style.transform)
32
- .borderStyle(style.borderStyle)
33
- .borderWidth(style.borderWidth)
34
- .borderColor(style.borderColor)
35
- .borderRadius(style.borderRadius)
36
- .linearGradient(style.linearGradient)
37
- .zIndex(style.zIndex)
38
- .opacity(style.opacity)
39
- .clip(style.clip)
40
- }
41
-
42
12
  @Extend(Toggle)
43
13
  function attrs(attr: SwitchAttrs) {
44
14
  .selectedColor(attr.selectedColor)
@@ -56,28 +26,45 @@ function themeStyles(isDisabled: boolean) {
56
26
  .opacity(isDisabled ? 0.4 : 1)
57
27
  }
58
28
 
59
- @Builder
60
- export default function TaroSwitch (node: TaroSwitchElement) {
61
- Toggle({
62
- type: node._attrs.type !== 'checkbox' ? ToggleType.Switch : ToggleType.Checkbox,
63
- isOn: node.checked,
64
- })
65
- .styles(getNormalAttributes(node))
66
- .attrs(getAttributes(node))
67
- .themeStyles(!!node._attrs.disabled)
68
- .onChange((isOn: boolean) => {
69
- if (!node?._attrs.disabled) {
70
- const event: TaroEvent = createTaroEvent('change', { detail: { value: isOn } }, node)
29
+ @Component
30
+ export default struct TaroSwitch {
31
+ node: TaroSwitchElement | null = null
32
+
33
+ aboutToAppear () {
34
+ if (this.node && !this.node._isInit) {
35
+ this.node._isInit = true
36
+ this.node._reset = this.node.checked || false
37
+ }
38
+ }
71
39
 
72
- node.updateCheckedValue(isOn)
73
- eventHandler(event, 'change', node)
74
- } else {
75
- node.updateComponent()
76
- }
77
- })
78
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
79
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
80
- node._nodeInfo.areaInfo = res[1]
81
- }))
82
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
40
+ build () {
41
+ if (this.node) {
42
+ Toggle({
43
+ type: this.node._attrs.type !== 'checkbox' ? ToggleType.Switch : ToggleType.Checkbox,
44
+ isOn: this.node.checked,
45
+ })
46
+ .attributeModifier(commonStyleModify.setNode(this.node))
47
+ .attrs(getAttributes(this.node))
48
+ .themeStyles(!!this.node._attrs.disabled)
49
+ .onChange((isOn: boolean) => {
50
+ if (this.node) {
51
+ if (!this.node?._attrs.disabled) {
52
+ const event: TaroEvent = createTaroEvent('change', { detail: { value: isOn } }, this.node)
53
+
54
+ this.node.updateCheckedValue(isOn)
55
+ eventHandler(event, 'change', this.node)
56
+ } else {
57
+ this.node.updateComponent()
58
+ }
59
+ }
60
+ })
61
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
62
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
63
+ if (this.node) {
64
+ this.node._nodeInfo.areaInfo = res[1]
65
+ }
66
+ }))
67
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
68
+ }
69
+ }
83
70
  }
@@ -1,39 +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
6
  import { getNodeThresholds, getNormalAttributes, 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
- .padding(style.padding)
12
- .margin(style.margin)
13
- .width(style.width)
14
- .height(style.height)
15
- .constraintSize(style.constraintSize)
16
- .flexGrow(style.flexGrow)
17
- .flexShrink(style.flexShrink)
18
- .flexBasis(style.flexBasis)
19
- .alignSelf(style.alignSelf)
20
- .backgroundColor(style.backgroundColor)
21
- .backgroundImage(style.backgroundImage, style.backgroundRepeat)
22
- .backgroundImageSize(style.backgroundImageSize)
23
- .backgroundImagePosition(style.backgroundImagePosition)
24
- .rotate(style.rotate)
25
- .scale(style.scale)
26
- .translate(style.translate)
27
- .transform(style.transform)
28
- .borderStyle(style.borderStyle)
29
- .borderWidth(style.borderWidth)
30
- .borderColor(style.borderColor)
31
- .borderRadius(style.borderRadius)
32
- .linearGradient(style.linearGradient)
33
- .zIndex(style.zIndex)
34
- .clip(style.clip)
35
- }
36
-
37
10
  @Extend(Text)
38
11
  function textNormalFontStyle (style: TaroStyleType) {
39
12
  .id(style.id)
@@ -46,7 +19,7 @@ function textNormalFontStyle (style: TaroStyleType) {
46
19
  .fontFamily(style.fontFamily)
47
20
  .lineHeight(style.lineHeight)
48
21
  .decoration({
49
- type: style.decoration,
22
+ type: style.textDecoration,
50
23
  color: style.color
51
24
  })
52
25
  }
@@ -55,7 +28,7 @@ function textNormalFontStyle (style: TaroStyleType) {
55
28
  function textSpecialFontStyle(attr: TaroTextStyleType) {
56
29
  .textAlign(attr.textAlign)
57
30
  .textOverflow(attr.textOverflow)
58
- .maxLines(attr.maxLines)
31
+ .maxLines(attr.WebkitLineClamp)
59
32
  .letterSpacing(attr.letterSpacing)
60
33
  }
61
34
 
@@ -82,12 +55,12 @@ export default function TaroText (node: TaroTextElement) {
82
55
  } else {
83
56
  Text(node.textContent)
84
57
  .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
85
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
86
- node._nodeInfo.areaInfo = res[1]
87
- }))
88
- .textNormalStyle(getNormalAttributes(node))
58
+ .attributeModifier(commonStyleModify.setNode(node))
89
59
  .textNormalFontStyle(getNormalAttributes(node))
90
60
  .textSpecialFontStyle(getFontAttributes(node))
91
61
  .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
62
+ .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
63
+ node._nodeInfo.areaInfo = res[1]
64
+ }))
92
65
  }
93
66
  }