@tarojs/plugin-platform-harmony-ets 4.0.0-alpha.0 → 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 (139) 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 +16 -8
  4. package/dist/apis/device/memory.ts +10 -3
  5. package/dist/apis/framework/index.ts +1 -5
  6. package/dist/apis/index.ts +27 -17
  7. package/dist/apis/media/image/index.ts +1 -1
  8. package/dist/apis/media/video/VideoContext.ts +56 -7
  9. package/dist/apis/media/video/index.ts +3 -2
  10. package/dist/apis/network/request.ts +5 -5
  11. package/dist/apis/route/index.ts +15 -0
  12. package/dist/apis/storage/index.ts +146 -78
  13. package/dist/apis/ui/animation/animation.ts +71 -29
  14. package/dist/apis/ui/background.ts +2 -1
  15. package/dist/apis/ui/interaction/index.ts +42 -59
  16. package/dist/apis/ui/navigation-bar/index.ts +1 -1
  17. package/dist/apis/ui/pull-down-refresh.ts +9 -3
  18. package/dist/apis/ui/scroll/index.ts +5 -5
  19. package/dist/apis/ui/tab-bar.ts +3 -3
  20. package/dist/apis/utils/index.ts +1 -1
  21. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  22. package/dist/apis/wxml/index.ts +2 -0
  23. package/dist/apis/wxml/selectorQuery.ts +26 -13
  24. package/dist/components-harmony-ets/button.ets +68 -68
  25. package/dist/components-harmony-ets/canvas.ets +51 -0
  26. package/dist/components-harmony-ets/checkbox.ets +81 -102
  27. package/dist/components-harmony-ets/form.ets +54 -45
  28. package/dist/components-harmony-ets/icon.ets +34 -50
  29. package/dist/components-harmony-ets/image.ets +35 -45
  30. package/dist/components-harmony-ets/index.ets +92 -0
  31. package/dist/components-harmony-ets/innerHtml.ets +11 -6
  32. package/dist/components-harmony-ets/input.ets +51 -67
  33. package/dist/components-harmony-ets/label.ets +73 -53
  34. package/dist/components-harmony-ets/listView.ets +26 -0
  35. package/dist/components-harmony-ets/movableArea.ets +124 -0
  36. package/dist/components-harmony-ets/movableView.ets +93 -0
  37. package/dist/components-harmony-ets/navigationBar.ets +65 -0
  38. package/dist/components-harmony-ets/pageMeta.ets +94 -0
  39. package/dist/components-harmony-ets/picker.ets +74 -77
  40. package/dist/components-harmony-ets/progress.ets +52 -0
  41. package/dist/components-harmony-ets/pseudo.ets +80 -0
  42. package/dist/components-harmony-ets/radio.ets +82 -104
  43. package/dist/components-harmony-ets/richText.ets +20 -68
  44. package/dist/components-harmony-ets/scrollList.ets +94 -0
  45. package/dist/components-harmony-ets/scrollView.ets +67 -103
  46. package/dist/components-harmony-ets/slider.ets +23 -47
  47. package/dist/components-harmony-ets/stickySection.ets +42 -0
  48. package/dist/components-harmony-ets/style.ets +396 -0
  49. package/dist/components-harmony-ets/swiper.ets +64 -53
  50. package/dist/components-harmony-ets/switch.ets +44 -55
  51. package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
  52. package/dist/components-harmony-ets/text.ets +134 -75
  53. package/dist/components-harmony-ets/textArea.ets +54 -62
  54. package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
  55. package/dist/components-harmony-ets/utils/DynamicCenter.ts +4 -13
  56. package/dist/components-harmony-ets/utils/flexManager.ets +76 -8
  57. package/dist/components-harmony-ets/utils/helper.ets +20 -7
  58. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  59. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  60. package/dist/components-harmony-ets/utils/index.ts +54 -50
  61. package/dist/components-harmony-ets/utils/styles.ets +178 -63
  62. package/dist/components-harmony-ets/video.ets +37 -54
  63. package/dist/components-harmony-ets/view.ets +63 -94
  64. package/dist/components-harmony-ets/webView.ets +56 -0
  65. package/dist/index.d.ts +152 -0
  66. package/dist/index.js +199 -58
  67. package/dist/index.js.map +1 -1
  68. package/dist/runtime-ets/bom/document.ts +6 -4
  69. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
  70. package/dist/runtime-ets/bom/window.ts +9 -2
  71. package/dist/runtime-ets/current.ts +3 -0
  72. package/dist/runtime-ets/dom/bind.ts +28 -12
  73. package/dist/runtime-ets/dom/class-list.ts +2 -2
  74. package/dist/runtime-ets/dom/cssNesting.ts +409 -0
  75. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +29 -19
  76. package/dist/runtime-ets/dom/document.ts +22 -8
  77. package/dist/runtime-ets/dom/element/canvas.ts +136 -0
  78. package/dist/runtime-ets/dom/element/element.ts +334 -57
  79. package/dist/runtime-ets/dom/element/form.ts +32 -26
  80. package/dist/runtime-ets/dom/element/index.ts +33 -2
  81. package/dist/runtime-ets/dom/element/movableArea.ts +11 -0
  82. package/dist/runtime-ets/dom/element/movableView.ts +242 -0
  83. package/dist/runtime-ets/dom/element/normal.ts +36 -8
  84. package/dist/runtime-ets/dom/element/progress.ts +11 -0
  85. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  86. package/dist/runtime-ets/dom/element/text.ts +1 -8
  87. package/dist/runtime-ets/dom/element/video.ts +5 -4
  88. package/dist/runtime-ets/dom/element/webView.ts +68 -0
  89. package/dist/runtime-ets/dom/event.ts +2 -4
  90. package/dist/runtime-ets/dom/eventTarget.ts +2 -3
  91. package/dist/runtime-ets/dom/node.ts +62 -27
  92. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +805 -0
  93. package/dist/runtime-ets/dom/stylesheet/index.ts +98 -518
  94. package/dist/runtime-ets/dom/stylesheet/type.ts +92 -17
  95. package/dist/runtime-ets/dom/stylesheet/util.ts +74 -16
  96. package/dist/runtime-ets/index.ts +2 -2
  97. package/dist/runtime-ets/interface/event.ts +3 -2
  98. package/dist/runtime-ets/utils/index.ts +77 -12
  99. package/dist/runtime-ets/utils/info.ts +4 -2
  100. package/dist/runtime-framework/react/app.ts +17 -22
  101. package/dist/runtime-framework/react/hooks.ts +3 -4
  102. package/dist/runtime-framework/react/index.ts +1 -2
  103. package/dist/runtime-framework/react/native-page.ts +421 -0
  104. package/dist/runtime-framework/react/page.ts +4 -9
  105. package/dist/runtime-framework/solid/app.ts +25 -45
  106. package/dist/runtime-framework/solid/connect.ts +21 -3
  107. package/dist/runtime-framework/solid/hooks.ts +17 -12
  108. package/dist/runtime-framework/solid/index.ts +6 -2
  109. package/dist/runtime-framework/solid/page.ts +84 -30
  110. package/dist/runtime-framework/solid/reconciler/props.ts +70 -25
  111. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  112. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  113. package/dist/runtime-framework/solid/utils/index.ts +0 -2
  114. package/dist/runtime-utils.d.ts +827 -0
  115. package/dist/runtime-utils.js +510 -237
  116. package/dist/runtime-utils.js.map +1 -1
  117. package/dist/runtime.d.ts +1 -0
  118. package/dist/runtime.js +510 -237
  119. package/dist/runtime.js.map +1 -1
  120. package/index.js +3 -1
  121. package/package.json +14 -15
  122. package/static/media/cancel.svg +1 -0
  123. package/static/media/circle.svg +1 -0
  124. package/static/media/clear.svg +1 -0
  125. package/static/media/download.svg +1 -0
  126. package/static/media/info.svg +1 -0
  127. package/static/media/info_circle.svg +1 -0
  128. package/static/media/search.svg +1 -0
  129. package/static/media/success.svg +1 -0
  130. package/static/media/success_no_circle.svg +1 -0
  131. package/static/media/taro_arrow_left.svg +1 -0
  132. package/static/media/taro_home.svg +1 -0
  133. package/static/media/waiting.svg +1 -0
  134. package/static/media/warn.svg +1 -0
  135. package/types/harmony.d.ts +4 -0
  136. package/types/index.d.ts +4 -0
  137. package/types/runtime.d.ts +3 -1
  138. package/dist/runtime-ets/utils/bind.ts +0 -24
  139. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
