@tarojs/plugin-platform-harmony-ets 4.0.0-canary.8 → 4.0.0

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 (135) hide show
  1. package/dist/apis/base/system.ts +73 -20
  2. package/dist/apis/canvas/index.ts +10 -1
  3. package/dist/apis/device/clipboard.ts +23 -8
  4. package/dist/apis/framework/index.ts +1 -5
  5. package/dist/apis/index.ts +27 -17
  6. package/dist/apis/media/image/index.ts +169 -17
  7. package/dist/apis/network/request.ts +5 -5
  8. package/dist/apis/route/index.ts +15 -0
  9. package/dist/apis/storage/index.ts +146 -78
  10. package/dist/apis/ui/animation/animation.ts +71 -29
  11. package/dist/apis/ui/background.ts +2 -1
  12. package/dist/apis/ui/interaction/index.ts +58 -59
  13. package/dist/apis/ui/navigation-bar/index.ts +1 -1
  14. package/dist/apis/ui/pull-down-refresh.ts +9 -3
  15. package/dist/apis/ui/scroll/index.ts +5 -5
  16. package/dist/apis/ui/tab-bar.ts +3 -3
  17. package/dist/apis/utils/index.ts +21 -2
  18. package/dist/apis/utils/permissions.ts +6 -0
  19. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  20. package/dist/apis/wxml/index.ts +2 -0
  21. package/dist/apis/wxml/selectorQuery.ts +26 -13
  22. package/dist/components-harmony-ets/button.ets +63 -77
  23. package/dist/components-harmony-ets/canvas.ets +51 -0
  24. package/dist/components-harmony-ets/checkbox.ets +75 -258
  25. package/dist/components-harmony-ets/form.ets +51 -158
  26. package/dist/components-harmony-ets/icon.ets +33 -83
  27. package/dist/components-harmony-ets/image.ets +35 -79
  28. package/dist/components-harmony-ets/index.ets +92 -0
  29. package/dist/components-harmony-ets/innerHtml.ets +11 -6
  30. package/dist/components-harmony-ets/input.ets +64 -101
  31. package/dist/components-harmony-ets/label.ets +72 -174
  32. package/dist/components-harmony-ets/listView.ets +31 -0
  33. package/dist/components-harmony-ets/movableArea.ets +126 -0
  34. package/dist/components-harmony-ets/movableView.ets +93 -0
  35. package/dist/components-harmony-ets/navigationBar.ets +65 -0
  36. package/dist/components-harmony-ets/pageMeta.ets +94 -0
  37. package/dist/components-harmony-ets/picker.ets +46 -163
  38. package/dist/components-harmony-ets/progress.ets +52 -0
  39. package/dist/components-harmony-ets/pseudo.ets +80 -0
  40. package/dist/components-harmony-ets/radio.ets +80 -264
  41. package/dist/components-harmony-ets/richText.ets +20 -102
  42. package/dist/components-harmony-ets/scrollList.ets +108 -0
  43. package/dist/components-harmony-ets/scrollView.ets +71 -160
  44. package/dist/components-harmony-ets/slider.ets +22 -82
  45. package/dist/components-harmony-ets/stickySection.ets +42 -0
  46. package/dist/components-harmony-ets/style.ets +410 -0
  47. package/dist/components-harmony-ets/swiper.ets +64 -87
  48. package/dist/components-harmony-ets/switch.ets +39 -99
  49. package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
  50. package/dist/components-harmony-ets/text.ets +111 -113
  51. package/dist/components-harmony-ets/textArea.ets +51 -95
  52. package/dist/components-harmony-ets/utils/AttributeManager.ets +2 -2
  53. package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -2
  54. package/dist/components-harmony-ets/utils/flexManager.ets +50 -19
  55. package/dist/components-harmony-ets/utils/helper.ets +20 -8
  56. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  57. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  58. package/dist/components-harmony-ets/utils/index.ts +54 -50
  59. package/dist/components-harmony-ets/utils/styles.ets +172 -92
  60. package/dist/components-harmony-ets/video.ets +37 -88
  61. package/dist/components-harmony-ets/view.ets +63 -159
  62. package/dist/components-harmony-ets/webView.ets +41 -98
  63. package/dist/index.d.ts +152 -0
  64. package/dist/index.js +187 -56
  65. package/dist/index.js.map +1 -1
  66. package/dist/runtime-ets/bom/document.ts +6 -4
  67. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
  68. package/dist/runtime-ets/bom/window.ts +9 -2
  69. package/dist/runtime-ets/current.ts +5 -1
  70. package/dist/runtime-ets/dom/bind.ts +28 -12
  71. package/dist/runtime-ets/dom/class-list.ts +2 -2
  72. package/dist/runtime-ets/dom/cssNesting.ts +419 -0
  73. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +28 -42
  74. package/dist/runtime-ets/dom/document.ts +22 -8
  75. package/dist/runtime-ets/dom/element/canvas.ts +136 -0
  76. package/dist/runtime-ets/dom/element/element.ts +376 -57
  77. package/dist/runtime-ets/dom/element/form.ts +31 -26
  78. package/dist/runtime-ets/dom/element/index.ts +30 -2
  79. package/dist/runtime-ets/dom/element/movableArea.ts +11 -0
  80. package/dist/runtime-ets/dom/element/movableView.ts +248 -0
  81. package/dist/runtime-ets/dom/element/normal.ts +35 -8
  82. package/dist/runtime-ets/dom/element/progress.ts +11 -0
  83. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  84. package/dist/runtime-ets/dom/element/text.ts +1 -8
  85. package/dist/runtime-ets/dom/element/video.ts +5 -4
  86. package/dist/runtime-ets/dom/element/webView.ts +12 -5
  87. package/dist/runtime-ets/dom/event.ts +3 -5
  88. package/dist/runtime-ets/dom/eventTarget.ts +2 -3
  89. package/dist/runtime-ets/dom/node.ts +65 -32
  90. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +418 -237
  91. package/dist/runtime-ets/dom/stylesheet/index.ts +29 -311
  92. package/dist/runtime-ets/dom/stylesheet/type.ts +53 -11
  93. package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
  94. package/dist/runtime-ets/index.ts +2 -2
  95. package/dist/runtime-ets/interface/event.ts +1 -1
  96. package/dist/runtime-ets/utils/index.ts +74 -13
  97. package/dist/runtime-ets/utils/info.ts +2 -2
  98. package/dist/runtime-framework/react/app.ts +25 -30
  99. package/dist/runtime-framework/react/hooks.ts +3 -4
  100. package/dist/runtime-framework/react/index.ts +0 -2
  101. package/dist/runtime-framework/react/native-page.ts +219 -82
  102. package/dist/runtime-framework/react/page.ts +6 -10
  103. package/dist/runtime-framework/react/utils/index.ts +3 -3
  104. package/dist/runtime-framework/solid/app.ts +30 -46
  105. package/dist/runtime-framework/solid/connect.ts +21 -3
  106. package/dist/runtime-framework/solid/hooks.ts +17 -12
  107. package/dist/runtime-framework/solid/index.ts +6 -2
  108. package/dist/runtime-framework/solid/page.ts +85 -31
  109. package/dist/runtime-framework/solid/reconciler/props.ts +70 -25
  110. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  111. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  112. package/dist/runtime-framework/solid/utils/index.ts +3 -5
  113. package/dist/runtime-utils.d.ts +827 -0
  114. package/dist/runtime-utils.js +618 -245
  115. package/dist/runtime-utils.js.map +1 -1
  116. package/dist/runtime.d.ts +1 -0
  117. package/dist/runtime.js +618 -245
  118. package/dist/runtime.js.map +1 -1
  119. package/index.js +3 -1
  120. package/package.json +14 -15
  121. package/static/media/cancel.svg +1 -1
  122. package/static/media/circle.svg +1 -1
  123. package/static/media/clear.svg +1 -1
  124. package/static/media/download.svg +1 -1
  125. package/static/media/info.svg +1 -1
  126. package/static/media/info_circle.svg +1 -1
  127. package/static/media/search.svg +1 -1
  128. package/static/media/success.svg +1 -1
  129. package/static/media/success_no_circle.svg +1 -1
  130. package/static/media/warn.svg +1 -1
  131. package/types/harmony.d.ts +5 -0
  132. package/types/index.d.ts +4 -0
  133. package/types/runtime.d.ts +3 -1
  134. package/dist/runtime-ets/utils/bind.ts +0 -24
  135. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
