@tarojs/plugin-platform-harmony-ets 4.0.0-beta.12 → 4.0.0-beta.121

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 (143) hide show
  1. package/dist/apis/base/system.ts +60 -25
  2. package/dist/apis/base/weapp/life-cycle.ts +1 -1
  3. package/dist/apis/canvas/index.ts +10 -1
  4. package/dist/apis/device/clipboard.ts +23 -8
  5. package/dist/apis/framework/index.ts +2 -6
  6. package/dist/apis/index.ts +25 -17
  7. package/dist/apis/media/image/index.ts +169 -17
  8. package/dist/apis/route/index.ts +1 -2
  9. package/dist/apis/storage/index.ts +135 -131
  10. package/dist/apis/ui/animation/animation.ts +71 -29
  11. package/dist/apis/ui/background.ts +3 -2
  12. package/dist/apis/ui/interaction/index.ts +58 -59
  13. package/dist/apis/ui/navigation-bar/index.ts +2 -2
  14. package/dist/apis/ui/pull-down-refresh.ts +9 -3
  15. package/dist/apis/ui/scroll/index.ts +6 -6
  16. package/dist/apis/ui/tab-bar.ts +4 -5
  17. package/dist/apis/utils/index.ts +20 -2
  18. package/dist/apis/utils/permissions.ts +6 -0
  19. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  20. package/dist/apis/wxml/selectorQuery.ts +26 -13
  21. package/dist/components-harmony-ets/button.ets +36 -9
  22. package/dist/components-harmony-ets/canvas.ets +51 -0
  23. package/dist/components-harmony-ets/checkbox.ets +69 -60
  24. package/dist/components-harmony-ets/form.ets +33 -15
  25. package/dist/components-harmony-ets/icon.ets +16 -8
  26. package/dist/components-harmony-ets/image.ets +22 -6
  27. package/dist/components-harmony-ets/index.ets +39 -0
  28. package/dist/components-harmony-ets/innerHtml.ets +6 -5
  29. package/dist/components-harmony-ets/input.ets +63 -37
  30. package/dist/components-harmony-ets/label.ets +43 -21
  31. package/dist/components-harmony-ets/listView.ets +32 -0
  32. package/dist/components-harmony-ets/movableArea.ets +110 -51
  33. package/dist/components-harmony-ets/movableView.ets +74 -47
  34. package/dist/components-harmony-ets/navigationBar.ets +65 -0
  35. package/dist/components-harmony-ets/pageMeta.ets +94 -0
  36. package/dist/components-harmony-ets/picker.ets +36 -33
  37. package/dist/components-harmony-ets/progress.ets +31 -24
  38. package/dist/components-harmony-ets/pseudo.ets +80 -0
  39. package/dist/components-harmony-ets/radio.ets +75 -66
  40. package/dist/components-harmony-ets/richText.ets +4 -25
  41. package/dist/components-harmony-ets/scrollList.ets +108 -0
  42. package/dist/components-harmony-ets/scrollView.ets +46 -42
  43. package/dist/components-harmony-ets/slider.ets +19 -15
  44. package/dist/components-harmony-ets/stickySection.ets +42 -0
  45. package/dist/components-harmony-ets/style.ets +386 -129
  46. package/dist/components-harmony-ets/swiper.ets +42 -5
  47. package/dist/components-harmony-ets/switch.ets +36 -32
  48. package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
  49. package/dist/components-harmony-ets/text.ets +102 -46
  50. package/dist/components-harmony-ets/textArea.ets +49 -34
  51. package/dist/components-harmony-ets/utils/AttributeManager.ets +2 -2
  52. package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -2
  53. package/dist/components-harmony-ets/utils/flexManager.ets +49 -19
  54. package/dist/components-harmony-ets/utils/helper.ets +20 -8
  55. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  56. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  57. package/dist/components-harmony-ets/utils/index.ts +54 -50
  58. package/dist/components-harmony-ets/utils/styles.ets +169 -91
  59. package/dist/components-harmony-ets/video.ets +28 -20
  60. package/dist/components-harmony-ets/view.ets +45 -39
  61. package/dist/components-harmony-ets/webView.ets +6 -5
  62. package/dist/index.d.ts +152 -0
  63. package/dist/index.js +73 -44
  64. package/dist/index.js.map +1 -1
  65. package/dist/runtime-ets/bom/URL.ts +2 -0
  66. package/dist/runtime-ets/bom/document.ts +5 -4
  67. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -3
  68. package/dist/runtime-ets/bom/history.ts +1 -0
  69. package/dist/runtime-ets/bom/location.ts +1 -0
  70. package/dist/runtime-ets/bom/navigator.ts +1 -21
  71. package/dist/runtime-ets/bom/raf.ts +1 -37
  72. package/dist/runtime-ets/bom/window.ts +10 -4
  73. package/dist/runtime-ets/constant.ts +17 -10
  74. package/dist/runtime-ets/current.ts +5 -2
  75. package/dist/runtime-ets/dom/bind.ts +28 -12
  76. package/dist/runtime-ets/dom/class-list.ts +2 -2
  77. package/dist/runtime-ets/dom/cssNesting.ts +419 -0
  78. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +28 -42
  79. package/dist/runtime-ets/dom/document.ts +9 -12
  80. package/dist/runtime-ets/dom/element/canvas.ts +137 -0
  81. package/dist/runtime-ets/dom/element/element.ts +379 -55
  82. package/dist/runtime-ets/dom/element/form.ts +26 -22
  83. package/dist/runtime-ets/dom/element/index.ts +22 -2
  84. package/dist/runtime-ets/dom/element/movableArea.ts +0 -1
  85. package/dist/runtime-ets/dom/element/movableView.ts +238 -2
  86. package/dist/runtime-ets/dom/element/normal.ts +27 -6
  87. package/dist/runtime-ets/dom/element/progress.ts +0 -2
  88. package/dist/runtime-ets/dom/element/text.ts +0 -8
  89. package/dist/runtime-ets/dom/element/video.ts +4 -4
  90. package/dist/runtime-ets/dom/element/webView.ts +4 -5
  91. package/dist/runtime-ets/dom/event-source.ts +1 -0
  92. package/dist/runtime-ets/dom/event.ts +3 -5
  93. package/dist/runtime-ets/dom/eventTarget.ts +3 -4
  94. package/dist/runtime-ets/dom/node.ts +53 -22
  95. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +418 -237
  96. package/dist/runtime-ets/dom/stylesheet/index.ts +29 -311
  97. package/dist/runtime-ets/dom/stylesheet/type.ts +53 -11
  98. package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
  99. package/dist/runtime-ets/emitter/emitter.ts +1 -0
  100. package/dist/runtime-ets/env.ts +1 -0
  101. package/dist/runtime-ets/index.ts +23 -7
  102. package/dist/runtime-ets/interface/event.ts +1 -1
  103. package/dist/runtime-ets/interface/index.ts +6 -0
  104. package/dist/runtime-ets/utils/index.ts +78 -19
  105. package/dist/runtime-ets/utils/info.ts +2 -2
  106. package/dist/runtime-ets/utils/router.ts +9 -0
  107. package/dist/runtime-framework/react/app.ts +15 -11
  108. package/dist/runtime-framework/react/hooks.ts +1 -2
  109. package/dist/runtime-framework/react/index.ts +0 -2
  110. package/dist/runtime-framework/react/native-page.ts +217 -81
  111. package/dist/runtime-framework/react/page.ts +4 -10
  112. package/dist/runtime-framework/react/utils/index.ts +3 -3
  113. package/dist/runtime-framework/solid/app.ts +29 -46
  114. package/dist/runtime-framework/solid/connect.ts +21 -3
  115. package/dist/runtime-framework/solid/hooks.ts +16 -11
  116. package/dist/runtime-framework/solid/index.ts +6 -2
  117. package/dist/runtime-framework/solid/page.ts +84 -31
  118. package/dist/runtime-framework/solid/reconciler/props.ts +73 -29
  119. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  120. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  121. package/dist/runtime-framework/solid/utils/index.ts +3 -5
  122. package/dist/runtime-utils.d.ts +827 -0
  123. package/dist/runtime-utils.js +574 -285
  124. package/dist/runtime-utils.js.map +1 -1
  125. package/dist/runtime.d.ts +1 -0
  126. package/dist/runtime.js +574 -285
  127. package/dist/runtime.js.map +1 -1
  128. package/index.js +3 -1
  129. package/package.json +14 -15
  130. package/static/media/cancel.svg +1 -1
  131. package/static/media/circle.svg +1 -1
  132. package/static/media/clear.svg +1 -1
  133. package/static/media/download.svg +1 -1
  134. package/static/media/info.svg +1 -1
  135. package/static/media/info_circle.svg +1 -1
  136. package/static/media/search.svg +1 -1
  137. package/static/media/success.svg +1 -1
  138. package/static/media/success_no_circle.svg +1 -1
  139. package/static/media/warn.svg +1 -1
  140. package/types/harmony.d.ts +5 -0
  141. package/types/index.d.ts +4 -0
  142. package/types/runtime.d.ts +1 -1
  143. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