@@ -0,0 +1,94 @@
1
+ import { APP, eventCenter } from '@tarojs/runtime/dist/runtime.esm'
2
+ import { getCurrentInstance, pageScrollTo } from '@tarojs/taro'
3
+
4
+ import { isTagFirstChild } from './utils/helper'
5
+
6
+ import type { TaroAny, TaroPageMetaElement } from '@tarojs/runtime'
7
+
8
+ export interface IComponentAttributeUpdateEvents {
9
+ id: string
10
+ tagName: string
11
+ attribute: string
12
+ value: TaroAny
13
+ }
14
+
15
+ @Component
16
+ export default struct TaroPageMeta {
17
+ @Builder customBuilder() {}
18
+ @BuilderParam createLazyChildren: (node: TaroPageMetaElement) => void = this.customBuilder
19
+ @ObjectLink node: TaroPageMetaElement
20
+
21
+ page: TaroAny = {}
22
+
23
+ aboutToAppear(): void {
24
+ if (!isTagFirstChild(this.node, APP, 2)) {
25
+ // PageMeta 只能是页面内的第一个元素
26
+ console.error('PageMeta 只能是页面内的第一个元素。')
27
+ }
28
+
29
+ this.page = getCurrentInstance().page
30
+ if (this.node) {
31
+ this.node._instance = this
32
+ }
33
+
34
+ // FIXME 在 Harmony 提供 @Watch 文档后,根据 node 实际使用更细粒度的监听
35
+ eventCenter.on('__taroComponentAttributeUpdate', this.handleAttributeUpdate)
36
+ this.handleAttributes(this.node._attrs)
37
+ }
38
+
39
+ aboutToDisappear(): void {
40
+ eventCenter.off('__taroComponentAttributeUpdate', this.handleAttributeUpdate)
41
+ }
42
+
43
+ handleAttributeUpdate = (opt: IComponentAttributeUpdateEvents) => {
44
+ if (opt.id === this.node._nid && opt.tagName === 'PAGE-META') {
45
+ const attrs: Record<string, TaroAny> = {}
46
+ attrs[opt.attribute] = opt.value
47
+ this.handleAttributes(attrs)
48
+ }
49
+ }
50
+
51
+ handleAttributes (attrs: Record<string, TaroAny>) {
52
+ const options: Record<string, TaroAny> = {}
53
+ let triggerStyleEvent = false
54
+
55
+ // FIXME 更新类型支持度
56
+ if (attrs.backgroundColorTop || attrs.rootBackgroundColor || attrs.backgroundColor) {
57
+ options.backgroundColorContext = attrs.backgroundColorTop || attrs.rootBackgroundColor || attrs.backgroundColor
58
+ triggerStyleEvent = true
59
+ }
60
+ if (attrs.backgroundColorBottom || attrs.backgroundColor) {
61
+ options.backgroundColor = attrs.backgroundColorBottom || attrs.backgroundColor
62
+ triggerStyleEvent = true
63
+ }
64
+ if (attrs.backgroundTextStyle) {
65
+ options.backgroundTextStyle = attrs.backgroundTextStyle
66
+ triggerStyleEvent = true
67
+ }
68
+
69
+ if (this.page === getCurrentInstance().page) {
70
+ if (attrs.scrollTop || attrs.scrollDuration) {
71
+ pageScrollTo({
72
+ scrollTop: attrs.scrollTop || this.node._attrs.scrollTop,
73
+ duration: attrs.scrollDuration || this.node._attrs.scrollDuration,
74
+ } as TaroAny)
75
+ }
76
+ }
77
+ // pageStyle
78
+ // rootFontSize
79
+ // pageFontSize
80
+ // pageOrientation
81
+ if (triggerStyleEvent) {
82
+ eventCenter.trigger('__taroPageStyle', options)
83
+ }
84
+ // onResize
85
+ // onScroll
86
+ // onScrollDone
87
+ }
88
+
89
+ build() {
90
+ if (true) {
91
+ this.createLazyChildren(this.node)
92
+ }
93
+ }
94
+ }
@@ -1,75 +1,13 @@
1
1
  import { AREA_CHANGE_EVENT_NAME, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME, TaroPickerElement, createTaroEvent } from '@tarojs/runtime'
