@tarojs/plugin-platform-harmony-ets 3.7.0-alpha.27 → 4.0.0-alpha.10

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