@@ -0,0 +1,410 @@
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'
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
+ instance.textOverflow({overflow: TextOverflow.Ellipsis})
226
+ }
227
+ if (!isUndefined(style.letterSpacing)) {
228
+ instance.letterSpacing(style.letterSpacing)
229
+ }
230
+ if (!isUndefined(style.lineHeight)) {
231
+ instance.lineHeight(style.lineHeight)
232
+ }
233
+ if (!isUndefined(style.wordBreak)) {
234
+ if (style.wordBreak == 'break-all') {
235
+ instance.wordBreak(WordBreak.BREAK_ALL)
236
+ } else if (style.wordBreak == 'break-word') {
237
+ instance.wordBreak(WordBreak.BREAK_WORD)
238
+ } else if (style.wordBreak == 'normal') {
239
+ instance.wordBreak(WordBreak.NORMAL)
240
+ }
241
+ }
242
+ }
243
+
244
+ export function setNormalAttributeIntoInstance(instance: CommonAttribute, style: TaroStyleType, node?: TaroElement | null) {
245
+ instance.renderFit(RenderFit.RESIZE_FILL)
246
+ if (!isUndefined(style.id)) {
247
+ instance.id(style.id)
248
+ instance.key(style.id)
249
+ }
250
+ if (!isUndefined(style.display) || !isUndefined(style.visibility)) {
251
+ instance.visibility(style.display === 'none'
252
+ ? Visibility.None :
253
+ !isUndefined(style.visibility)
254
+ ? (style.visibility === 'hidden' ? Visibility.Hidden : Visibility.Visible)
255
+ : Visibility.Visible
256
+ )
257
+ }
258
+ if (!isUndefined(style.flexGrow)) {
259
+ instance.flexGrow(style.flexGrow)
260
+ }
261
+ if (!isUndefined(style.flexShrink)) {
262
+ instance.flexShrink(style.flexShrink)
263
+ }
264
+ if (!isUndefined(style.flexBasis)) {
265
+ instance.flexBasis(style.flexBasis)
266
+ }
267
+ if (!isUndefined(style.alignSelf)) {
268
+ instance.alignSelf(style.alignSelf)
269
+ }
270
+ if (!isUndefined(style.paddingTop) || !isUndefined(style.paddingRight) || !isUndefined(style.paddingBottom) || !isUndefined(style.paddingLeft)) {
271
+ instance.padding({
272
+ top: style.paddingTop,
273
+ right: style.paddingRight,
274
+ bottom: style.paddingBottom,
275
+ left: style.paddingLeft
276
+ })
277
+ }
278
+ if (!isUndefined(style.marginTop) || !isUndefined(style.marginRight) || !isUndefined(style.marginBottom) || !isUndefined(style.marginLeft)) {
279
+ instance.margin({
280
+ top: style.marginTop,
281
+ right: style.marginRight,
282
+ bottom: style.marginBottom,
283
+ left: style.marginLeft
284
+ })
285
+ }
286
+ if (node) {
287
+ instance.width(isMaxWidthView(node as TaroElement) && isUndefined(style.width) ? '100%' : style.width)
288
+ } else {
289
+ if (!isUndefined(style.width)) {
290
+ instance.width(style.width)
291
+ }
292
+ }
293
+ if (!isUndefined(style.height)) {
294
+ instance.height(style.height)
295
+ }
296
+ if (!isUndefined(style.minWidth) || !isUndefined(style.maxWidth) || !isUndefined(style.minHeight) || !isUndefined(style.maxHeight)) {
297
+ instance.constraintSize({
298
+ minWidth: style.minWidth,
299
+ maxWidth: style.maxWidth,
300
+ minHeight: style.minHeight,
301
+ maxHeight: style.maxHeight
302
+ })
303
+ }
304
+ if (!isUndefined(style.backgroundColor)) {
305
+ instance.backgroundColor(style.backgroundColor)
306
+ }
307
+ if (!isUndefined(style.backgroundImage)) {
308
+ if (style.backgroundImage.center) {
309
+ // radialGradient
310
+ instance.radialGradient(style.backgroundImage)
311
+ } else if (style.backgroundImage.colors) {
312
+ // linearGradient
313
+ instance.linearGradient(style.backgroundImage)
314
+ } else {
315
+ instance.backgroundImage(style.backgroundImage?.src, style.backgroundRepeat)
316
+ }
317
+ }
318
+ if (!isUndefined(style.backgroundSize)) {
319
+ instance.backgroundImageSize(style.backgroundSize)
320
+ }
321
+ if (!isUndefined(style.backgroundPosition)) {
322
+ if (typeof style.backgroundPosition !== 'number') {
323
+ let pos = computeBackgroundPosition(style)
324
+ instance.backgroundImagePosition({
325
+ x: pos.offsetX,
326
+ y: pos.offsetY,
327
+ })
328
+ } else {
329
+ instance.backgroundImagePosition(style.backgroundPosition)
330
+ }
331
+ }
332
+ if (!isUndefined(style.borderTopStyle) || !isUndefined(style.borderRightStyle) || !isUndefined(style.borderBottomStyle) || !isUndefined(style.borderLeftStyle)) {
333
+ instance.borderStyle({
334
+ top: style.borderTopStyle,
335
+ right: style.borderRightStyle,
336
+ bottom: style.borderBottomStyle,
337
+ left: style.borderLeftStyle
338
+ })
339
+ }
340
+ if (!isUndefined(style.borderTopWidth) || !isUndefined(style.borderRightWidth) || !isUndefined(style.borderBottomWidth) || !isUndefined(style.borderLeftWidth)) {
341
+ instance.borderWidth({
342
+ top: style.borderTopWidth,
343
+ right: style.borderRightWidth,
344
+ bottom: style.borderBottomWidth,
345
+ left: style.borderLeftWidth
346
+ })
347
+ }
348
+ if (!isUndefined(style.borderTopColor) || !isUndefined(style.borderRightColor) || !isUndefined(style.borderBottomColor) || !isUndefined(style.borderLeftColor)) {
349
+ instance.borderColor({
350
+ top: style.borderTopColor,
351
+ right: style.borderRightColor,
352
+ bottom: style.borderBottomColor,
353
+ left: style.borderLeftColor
354
+ })
355
+ }
356
+ if (!isUndefined(style.borderTopLeftRadius) || !isUndefined(style.borderTopRightRadius) || !isUndefined(style.borderBottomLeftRadius) || !isUndefined(style.borderBottomRightRadius)) {
357
+ instance.borderRadius({
358
+ topLeft: style.borderTopLeftRadius,
359
+ topRight: style.borderTopRightRadius,
360
+ bottomLeft: style.borderBottomLeftRadius,
361
+ bottomRight: style.borderBottomRightRadius
362
+ })
363
+ }
364
+ if (!isUndefined(style.opacity)) {
365
+ instance.opacity(style.opacity)
366
+ }
367
+ if (!isUndefined(style.overflow)) {
368
+ instance.clip(style.overflow === 'hidden')
369
+ }
370
+ if (style.position === 'absolute' || style.position === 'fixed') {
371
+ instance.position({
372
+ left: style.left,
373
+ top: style.top,
374
+ right: style.right,
375
+ bottom: style.bottom,
376
+ })
377
+ // 绝对定位和固定定位在web上都会脱离文档流,因此需要设置zIndex让它相比正常流的元素更上层
378
+ instance.zIndex(1)
379
+ }
380
+ if (style.position === 'relative') {
381
+ instance.offset({
382
+ left: style.left,
383
+ top: style.top,
384
+ right: style.right,
385
+ bottom: style.bottom,
386
+ })
387
+ // 绝对定位和固定定位在web上都会脱离文档流,因此需要设置zIndex让它相比正常流的元素更上层
388
+ instance.zIndex(1)
389
+ }
390
+ if (!isUndefined(style.zIndex)) {
391
+ // 为了适应position不设置z-index也能高于同层级组件,估且让设置了z-index的会更高一级
392
+ instance.zIndex(style.zIndex + 1)
393
+ }
394
+ if (!isUndefined(style.boxShadow)) {
395
+ instance.shadow({
396
+ radius: convertVp2Px(style.boxShadow.radius),
397
+ color: style.boxShadow.color,
398
+ offsetX: convertVp2Px(style.boxShadow.offsetX),
399
+ offsetY: convertVp2Px(style.boxShadow.offsetY),
400
+ fill: style.boxShadow.fill,
401
+ })
402
+ }
403
+ }
404
+
405
+ export const pseudoModify = new PseudoStyleModify()
406
+ export const rowModify = new RowStyleModify()
407
+ export const columnModify = new ColumnStyleModify()
408
+ export const textModify = new TextStyleModify()
409
+
410
+ export default new CommonStyleModify()
@@ -1,9 +1,9 @@
1
1
  import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