2
- import { createLazyChildren } from './render'
2
+ import commonStyleModify from './style'
3
3
  import { getSingleSelector, getMultiSelector } from './utils'
4
4
  import { TOUCH_EVENT_MAP } from './utils/constant/event'
5
- import { FlexManager } from './utils/FlexManager'
6
- import { getNormalAttributes, shouldBindEvent, getNodeThresholds } from './utils/helper'
5
+ import { FlexManager } from './utils/flexManager'
6
+ import { shouldBindEvent, getNodeThresholds } from './utils/helper'
7
7
 
8
- import type { TaroAny, TaroStyleType, TaroEvent } from '@tarojs/runtime'
8
+ import type { TaroAny, TaroEvent } from '@tarojs/runtime'
9
9
 
10
- import { PickerDateProps, PickerMultiSelectorProps, PickerSelectorProps, PickerTimeProps } from './types'
11
-
12
- @Extend(TextPicker)
13
- function textPickerAttrs (style: TaroStyleType) {
14
- .id(style.id)
15
- .key(style.id)
16
- .padding(style.padding)
17
- .margin(style.margin)
18
- .width(style.width || '100%')
19
- .height(style.height)
20
- .constraintSize(style.constraintSize)
21
- .flexGrow(style.flexGrow)
22
- .flexShrink(style.flexShrink)
23
- .flexBasis(style.flexBasis)
24
- .alignSelf(style.alignSelf)
25
- .backgroundColor(style.backgroundColor || '#fff')
26
- .backgroundImage(style.backgroundImage, style.backgroundRepeat)
27
- .backgroundImageSize(style.backgroundImageSize)
28
- .backgroundImagePosition(style.backgroundImagePosition)
29
- .rotate(style.rotate)
30
- .scale(style.scale)
31
- .translate(style.translate)
32
- .transform(style.transform)
33
- .borderStyle(style.borderStyle)
34
- .borderWidth(style.borderWidth)
35
- .borderColor(style.borderColor)
36
- .borderRadius(style.borderRadius)
37
- .linearGradient(style.linearGradient)
38
- .zIndex(style.zIndex)
39
- .opacity(style.opacity)
40
- .clip(style.clip)
41
- }
42
-
43
- @Extend(DatePicker)
44
- function datePickerAttrs (style: TaroStyleType) {
45
- .id(style.id)
46
- .key(style.id)
47
- .padding(style.padding)
48
- .margin(style.margin)
49
- .width(style.width || '100%')
50
- .height(style.height)
51
- .constraintSize(style.constraintSize)
52
- .flexGrow(style.flexGrow)
53
- .flexShrink(style.flexShrink)
54
- .flexBasis(style.flexBasis)
55
- .alignSelf(style.alignSelf)
56
- .backgroundColor(style.backgroundColor || '#fff')
57
- .backgroundImage(style.backgroundImage, style.backgroundRepeat)
58
- .backgroundImageSize(style.backgroundImageSize)
59
- .backgroundImagePosition(style.backgroundImagePosition)
60
- .rotate(style.rotate)
61
- .scale(style.scale)
62
- .translate(style.translate)
63
- .transform(style.transform)
64
- .borderStyle(style.borderStyle)
65
- .borderWidth(style.borderWidth)
66
- .borderColor(style.borderColor)
67
- .borderRadius(style.borderRadius)
68
- .linearGradient(style.linearGradient)
69
- .zIndex(style.zIndex)
70
- .opacity(style.opacity)
71
- .clip(style.clip)
72
- }
10
+ import { PickerDateProps, PickerMultiSelectorProps, PickerSelectorProps, PickerTimeProps } from '@tarojs/components/types'
73
11
 