@@ -1,154 +1,411 @@
1
- import type { TaroElement, TaroStyleType } from '@tarojs/runtime'
2
- import { isUndefined } from '../shared'
1
+ import { ObjectAssign } from '@tarojs/runtime'
2
+ import { isUndefined } from '@tarojs/shared'
3
+ import { computeBackgroundPosition, convertVp2Px } from './utils'
3
4
  import { getNormalAttributes } from './utils/helper'
5
+ import { isMaxWidthView } from './utils/styles'
6
+ import { FlexManager } from './utils/flexManager'
4
7
 
5
- function getTop (node: TaroElement): Length | number {
6
- return node?.hmStyle?.top || 0
7
- }
8
+ import type { HarmonyStyle, TaroAny, TaroElement, TaroStyleType, TaroTextElement } from '@tarojs/runtime'
9
+
10
+ class TextStyleModify implements AttributeModifier<TextAttribute> {
11
+ initStyle?: TaroStyleType
12
+ node: TaroTextElement | null = null
13
+ style: HarmonyStyle | null = null
14
+ overwriteStyle: Record<string, TaroAny> = {}
15
+ withNormal: boolean = false
16
+
17
+ setNode (node: TaroTextElement, initStyle?: HarmonyStyle) {
18
+ this.node = node
19
+ this.withNormal = false
20
+ this.overwriteStyle = {}
21
+ this.style = getNormalAttributes(this.node)
22
+ this.initStyle = initStyle
23
+ // 覆盖初始化样式
24
+ if (initStyle) {
25
+ Object.keys(initStyle).forEach(key => {
26
+ if (this.style && !this.style[key]) {
27
+ this.style[key] = initStyle[key]
28
+ }
29
+ })
30
+ }
31
+ return this
32
+ }
33
+
34
+ withNormalStyle () {
35
+ this.withNormal = true
36
+ return this
37
+ }
38
+
39
+ setAnimationStyle (overwriteStyle: Record<string, TaroAny>) {
40
+ this.overwriteStyle = overwriteStyle
41
+ if (this.style && this.overwriteStyle && Object.keys(this.overwriteStyle).length) {
42
+ // 防止污染原始样式
43
+ this.style = ObjectAssign({}, this.style)
44
+ Object.keys(this.overwriteStyle).forEach(key => {
45
+ this.style![key] = this.overwriteStyle[key]
46
+ })
47
+ }
48
+ return this
49
+ }
8
50
 
9
- function getLeft (node: TaroElement): Length | number {
10
- return node?.hmStyle?.left || 0
51
+ applyNormalAttribute(instance: TextAttribute): void {
52
+ if (this.node && this.style) {
53
+ if (this.withNormal) {
54
+ setNormalAttributeIntoInstance(instance, this.style, this.node)
55
+ setTransformAttributeIntoInstance(instance, this.style || {})
56
+ }
57
+ setNormalTextAttributeIntoInstance(instance, this.style, this.node)
58
+ setSpecialTextAttributeIntoInstance(instance, this.style, this.node)
59
+ }
60
+
61
+ }
11
62
  }
12
63
 
13
64
  class CommonStyleModify implements AttributeModifier<CommonAttribute> {
65
+ initStyle?: TaroStyleType
14
66
  node: TaroElement | null = null
15
67
  style: TaroStyleType | null = null
68
+ overwriteStyle: TaroStyleType = {}
16
69
 
17
- setNode (node: TaroElement) {
70
+ setNode (node: TaroElement, initStyle?: TaroStyleType) {
18
71
  this.node = node
19
72
  this.style = getNormalAttributes(this.node)
73
+ this.initStyle = initStyle
74
+ this.overwriteStyle = {}
75
+ // 覆盖初始化样式
76
+ if (initStyle) {
77
+ Object.keys(initStyle).forEach(key => {
78
+ if (this.style && !this.style[key]) {
79
+ this.style[key] = initStyle[key]
80
+ }
81
+ })
82
+ }
83
+ return this
84
+ }
20
85
 
86
+ setAnimationStyle (overwriteStyle: Record<string, TaroAny>) {
87
+ this.overwriteStyle = overwriteStyle
88
+ if (this.style && this.overwriteStyle && Object.keys(this.overwriteStyle).length) {
89
+ // 防止污染原始样式
90
+ this.style = ObjectAssign({}, this.style)
91
+ Object.keys(this.overwriteStyle).forEach(key => {
92
+ this.style![key] = this.overwriteStyle[key]
93
+ })
94
+ }
21
95
  return this
22
96
  }
23
97
 
24
98
  applyNormalAttribute(instance: CommonAttribute): void {
25
99
  if (this.node && this.style) {
100
+ setNormalAttributeIntoInstance(instance, this.style, this.node)
101
+ setTransformAttributeIntoInstance(instance, this.style || {})
102
+ }
103
+ }
104
+ }
26
105
 
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
- })
106
+ class PseudoStyleModify implements AttributeModifier<CommonAttribute> {
107
+ style: TaroStyleType | null = null
108
+
109
+ setStyle (style: HarmonyStyle) {
110
+ this.style = style
111
+ return this
112
+ }
113
+
114
+ applyNormalAttribute(instance: CommonAttribute): void {
115
+ if (this.style) {
116
+ setNormalAttributeIntoInstance(instance, this.style)
117
+ setTransformAttributeIntoInstance(instance, this.style || {})
118
+ }
119
+ }
120
+ }
121
+
122
+ class RowStyleModify extends CommonStyleModify {
123
+
124
+ applyNormalAttribute(instance: RowAttribute): void {
125
+ if (this.style) {
126
+ setNormalAttributeIntoInstance(instance, this.style, this.node)
127
+ instance.constraintSize({
128
+ minWidth: this.style.minWidth || this.style.width,
129
+ maxWidth: this.style.maxWidth,
130
+ minHeight: this.style.minHeight,
131
+ maxHeight: this.style.maxHeight
132
+ })
133
+ if (this.node) {
134
+ instance.alignItems(FlexManager.alignItems<VerticalAlign>(this.node))
135
+ instance.justifyContent(FlexManager.justifyContent(this.node))
141
136
  }
142
- if (this.node.hmStyle?.position === 'relative') {
143
- instance.offset({
144
- x: getLeft(this.node),
145
- y: getTop(this.node)
146
- })
137
+ setTransformAttributeIntoInstance(instance, this.style || {})
138
+ }
139
+
140
+ }
141
+ }
142
+
143
+ class ColumnStyleModify extends CommonStyleModify {
144
+ applyNormalAttribute(instance: ColumnAttribute): void {
145
+ if (this.style) {
146
+ setNormalAttributeIntoInstance(instance, this.style, this.node)
147
+ instance.constraintSize({
148
+ minWidth: this.style.minWidth,
149
+ maxWidth: this.style.maxWidth,
150
+ minHeight: this.style.minHeight || this.style.height,
151
+ maxHeight: this.style.maxHeight
152
+ })
153
+ if (this.node) {
154
+ instance.alignItems(FlexManager.alignItems<HorizontalAlign>(this.node))
155
+ instance.justifyContent(FlexManager.justifyContent(this.node))
147
156
  }
157
+ setTransformAttributeIntoInstance(instance, this.style || {})
158
+ }
159
+
160
+ }
161
+ }
162
+
163
+ export function setTransformAttributeIntoInstance(instance: CommonAttribute, style: TaroStyleType) {
164
+ // Animation 需要提前和 @State 变量绑定才能产生动画效果,因此不能做 if else 判断
165
+ instance.translate({
166
+ x: style.transform?.Translate?.x,
167
+ y: style.transform?.Translate?.y,
168
+ z: style.transform?.Translate?.z,
169
+ })
170
+ instance.scale({
171
+ x: style.transform?.Scale?.x,
172
+ y: style.transform?.Scale?.y,
173
+ z: style.transform?.Scale?.z,
174
+ centerX: style.transformOrigin?.x,
175
+ centerY: style.transformOrigin?.y,
176
+ })
177
+ instance.rotate({
178
+ x: style.transform?.Rotate?.x,
179
+ y: style.transform?.Rotate?.y,
180
+ z: style.transform?.Rotate?.z,
181
+ centerX: style.transformOrigin?.x,
182
+ centerY: style.transformOrigin?.y,
183
+ angle: style.transform?.Rotate?.angle || 0,
184
+ })
185
+ }
186
+
187
+ export function setNormalTextAttributeIntoInstance(instance: TextAttribute | SpanAttribute, style: HarmonyStyle, node?: TaroTextElement | null) {
188
+ if (!isUndefined(style.color)) {
189
+ instance.fontColor(style.color)
190
+ }
191
+ if (!isUndefined(style.fontSize)) {
192
+ instance.fontSize(style.fontSize)
193
+ }
194
+ if (!isUndefined(style.fontWeight)) {
195
+ instance.fontWeight(style.fontWeight)
196
+ }
197
+ if (!isUndefined(style.fontStyle)) {
198
+ instance.fontStyle(style.fontStyle)
199
+ }
200
+ if (!isUndefined(style.fontFamily)) {
201
+ instance.fontFamily(style.fontFamily)
202
+ }
203
+ if (!isUndefined(style.textDecoration)) {
204
+ instance.decoration({
205
+ type: style.textDecoration.type,
206
+ color: style.color
207
+ })
208
+ }
209
+ }
210
+
211
+ export function setSpecialTextAttributeIntoInstance(instance: TextAttribute, style: HarmonyStyle, node?: TaroTextElement | null) {
212
+ if (!isUndefined(style.textAlign)) {
213
+ instance.textAlign(style.textAlign)
214
+ }
215
+ if (!isUndefined(style.verticalAlign)) {
216
+ instance.align(style.verticalAlign)
217
+ }
218
+ if (!isUndefined(style.textOverflow)) {
219
+ instance.textOverflow(style.textOverflow)
220
+ }
221
+ if (!isUndefined(style.whiteSpace) && style.whiteSpace === 'nowrap') {
222
+ instance.maxLines(1)
223
+ }
224
+ if (!isUndefined(style.WebkitLineClamp)) {
225
+ instance.maxLines(style.WebkitLineClamp)
226
+ instance.textOverflow({overflow: TextOverflow.Ellipsis})
227
+ }
228
+ if (!isUndefined(style.letterSpacing)) {
229
+ instance.letterSpacing(style.letterSpacing)
230
+ }
231
+ if (!isUndefined(style.lineHeight)) {
232
+ instance.lineHeight(style.lineHeight)
233
+ }
234
+ if (!isUndefined(style.wordBreak)) {
235
+ if (style.wordBreak == 'break-all') {
236
+ instance.wordBreak(WordBreak.BREAK_ALL)
237
+ } else if (style.wordBreak == 'break-word') {
238
+ instance.wordBreak(WordBreak.BREAK_WORD)
239
+ } else if (style.wordBreak == 'normal') {
240
+ instance.wordBreak(WordBreak.NORMAL)
148
241
  }
149
242
  }
150
243
  }
151
244
 
152
- const modify = new CommonStyleModify()
245
+ export function setNormalAttributeIntoInstance(instance: CommonAttribute, style: TaroStyleType, node?: TaroElement | null) {
246
+ instance.renderFit(RenderFit.RESIZE_FILL)
247
+ if (!isUndefined(style.id)) {
248
+ instance.id(style.id)
249
+ instance.key(style.id)
250
+ }
251
+ if (!isUndefined(style.display) || !isUndefined(style.visibility)) {
252
+ instance.visibility(style.display === 'none'
253
+ ? Visibility.None :
254
+ !isUndefined(style.visibility)
255
+ ? (style.visibility === 'hidden' ? Visibility.Hidden : Visibility.Visible)
256
+ : Visibility.Visible
257
+ )
258
+ }
259
+ if (!isUndefined(style.flexGrow)) {
260
+ instance.flexGrow(style.flexGrow)
261
+ }
262
+ if (!isUndefined(style.flexShrink)) {
263
+ instance.flexShrink(style.flexShrink)
264
+ }
265
+ if (!isUndefined(style.flexBasis)) {
266
+ instance.flexBasis(style.flexBasis)
267
+ }
268
+ if (!isUndefined(style.alignSelf)) {
269
+ instance.alignSelf(style.alignSelf)
270
+ }
271
+ if (!isUndefined(style.paddingTop) || !isUndefined(style.paddingRight) || !isUndefined(style.paddingBottom) || !isUndefined(style.paddingLeft)) {
272
+ instance.padding({
273
+ top: style.paddingTop,
274
+ right: style.paddingRight,
275
+ bottom: style.paddingBottom,
276
+ left: style.paddingLeft
277
+ })
278
+ }
279
+ if (!isUndefined(style.marginTop) || !isUndefined(style.marginRight) || !isUndefined(style.marginBottom) || !isUndefined(style.marginLeft)) {
280
+ instance.margin({
281
+ top: style.marginTop,
282
+ right: style.marginRight,
283
+ bottom: style.marginBottom,
284
+ left: style.marginLeft
285
+ })
286
+ }
287
+ if (node) {
288
+ instance.width(isMaxWidthView(node as TaroElement) && isUndefined(style.width) ? '100%' : style.width)
289
+ } else {
290
+ if (!isUndefined(style.width)) {
291
+ instance.width(style.width)
292
+ }
293
+ }
294
+ if (!isUndefined(style.height)) {
295
+ instance.height(style.height)
296
+ }
297
+ if (!isUndefined(style.minWidth) || !isUndefined(style.maxWidth) || !isUndefined(style.minHeight) || !isUndefined(style.maxHeight)) {
298
+ instance.constraintSize({
299
+ minWidth: style.minWidth,
300
+ maxWidth: style.maxWidth,
301
+ minHeight: style.minHeight,
302
+ maxHeight: style.maxHeight
303
+ })
304
+ }
305
+ if (!isUndefined(style.backgroundColor)) {
306
+ instance.backgroundColor(style.backgroundColor)
307
+ }
308
+ if (!isUndefined(style.backgroundImage)) {
309
+ if (style.backgroundImage.center) {
310
+ // radialGradient
311
+ instance.radialGradient(style.backgroundImage)
312
+ } else if (style.backgroundImage.colors) {
313
+ // linearGradient
314
+ instance.linearGradient(style.backgroundImage)
315
+ } else {
316
+ instance.backgroundImage(style.backgroundImage?.src, style.backgroundRepeat)
317
+ }
318
+ }
319
+ if (!isUndefined(style.backgroundSize)) {
320
+ instance.backgroundImageSize(style.backgroundSize)
321
+ }
322
+ if (!isUndefined(style.backgroundPosition)) {
323
+ if (typeof style.backgroundPosition !== 'number') {
324
+ let pos = computeBackgroundPosition(style)
325
+ instance.backgroundImagePosition({
326
+ x: pos.offsetX,
327
+ y: pos.offsetY,
328
+ })
329
+ } else {
330
+ instance.backgroundImagePosition(style.backgroundPosition)
331
+ }
332
+ }
333
+ if (!isUndefined(style.borderTopStyle) || !isUndefined(style.borderRightStyle) || !isUndefined(style.borderBottomStyle) || !isUndefined(style.borderLeftStyle)) {
334
+ instance.borderStyle({
335
+ top: style.borderTopStyle,
336
+ right: style.borderRightStyle,
337
+ bottom: style.borderBottomStyle,
338
+ left: style.borderLeftStyle
339
+ })
340
+ }
341
+ if (!isUndefined(style.borderTopWidth) || !isUndefined(style.borderRightWidth) || !isUndefined(style.borderBottomWidth) || !isUndefined(style.borderLeftWidth)) {
342
+ instance.borderWidth({
343
+ top: style.borderTopWidth,
344
+ right: style.borderRightWidth,
345
+ bottom: style.borderBottomWidth,
346
+ left: style.borderLeftWidth
347
+ })
348
+ }
349
+ if (!isUndefined(style.borderTopColor) || !isUndefined(style.borderRightColor) || !isUndefined(style.borderBottomColor) || !isUndefined(style.borderLeftColor)) {
350
+ instance.borderColor({
351
+ top: style.borderTopColor,
352
+ right: style.borderRightColor,
353
+ bottom: style.borderBottomColor,
354
+ left: style.borderLeftColor
355
+ })
356
+ }
357
+ if (!isUndefined(style.borderTopLeftRadius) || !isUndefined(style.borderTopRightRadius) || !isUndefined(style.borderBottomLeftRadius) || !isUndefined(style.borderBottomRightRadius)) {
358
+ instance.borderRadius({
359
+ topLeft: style.borderTopLeftRadius,
360
+ topRight: style.borderTopRightRadius,
361
+ bottomLeft: style.borderBottomLeftRadius,
362
+ bottomRight: style.borderBottomRightRadius
363
+ })
364
+ }
365
+ if (!isUndefined(style.opacity)) {
366
+ instance.opacity(style.opacity)
367
+ }
368
+ if (!isUndefined(style.overflow)) {
369
+ instance.clip(style.overflow === 'hidden')
370
+ }
371
+ if (style.position === 'absolute' || style.position === 'fixed') {
372
+ instance.position({
373
+ left: style.left,
374
+ top: style.top,
375
+ right: style.right,
376
+ bottom: style.bottom,
377
+ })
378
+ // 绝对定位和固定定位在web上都会脱离文档流,因此需要设置zIndex让它相比正常流的元素更上层
379
+ instance.zIndex(1)
380
+ }
381
+ if (style.position === 'relative') {
382
+ instance.offset({
383
+ left: style.left,
384
+ top: style.top,
385
+ right: style.right,
386
+ bottom: style.bottom,
387
+ })
388
+ // 绝对定位和固定定位在web上都会脱离文档流,因此需要设置zIndex让它相比正常流的元素更上层
389
+ instance.zIndex(1)
390
+ }
391
+ if (!isUndefined(style.zIndex)) {
392
+ // 为了适应position不设置z-index也能高于同层级组件,估且让设置了z-index的会更高一级
393
+ instance.zIndex(style.zIndex + 1)
394
+ }
395
+ if (!isUndefined(style.boxShadow)) {
396
+ instance.shadow({
397
+ radius: convertVp2Px(style.boxShadow.radius),
398
+ color: style.boxShadow.color,
399
+ offsetX: convertVp2Px(style.boxShadow.offsetX),
400
+ offsetY: convertVp2Px(style.boxShadow.offsetY),
401
+ fill: style.boxShadow.fill,
402
+ })
403
+ }
404
+ }
405
+
406
+ export const pseudoModify = new PseudoStyleModify()
407
+ export const rowModify = new RowStyleModify()
408
+ export const columnModify = new ColumnStyleModify()
409
+ export const textModify = new TextStyleModify()
153
410
 
154
- export default modify
411
+ export default new CommonStyleModify()
@@ -1,10 +1,9 @@
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
- import type { TaroSwiperElement, TaroEvent, TaroAny } from '@tarojs/runtime'
6
+ import type { TaroAny, TaroEvent, TaroSwiperElement } from '@tarojs/runtime'
8
7
 
9
8
  interface SwiperAttrs {
10
9
  index?: number
@@ -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,18 +40,29 @@ 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
48
  @Component
44
49
  export default struct TaroSwiper {
50
+ @Builder customBuilder() {}
51
+ @BuilderParam createLazyChildren: (node: TaroSwiperElement, layer?: number) => void = this.customBuilder
45
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
+ }
46
60
 
47
61
  build () {
48
62
  Swiper(this.node.controller) {
49
- createLazyChildren(this.node)
63
+ this.createLazyChildren(this.node, 0)
50
64
  }
51
- .attributeModifier(commonStyleModify.setNode(this.node))
65
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
52
66
  .swiperAttr(getSwiperAttributes(this.node))
53
67
  .indicatorStyle({
54
68
  color: this.node.getAttribute('indicatorColor'),
@@ -58,10 +72,33 @@ export default struct TaroSwiper {
58
72
  const event: TaroEvent = createTaroEvent('change', { detail: { current: index } }, this.node)
59
73
  eventHandler(event, 'change', this.node)
60
74
  })
61
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
75
+ .onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', this.node) }, this.node, ['click']))
62
76
  .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
63
77
  this.node._nodeInfo.areaInfo = res[1]
64
78
  }))
65
79
  .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
80
+ .onGestureSwipe(shouldBindEvent((index: number, extraInfo: SwiperAnimationEvent) => {
81
+ const currentOffset = extraInfo.currentOffset || 0
82
+ // 判断设置的滚动方向
83
+ const isVertical = this.node._attrs.vertical || false
84
+ let event: TaroEvent
85
+ if (isVertical) {
86
+ event = createTaroEvent('transition', { detail: { dx: 0, dy: vp2px(currentOffset) } }, this.node)
87
+ } else {
88
+ event = createTaroEvent('transition', { detail: { dx: vp2px(currentOffset), dy: 0 } }, this.node)
89
+ }
90
+ eventHandler(event, 'transition', this.node)
91
+ }, this.node, ['transition']))
92
+ .onTouch(shouldBindEvent((event: TouchEvent) => {
93
+ if (event.type === TouchType.Down) {
94
+ eventHandler(event, 'touchStart', this.node)
95
+ }
96
+ if (event.type === TouchType.Up) {
97
+ eventHandler(event, 'touchEnd', this.node)
98
+ }
99
+ if (event.type === TouchType.Move) {
100
+ eventHandler(event, 'touchMove', this.node)
101
+ }
102
+ }, this.node, ['touchstart', 'touchmove', 'touchend']))
66
103
  }
67
104
  }