2
2
 
3
- import { createLazyChildren } from './render'
4
- import { getNodeThresholds, getNormalAttributes, shouldBindEvent } from './utils/helper'
3
+ import commonStyleModify from './style'
4
+ import { getNodeThresholds, shouldBindEvent } from './utils/helper'
5
5
 
6
- import type { TaroStyleType, TaroSwiperElement, TaroEvent, TaroAny } from '@tarojs/runtime'
6
+ import type { TaroSwiperElement, TaroEvent, TaroAny } from '@tarojs/runtime'
7
7
 
8
8
  interface SwiperAttrs {
9
9
  index?: number
@@ -13,71 +13,8 @@ interface SwiperAttrs {
13
13
  vertical?: boolean
14
14
  autoPlay?: boolean
15
15
  indicator?: boolean
16
- }
17
-
18
- @Extend(Swiper)
19
- function swiperStyle (style: TaroStyleType) {
20
- .id(style.id)
21
- .key(style.id)
22
- .flexGrow(style.flexGrow)
23
- .flexShrink(style.flexShrink)
24
- .flexBasis(style.flexBasis)
25
- .alignSelf(style.alignSelf)
26
- .padding({
27
- top: style.paddingTop,
28
- right: style.paddingRight,
29
- bottom: style.paddingBottom,
30
- left: style.paddingLeft
31
- })
32
- .margin({
33
- top: style.marginTop,
34
- right: style.marginRight,
35
- bottom: style.marginBottom,
36
- left: style.marginLeft
37
- })
38
- .width(style.width)
39
- .height(style.height)
40
- .constraintSize({
41
- minWidth: style.minWidth,
42
- maxWidth: style.maxWidth,
43
- minHeight: style.minHeight,
44
- maxHeight: style.maxHeight
45
- })
46
- .backgroundColor(style.backgroundColor)
47
- .backgroundImage(style.backgroundImage?.src, style.backgroundRepeat)
48
- .backgroundImageSize(style.backgroundSize)
49
- .backgroundImagePosition(style.backgroundPosition)
50
- .borderStyle({
51
- top: style.borderTopStyle,
52
- right: style.borderRightStyle,
53
- bottom: style.borderBottomStyle,
54
- left: style.borderLeftStyle
55
- })
56
- .borderWidth({
57
- top: style.borderTopWidth,
58
- right: style.borderRightWidth,
59
- bottom: style.borderBottomWidth,
60
- left: style.borderLeftWidth
61
- })
62
- .borderColor({
63
- top: style.borderTopColor,
64
- right: style.borderRightColor,
65
- bottom: style.borderBottomColor,
66
- left: style.borderLeftColor
67
- })
68
- .borderRadius({
69
- topLeft: style.borderTopLeftRadius,
70
- topRight: style.borderTopRightRadius,
71
- bottomLeft: style.borderBottomLeftRadius,
72
- bottomRight: style.borderBottomRightRadius
73
- })
74
- .zIndex(style.zIndex)
75
- .opacity(style.opacity)
76
- .linearGradient(style.linearGradient)
77
- .clip(style.overflow)
78
- .rotate({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y, angle: 0 })
79
- .scale({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y })
80
- .transform(style.transform)
16
+ nextMargin?: Length
17
+ prevMargin?: Length
81
18
  }
82
19
 
83
20
  @Extend(Swiper)
@@ -89,6 +26,8 @@ function swiperAttr (attr: SwiperAttrs) {
89
26
  .vertical(attr.vertical)
90
27
  .autoPlay(attr.autoPlay)
91
28
  .indicator(attr.indicator)
29
+ .nextMargin(attr.nextMargin)
30
+ .prevMargin(attr.prevMargin)
92
31
  }
93
32
 
94
33
  function getSwiperAttributes (node: TaroSwiperElement): SwiperAttrs {
@@ -101,27 +40,65 @@ function getSwiperAttributes (node: TaroSwiperElement): SwiperAttrs {
101
40
  swiperAttrs.vertical = _attrs.vertical || false
102
41
  swiperAttrs.autoPlay = _attrs.autoplay || false
103
42
  swiperAttrs.indicator = _attrs.indicatorDots || false
43
+ swiperAttrs.nextMargin = _attrs.nextMargin || 0
44
+ swiperAttrs.prevMargin = _attrs.previousMargin || 0
104
45
  return swiperAttrs
105
46
  }
106
47
 
107
- @Builder
108
- export default function TaroSwiper (node: TaroSwiperElement) {
109
- Swiper(node.controller) {
110
- createLazyChildren(node)
48
+ @Component
49
+ export default struct TaroSwiper {
50
+ @Builder customBuilder() {}
51
+ @BuilderParam createLazyChildren: (node: TaroSwiperElement, layer?: number) => void = this.customBuilder
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
+ }
60
+
61
+ build () {
62
+ Swiper(this.node.controller) {
63
+ this.createLazyChildren(this.node, 0)
64
+ }
65
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
66
+ .swiperAttr(getSwiperAttributes(this.node))
67
+ .indicatorStyle({
68
+ color: this.node.getAttribute('indicatorColor'),
69
+ selectedColor: this.node.getAttribute('indicatorActiveColor')
70
+ })
71
+ .onChange((index: number) => {
72
+ const event: TaroEvent = createTaroEvent('change', { detail: { current: index } }, this.node)
73
+ eventHandler(event, 'change', this.node)
74
+ })
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: 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']))
111
103
  }
112
- .swiperStyle(getNormalAttributes(node))
113
- .swiperAttr(getSwiperAttributes(node))
114
- .indicatorStyle({
115
- color: node.getAttribute('indicatorColor'),
116
- selectedColor: node.getAttribute('indicatorActiveColor')
117
- })
118
- .onChange((index: number) => {
119
- const event: TaroEvent = createTaroEvent('change', { detail: { current: index } }, node)
120
- eventHandler(event, 'change', node)
121
- })
122
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
123
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
124
- node._nodeInfo.areaInfo = res[1]
125
- }))
126
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
127
104
  }