74
12
  interface TimeRange {
75
13
  startHH: number
@@ -129,7 +67,7 @@ export struct PickerView {
129
67
  const left = generateNumberArray(timeRange.startHH, timeRange.endHH)
130
68
  const right = generateNumberArray(timeRange.startMM, timeRange.endMM)
131
69
  const range = [left, right]
132
- const _selected = _attrs.value.split(':')
70
+ const _selected = _attrs.value?.split(':') as string[]
133
71
  return {
134
72
  range: range,
135
73
  selected: [left.findIndex(i => parseInt(_selected[0]) === Number(i)), right.findIndex(i => parseInt(_selected[1]) === Number(i))],
@@ -191,7 +129,7 @@ export struct PickerView {
191
129
  this.controller?.close()
192
130
  })
193
131
  Text(this.getText()[0]).fontSize(15).padding({top: 20, bottom: 40}).fontColor('#1aad19').onClick(() => {
194
- this.emitEvent('change', { value: this.node?.value})
132
+ this.emitEvent('change', { value: this.node?.value })
195
133
  this.controller?.close()
196
134
  })
197
135
  }
@@ -207,7 +145,10 @@ export struct PickerView {
207
145
  color: '#000'
208
146
  })
209
147
  .canLoop(false)
210
- .textPickerAttrs(getNormalAttributes(this.node))
148
+ .attributeModifier(commonStyleModify.setNode(this.node, {
149
+ width: '100%',
150
+ backgroundColor: '#fff'
151
+ }))
211
152
  .onChange((_, index) => {
212
153
  this.node?.updateFormWidgetValue(index)
213
154
  })
@@ -217,7 +158,10 @@ export struct PickerView {
217
158
  color: '#000'
218
159
  })
219
160
  .canLoop(false)
220
- .textPickerAttrs(getNormalAttributes(this.node))
161
+ .attributeModifier(commonStyleModify.setNode(this.node, {
162
+ width: '100%',
163
+ backgroundColor: '#fff'
164
+ }))
221
165
  .onChange((_, index) => {
222
166
  if (index instanceof Array) {
223
167
  this.node?.updateFormWidgetValue(index)
@@ -244,7 +188,10 @@ export struct PickerView {
244
188
  .selectedTextStyle({
245
189
  color: '#000'
246
190
  })
247
- .datePickerAttrs(getNormalAttributes(this.node))
191
+ .attributeModifier(commonStyleModify.setNode(this.node, {
192
+ width: '100%',
193
+ backgroundColor: '#fff'
194
+ }))
248
195
  .onDateChange(value => {
249
196
  const data = value.toLocaleDateString().split('/')
250
197
  const day = data[1]
@@ -258,7 +205,10 @@ export struct PickerView {
258
205
  color: '#000'
259
206
  })
260
207
  .canLoop(false)
261
- .textPickerAttrs(getNormalAttributes(this.node))
208
+ .attributeModifier(commonStyleModify.setNode(this.node, {
209
+ width: '100%',
210
+ backgroundColor: '#fff'
211
+ }))
262
212
  .onChange((value) => {
263
213
  this.node?.updateFormWidgetValue(`${('00'+value[0]).slice(-2)}:${('00'+value[1]).slice(-2)}`)
264
214
  })
@@ -272,12 +222,49 @@ export struct PickerView {
272
222
  }
273
223
  }
274
224
 
225
+
275
226
  @Component
276
227
  export default struct TaroPicker {
277
- node: TaroPickerElement | null = null
228
+ @Builder customBuilder() {}
229
+ @BuilderParam createLazyChildren: (node: TaroPickerElement) => void = this.customBuilder
230
+ @ObjectLink node: TaroPickerElement
278
231
 
279
232
  aboutToAppear () {
280
233
  this.node?.addEventListener('click', this.handleClick)
234
+
235
+ if (this.node && !this.node._isInit) {
236
+ let defaultResetValue: TaroAny = ''
237
+ switch (this.node._attrs.mode) {
238
+ case 'selector':
239
+ defaultResetValue = 0
240
+ break
241
+ case 'multiSelector':
242
+ defaultResetValue = this.node._attrs.range.map((_: TaroAny) => 0)
243
+ break
244
+ case 'time': {
245
+ const hour = new Date().getHours()
246
+ const minute = new Date().getMinutes()
247
+
248
+ defaultResetValue = `${('00'+hour).slice(-2)}:${('00'+minute).slice(-2)}`
249
+ break
250
+ }
251
+ case 'date': {
252
+ const data = new Date().toLocaleDateString().split('/')
253
+ const day = data[1]
254
+ const month = data[0]
255
+ const year = data[2]
256
+
257
+ defaultResetValue = `${year}-${month}-${day}`
258
+ break
259
+ }
260
+ default:
261
+ defaultResetValue = ''
262
+ break
263
+ }
264
+
265
+ this.node._isInit = true
266
+ this.node._reset = this.node.value || defaultResetValue
267
+ }
281
268
  }
282
269
 
283
270
  dialogController: CustomDialogController | null = null
@@ -324,12 +311,22 @@ export default struct TaroPicker {
324
311
  }
325
312
 
326
313
  build() {
327
- if (this.node) {
328
- Flex(FlexManager.flexOptions(this.node)) {
329
- createLazyChildren(this.node)
314
+ if (FlexManager.isFlexNode(this.node) && FlexManager.direction(this.node) !== FlexDirection.Column) {
315
+ Row() {
316
+ this.createLazyChildren(this.node)
317
+ }
318
+ .defaultEvent()
319
+ .visibleChangeEvent()
320
+ .alignItems(FlexManager.alignItems<VerticalAlign>(this.node))
321
+ .justifyContent(FlexManager.justifyContent(this.node))
322
+ } else {
323
+ Column() {
324
+ this.createLazyChildren(this.node)
330
325
  }
331
326
  .defaultEvent()
332
327
  .visibleChangeEvent()
328
+ .alignItems(FlexManager.alignItems<HorizontalAlign>(this.node))
329
+ .justifyContent(FlexManager.justifyContent(this.node))
333
330
  }
334
331
  }
335
332
  }
@@ -0,0 +1,52 @@
1
+ import type { TaroProgressElement, TaroAny } from '@tarojs/runtime'
2
+ import commonStyleModify from './style'
3
+ import { shouldBindEvent, getNodeThresholds } from './utils/helper'
4
+ import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME } from '@tarojs/runtime'
5
+
6
+ const PROGRESS_ACTIVECOLOR = '#09BB07'
7
+ const PROGRESS_BACKGROUNDCOLOR = '#EBEBEB'
8
+ const PROGRESS_DEFAULTINFOFONTSIZE = 16
9
+
10
+ @Component
11
+ export default struct TaroProgress {
12
+ @Builder customBuilder() {}
13
+ @BuilderParam createLazyChildren: (node: TaroProgressElement) => void = this.customBuilder
14
+ @ObjectLink node: TaroProgressElement
15
+ @State overwriteStyle: Record<string, TaroAny> = {}
16
+
17
+ aboutToAppear(): void {
18
+ if (this.node) {
19
+ this.node._instance = this
20
+ }
21
+ }
22
+
23
+ build() {
24
+ Row({ space: 5 }) {
25
+ Progress({
26
+ value: parseFloat(this.node.getAttribute('percent')),
27
+ type: ProgressType.Linear
28
+ })
29
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
30
+ .color(this.node.getAttribute('activeColor') ?? PROGRESS_ACTIVECOLOR)
31
+ .backgroundColor(this.node.getAttribute('backgroundColor') ?? PROGRESS_BACKGROUNDCOLOR)
32
+ .style({
33
+ strokeWidth: this.node.getAttribute('strokeWidth'),
34
+ strokeRadius: parseFloat(this.node.getAttribute('borderRadius')),
35
+ enableSmoothEffect: Boolean(this.node.getAttribute('active')),
36
+ })
37
+
38
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
39
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
40
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
41
+ if (this.node) {
42
+ this.node._nodeInfo.areaInfo = res[1]
43
+ }
44
+ }))
45
+
46
+ if (this.node.getAttribute('showInfo')) {
47
+ Text(`${this.node.getAttribute('percent')}%`)
48
+ .fontSize(this.node.getAttribute('fontSize') ?? PROGRESS_DEFAULTINFOFONTSIZE)
49
+ }
50
+ }
51
+ }
52
+ }
@@ -0,0 +1,80 @@
1
+ import { getFontAttributes } from './utils/helper'
2
+ import { pseudoModify } from './style'
3
+
4
+ import type { TaroViewElement, TaroStyleType, TaroTextStyleType, TaroAny } from '@tarojs/runtime'
5
+
6
+ @Extend(Flex)
7
+ function flexAttrs (style: TaroStyleType) {
8
+ .constraintSize({
9
+ minWidth: style.minWidth,
10
+ maxWidth: style.maxWidth,
11
+ minHeight: style.minHeight || style.height,
12
+ maxHeight: style.maxHeight
13
+ })
14
+ }
15
+
16
+
17
+ @Extend(Text)
18
+ function textNormalFontStyle (style: TaroStyleType) {
19
+ .id(style.id)
20
+ .key(style.id)
21
+ .opacity(style.opacity)
22
+ .fontColor(style.color)
23
+ .fontSize(style.fontSize)
24
+ .fontWeight(style.fontWeight)
25
+ .fontStyle(style.fontStyle)
26
+ .fontFamily(style.fontFamily)
27
+ .decoration({
28
+ type: style.textDecoration?.type || TextDecorationType.None,
29
+ color: style.color
30
+ })
31
+ }
32
+
33
+ @Extend(Text)
34
+ function textSpecialFontStyle(attr: TaroTextStyleType) {
35
+ .textAlign(attr.textAlign)
36
+ .align(attr.verticalAlign)
37
+ .textOverflow(attr.textOverflow)
38
+ .maxLines(attr.WebkitLineClamp)
39
+ .letterSpacing(attr.letterSpacing)
40
+ .lineHeight(attr.lineHeight)
41
+ }
42
+
43
+ @Component
44
+ export default struct PseduoChildren {
45
+ @Builder customBuilder() {}
46
+ @BuilderParam createLazyChildren: (node: TaroAny) => void = this.customBuilder
47
+ @ObjectLink node: TaroViewElement
48
+
49
+ build () {
50
+ if (true) {
51
+ // 伪类::Before
52
+ if (this.node._pseudo_before) {
53
+ if (this.node._pseudo_before?.hmStyle.content) {
54
+ Text(this.node._pseudo_before.hmStyle.content)
55
+ .attributeModifier(pseudoModify.setStyle(this.node._pseudo_before.hmStyle))
56
+ .textNormalFontStyle(this.node._pseudo_before.hmStyle || {})
57
+ .textSpecialFontStyle(getFontAttributes(this.node))
58
+ } else {
59
+ Flex() {}
60
+ .attributeModifier(pseudoModify.setStyle(this.node._pseudo_before.hmStyle || {}))
61
+ .flexAttrs(this.node._pseudo_before.hmStyle || {})
62
+ }
63
+ }
64
+ this.createLazyChildren(this.node)
65
+ // 伪类::After
66
+ if (this.node._pseudo_after) {
67
+ if (this.node._pseudo_after?.hmStyle.content) {
68
+ Text(this.node._pseudo_after.hmStyle.content)
69
+ .attributeModifier(pseudoModify.setStyle(this.node._pseudo_after.hmStyle))
70
+ .textNormalFontStyle(this.node._pseudo_after.hmStyle || {})
71
+ .textSpecialFontStyle(getFontAttributes(this.node))
72
+ } else {
73
+ Flex() {}
74
+ .attributeModifier(pseudoModify.setStyle(this.node._pseudo_after.hmStyle || {}))
75
+ .flexAttrs(this.node._pseudo_after.hmStyle || {})
76
+ }
77
+ }
78
+ }
79
+ }
80
+ }
@@ -1,48 +1,18 @@
1
1
  import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
2
2
 
3
- import { createLazyChildren } from './render'
3
+ import commonStyleModify, { rowModify, columnModify } from './style'
4
4
  import { TOUCH_EVENT_MAP } from './utils/constant/event'
5
- import { FlexManager } from './utils/FlexManager'
6
- import { shouldBindEvent, getNormalAttributes, getNodeThresholds } from './utils/helper'
5
+ import { FlexManager } from './utils/flexManager'
6
+ import { shouldBindEvent, getNodeThresholds } from './utils/helper'
7
7
 
8
- import type { TaroEvent, TaroAny, TaroStyleType, HarmonyType, TaroRadioGroupElement, TaroRadioElement } from '@tarojs/runtime'
8
+ import { TaroEvent, TaroAny, HarmonyType, TaroRadioGroupElement, TaroRadioElement } from '@tarojs/runtime'
9
+ import { isUndefined } from '@tarojs/shared'
9
10
 
10
11
  interface RadioAttrs {
11
12
  radioStyle?: HarmonyType.RadioStyle
12
13
  themeStyles?: boolean
13
14
  }
14
15
 
15
- @Extend(Radio)
16
- function style (style: TaroStyleType) {
17
- .id(style.id)
18
- .key(style.id)
19
- .padding(style.padding)
20
- .margin(style.margin)
21
- .width(style.width)
22
- .height(style.height)
23
- .constraintSize(style.constraintSize)
24
- .flexGrow(style.flexGrow)
25
- .flexShrink(style.flexShrink)
26
- .flexBasis(style.flexBasis)
27
- .alignSelf(style.alignSelf)
28
- .backgroundColor(style.backgroundColor)
29
- .backgroundImage(style.backgroundImage, style.backgroundRepeat)
30
- .backgroundImageSize(style.backgroundImageSize)
31
- .backgroundImagePosition(style.backgroundImagePosition)
32
- .rotate(style.rotate)
33
- .scale(style.scale)
34
- .translate(style.translate)
35
- .transform(style.transform)
36
- .borderStyle(style.borderStyle)
37
- .borderWidth(style.borderWidth)
38
- .borderColor(style.borderColor)
39
- .borderRadius(style.borderRadius)
40
- .linearGradient(style.linearGradient)
41
- .zIndex(style.zIndex)
42
- .opacity(style.opacity)
43
- .clip(style.clip)
44
- }
45
-
46
16
  @Extend(Radio)
47
17
  function radioAttr (attr: RadioAttrs) {
48
18
  .radioStyle(attr.radioStyle)
@@ -63,81 +33,74 @@ function themeStyles(isDisabled: boolean) {
63
33
  .opacity(isDisabled ? 0.4 : 1)
64
34
  }
65
35
 
66
- @Builder
67
- export function TaroRadio (node: TaroRadioElement) {
68
- Stack() {
69
- Row() {
70
- Radio({
71
- group: node.group || node.parentNode?._nid || '',
72
- value: node._attrs.value || '',
73
- })
74
- .checked(node.checked)
75
- .style(getNormalAttributes(node))
76
- .radioAttr(getAttributes(node))
77
- .onChange((value: boolean) => {
78
- if (!!node?._attrs.disabled) {
79
- node.updateComponent()
80
- } else {
81
- node.updateCheckedValue(value)
82
-
83
- if (value) {
84
- const event: TaroEvent = createTaroEvent('change', { detail: { value: node?._attrs.value } }, node)
85
- eventHandler(event, 'change', node)
36
+ @Component
37
+ export struct TaroRadio {
38
+ @Builder customBuilder() {}
39
+ @BuilderParam createLazyChildren: (node: TaroRadioElement) => void = this.customBuilder
40
+ @ObjectLink node: TaroRadioElement
41
+ @State overwriteStyle: Record<string, TaroAny> = {}
42
+
43
+ aboutToAppear () {
44
+ if (this.node && !this.node._isInit) {
45
+ this.node._isInit = true
46
+ this.node._instance = this
47
+ this.node._reset = this.node.checked || false
48
+ }
49
+ }
50
+
51
+ build () {
52
+ Stack() {
53
+ Row() {
54
+ Radio({
55
+ group: this.node.group || this.node.parentNode?._nid || '',
56
+ value: this.node.value || '',
57
+ })
58
+ .checked(this.node.checked)
59
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
60
+ .radioAttr(getAttributes(this.node))
61
+ .onChange((value: boolean) => {
62
+ if (this.node) {
63
+ if (!!this.node?._attrs.disabled) {
64
+ this.node.updateComponent()
65
+ } else {
66
+ this.node.updateCheckedValue(value)
67
+
68
+ if (value) {
69
+ const event: TaroEvent = createTaroEvent('change', { detail: { value: this.node?._attrs.value } }, this.node)
70
+ eventHandler(event, 'change', this.node)
71
+ }
72
+ }
73
+ }
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
+ if (this.node) {
78
+ this.node._nodeInfo.areaInfo = res[1]
86
79
  }
80
+ }))
81
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
82
+ Text(this.node.textContent)
83
+ .textAlign(TextAlign.Center)
84
+ .opacity(!!this.node?._attrs.disabled ? 0.4 : 1)
85
+ }
86
+ .onClick(() => {
87
+ if (this.node) {
88
+ if (!this.node._checked && !this.node?._attrs.disabled) {
89
+ this.node.checked = !this.node.checked
87
90
  }
88
- })
89
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
90
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
91
- node._nodeInfo.areaInfo = res[1]
92
- }))
93
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
94
- Text(node.textContent)
95
- .textAlign(TextAlign.Center)
96
- .opacity(!!node?._attrs.disabled ? 0.4 : 1)
91
+ }
92
+ })
97
93
  }
98
- .onClick(() => {
99
- if (!node._checked && !node?._attrs.disabled) {
100
- node.checked = !node.checked
101
- }
102
- })
103
94
  }
104
95
  }
105
96
 
106
- @Extend(Flex)
107
- function radioGroupAttrs (style: TaroStyleType) {
108
- .id(style.id)
109
- .key(style.id)
110
- .padding(style.padding)
111
- .margin(style.margin)
112
- .width(style.width)
113
- .height(style.height)
114
- .constraintSize(style.constraintSize)
115
- .flexGrow(style.flexGrow)
116
- .flexShrink(style.flexShrink)
117
- .flexBasis(style.flexBasis)
118
- .alignSelf(style.alignSelf)
119
- .backgroundColor(style.backgroundColor)
120
- .backgroundImage(style.backgroundImage, style.backgroundRepeat)
121
- .backgroundImageSize(style.backgroundImageSize)
122
- .backgroundImagePosition(style.backgroundImagePosition)
123
- .rotate(style.rotate)
124
- .scale(style.scale)
125
- .translate(style.translate)
126
- .transform(style.transform)
127
- .borderStyle(style.borderStyle)
128
- .borderWidth(style.borderWidth)
129
- .borderColor(style.borderColor)
130
- .borderRadius(style.borderRadius)
131
- .linearGradient(style.linearGradient)
132
- .zIndex(style.zIndex)
133
- .opacity(style.opacity)
134
- .clip(style.clip)
135
- }
136
-
137
97
 
138
98
  @Component
139
99
  export struct TaroRadioGroup {
140
- node: TaroRadioGroupElement | null = null
100
+ @Builder customBuilder() {}
101
+ @BuilderParam createLazyChildren: (node: TaroRadioGroupElement) => void = this.customBuilder
102
+ @ObjectLink node: TaroRadioGroupElement
103
+ @State overwriteStyle: Record<string, TaroAny> = {}
141
104
 
142
105
  @Styles visibleChangeEvent () {
143
106
  .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
@@ -145,6 +108,7 @@ export struct TaroRadioGroup {
145
108
 
146
109
  aboutToAppear () {
147
110
  if (this.node) {
111
+ this.node._instance = this
148
112
  const childList = this.node.getElementsByTagName<TaroRadioElement>('RADIO')
149
113
  childList.forEach(element => {
150
114
  element.group = this.node?._attrs.name || this.node?._nid
@@ -165,11 +129,25 @@ export struct TaroRadioGroup {
165
129
  }
166
130
 
167
131
  build() {
168
- if (this.node) {
132
+ if (FlexManager.useFlexLayout(this.node)) {
169
133
  Flex(FlexManager.flexOptions(this.node)) {
170
- createLazyChildren(this.node)
134
+ this.createLazyChildren(this.node)
135
+ }
136
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
137
+ .defaultEvent()
138
+ .visibleChangeEvent()
139
+ } else if (FlexManager.isFlexNode(this.node) && FlexManager.direction(this.node) !== FlexDirection.Column) {
140
+ Row() {
141
+ this.createLazyChildren(this.node)
142
+ }
143
+ .attributeModifier(rowModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
144
+ .defaultEvent()
145
+ .visibleChangeEvent()
146
+ } else {
147
+ Column() {
148
+ this.createLazyChildren(this.node)
171
149
  }
172
- .radioGroupAttrs(getNormalAttributes(this.node))
150
+ .attributeModifier(columnModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
173
151
  .defaultEvent()
174
152
  .visibleChangeEvent()
175
153
  }