@tarojs/plugin-platform-harmony-ets 4.0.0-beta.13 → 4.0.0-beta.131

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 (146) hide show
  1. package/dist/apis/base/system.ts +60 -25
  2. package/dist/apis/base/weapp/life-cycle.ts +1 -1
  3. package/dist/apis/canvas/index.ts +10 -1
  4. package/dist/apis/device/clipboard.ts +23 -8
  5. package/dist/apis/framework/index.ts +1 -1
  6. package/dist/apis/index.ts +24 -16
  7. package/dist/apis/media/image/index.ts +169 -17
  8. package/dist/apis/network/downloadFile.ts +3 -1
  9. package/dist/apis/network/uploadFile.ts +3 -1
  10. package/dist/apis/route/index.ts +1 -2
  11. package/dist/apis/storage/index.ts +135 -131
  12. package/dist/apis/ui/animation/animation.ts +71 -29
  13. package/dist/apis/ui/background.ts +3 -2
  14. package/dist/apis/ui/interaction/index.ts +58 -59
  15. package/dist/apis/ui/navigation-bar/index.ts +2 -2
  16. package/dist/apis/ui/pull-down-refresh.ts +9 -3
  17. package/dist/apis/ui/scroll/index.ts +5 -5
  18. package/dist/apis/ui/tab-bar.ts +4 -5
  19. package/dist/apis/utils/handler.ts +2 -1
  20. package/dist/apis/utils/index.ts +20 -2
  21. package/dist/apis/utils/permissions.ts +6 -0
  22. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  23. package/dist/apis/wxml/selectorQuery.ts +26 -13
  24. package/dist/components-harmony-ets/button.ets +36 -9
  25. package/dist/components-harmony-ets/canvas.ets +51 -0
  26. package/dist/components-harmony-ets/checkbox.ets +69 -60
  27. package/dist/components-harmony-ets/form.ets +33 -15
  28. package/dist/components-harmony-ets/icon.ets +16 -8
  29. package/dist/components-harmony-ets/image.ets +22 -6
  30. package/dist/components-harmony-ets/index.ets +39 -0
  31. package/dist/components-harmony-ets/innerHtml.ets +6 -5
  32. package/dist/components-harmony-ets/input.ets +63 -37
  33. package/dist/components-harmony-ets/label.ets +43 -21
  34. package/dist/components-harmony-ets/listView.ets +32 -0
  35. package/dist/components-harmony-ets/movableArea.ets +110 -51
  36. package/dist/components-harmony-ets/movableView.ets +74 -47
  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 +36 -33
  40. package/dist/components-harmony-ets/progress.ets +31 -24
  41. package/dist/components-harmony-ets/pseudo.ets +43 -35
  42. package/dist/components-harmony-ets/radio.ets +75 -66
  43. package/dist/components-harmony-ets/richText.ets +4 -25
  44. package/dist/components-harmony-ets/scrollList.ets +108 -0
  45. package/dist/components-harmony-ets/scrollView.ets +53 -44
  46. package/dist/components-harmony-ets/slider.ets +19 -15
  47. package/dist/components-harmony-ets/stickySection.ets +42 -0
  48. package/dist/components-harmony-ets/style.ets +274 -38
  49. package/dist/components-harmony-ets/swiper.ets +42 -5
  50. package/dist/components-harmony-ets/switch.ets +36 -32
  51. package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
  52. package/dist/components-harmony-ets/text.ets +102 -46
  53. package/dist/components-harmony-ets/textArea.ets +49 -34
  54. package/dist/components-harmony-ets/utils/AttributeManager.ets +2 -2
  55. package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -2
  56. package/dist/components-harmony-ets/utils/flexManager.ets +43 -13
  57. package/dist/components-harmony-ets/utils/helper.ets +20 -8
  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 +165 -104
  62. package/dist/components-harmony-ets/video.ets +28 -20
  63. package/dist/components-harmony-ets/view.ets +44 -38
  64. package/dist/components-harmony-ets/webView.ets +6 -5
  65. package/dist/index.d.ts +152 -0
  66. package/dist/index.js +73 -44
  67. package/dist/index.js.map +1 -1
  68. package/dist/runtime-ets/bom/URL.ts +2 -0
  69. package/dist/runtime-ets/bom/document.ts +5 -4
  70. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -3
  71. package/dist/runtime-ets/bom/history.ts +1 -0
  72. package/dist/runtime-ets/bom/location.ts +1 -0
  73. package/dist/runtime-ets/bom/navigator.ts +1 -21
  74. package/dist/runtime-ets/bom/raf.ts +1 -37
  75. package/dist/runtime-ets/bom/window.ts +9 -5
  76. package/dist/runtime-ets/constant.ts +17 -10
  77. package/dist/runtime-ets/current.ts +26 -2
  78. package/dist/runtime-ets/dom/bind.ts +28 -12
  79. package/dist/runtime-ets/dom/class-list.ts +2 -2
  80. package/dist/runtime-ets/dom/cssNesting.ts +419 -0
  81. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +28 -42
  82. package/dist/runtime-ets/dom/document.ts +9 -12
  83. package/dist/runtime-ets/dom/element/canvas.ts +137 -0
  84. package/dist/runtime-ets/dom/element/element.ts +355 -71
  85. package/dist/runtime-ets/dom/element/form.ts +26 -22
  86. package/dist/runtime-ets/dom/element/index.ts +22 -2
  87. package/dist/runtime-ets/dom/element/movableArea.ts +0 -1
  88. package/dist/runtime-ets/dom/element/movableView.ts +238 -2
  89. package/dist/runtime-ets/dom/element/normal.ts +27 -6
  90. package/dist/runtime-ets/dom/element/progress.ts +0 -2
  91. package/dist/runtime-ets/dom/element/text.ts +0 -8
  92. package/dist/runtime-ets/dom/element/video.ts +4 -4
  93. package/dist/runtime-ets/dom/element/webView.ts +4 -5
  94. package/dist/runtime-ets/dom/event-source.ts +1 -0
  95. package/dist/runtime-ets/dom/event.ts +3 -5
  96. package/dist/runtime-ets/dom/eventTarget.ts +3 -4
  97. package/dist/runtime-ets/dom/node.ts +53 -22
  98. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +401 -243
  99. package/dist/runtime-ets/dom/stylesheet/index.ts +27 -316
  100. package/dist/runtime-ets/dom/stylesheet/type.ts +52 -11
  101. package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
  102. package/dist/runtime-ets/emitter/emitter.ts +1 -0
  103. package/dist/runtime-ets/env.ts +1 -0
  104. package/dist/runtime-ets/index.ts +23 -7
  105. package/dist/runtime-ets/interface/event.ts +1 -1
  106. package/dist/runtime-ets/interface/index.ts +6 -0
  107. package/dist/runtime-ets/utils/index.ts +78 -19
  108. package/dist/runtime-ets/utils/info.ts +2 -2
  109. package/dist/runtime-ets/utils/router.ts +9 -0
  110. package/dist/runtime-framework/react/app.ts +10 -10
  111. package/dist/runtime-framework/react/hooks.ts +1 -2
  112. package/dist/runtime-framework/react/index.ts +0 -2
  113. package/dist/runtime-framework/react/native-page.ts +212 -80
  114. package/dist/runtime-framework/react/page.ts +3 -10
  115. package/dist/runtime-framework/react/utils/index.ts +3 -3
  116. package/dist/runtime-framework/solid/app.ts +29 -46
  117. package/dist/runtime-framework/solid/connect.ts +21 -3
  118. package/dist/runtime-framework/solid/hooks.ts +16 -11
  119. package/dist/runtime-framework/solid/index.ts +6 -2
  120. package/dist/runtime-framework/solid/page.ts +84 -31
  121. package/dist/runtime-framework/solid/reconciler/props.ts +73 -29
  122. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  123. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  124. package/dist/runtime-framework/solid/utils/index.ts +3 -5
  125. package/dist/runtime-utils.d.ts +826 -0
  126. package/dist/runtime-utils.js +575 -284
  127. package/dist/runtime-utils.js.map +1 -1
  128. package/dist/runtime.d.ts +1 -0
  129. package/dist/runtime.js +575 -284
  130. package/dist/runtime.js.map +1 -1
  131. package/index.js +3 -1
  132. package/package.json +14 -15
  133. package/static/media/cancel.svg +1 -1
  134. package/static/media/circle.svg +1 -1
  135. package/static/media/clear.svg +1 -1
  136. package/static/media/download.svg +1 -1
  137. package/static/media/info.svg +1 -1
  138. package/static/media/info_circle.svg +1 -1
  139. package/static/media/search.svg +1 -1
  140. package/static/media/success.svg +1 -1
  141. package/static/media/success_no_circle.svg +1 -1
  142. package/static/media/warn.svg +1 -1
  143. package/types/harmony.d.ts +5 -0
  144. package/types/index.d.ts +4 -0
  145. package/types/runtime.d.ts +8 -1
  146. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
@@ -1,68 +1,93 @@
1
+ import { isString } from '@tarojs/shared'
1
2
  import { eventHandler, convertNumber2VP, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, NodeType } from '@tarojs/runtime'
2
3
 
3
- import commonStyleModify from './style'
4
+ import commonStyleModify, { textModify, setNormalTextAttributeIntoInstance } from './style'
4
5
  import { getButtonColor } from './button'
6
+ import { getImageMode } from './image'
5
7
  import { BUTTON_THEME_COLOR } from './utils/constant/style'
6
- import { getNodeThresholds, getNormalAttributes, getFontAttributes, shouldBindEvent } from './utils/helper'
8
+ import { getNodeThresholds, getStyleAttr, shouldBindEvent, getNormalAttributes } from './utils/helper'
7
9
 
8
- import type { TaroButtonElement, TaroElement, TaroTextElement, TaroAny, TaroTextStyleType, TaroStyleType } from '@tarojs/runtime'
10
+ import type { HarmonyStyle, TaroAny, TaroButtonElement, TaroElement, TaroTextElement } from '@tarojs/runtime'
9
11
 
10
- @Extend(Text)
11
- function textNormalFontStyle (style: TaroStyleType) {
12
- .id(style.id)
13
- .key(style.id)
14
- .opacity(style.opacity)
15
- .fontColor(style.color)
16
- .fontSize(style.fontSize)
17
- .fontWeight(style.fontWeight)
18
- .fontStyle(style.fontStyle)
19
- .fontFamily(style.fontFamily)
20
- .lineHeight(style.lineHeight)
21
- .decoration({
22
- type: style.textDecoration,
23
- color: style.color
24
- })
25
- }
12
+ function getButtonFontSize (node: TaroButtonElement): string | number {
13
+ const isMini = node._attrs.size === 'mini'
26
14
 
27
- @Extend(Text)
28
- function textSpecialFontStyle(attr: TaroTextStyleType) {
29
- .textAlign(attr.textAlign)
30
- .textOverflow(attr.textOverflow)
31
- .maxLines(attr.WebkitLineClamp)
32
- .letterSpacing(attr.letterSpacing)
15
+ return isMini ? convertNumber2VP(26) : convertNumber2VP(36)
33
16
  }
34
17
 
35
- function getButtonFontSize (node: TaroButtonElement) {
36
- const isMini = node._attrs.size === 'mini'
18
+ function getTextInViewWidth (node: TaroElement | null): TaroAny {
19
+ if (node) {
20
+ const hmStyle = node.hmStyle || {}
21
+ const isFlexView = hmStyle.display === 'flex'
22
+ const width: TaroAny = getStyleAttr(node, 'width')
23
+ const isPercentWidth = isString(width) && width.includes('%')
37
24
 
38
- return isMini ? convertNumber2VP(26) : convertNumber2VP(36)
25
+ return isFlexView || isPercentWidth ? null : getStyleAttr(node, 'width')
26
+ }
39
27
  }
40
28
 
29
+
41
30
  @Component
42
31
  export default struct TaroText {
32
+ @Builder customBuilder() {}
33
+ @BuilderParam createLazyChildren: (node: TaroTextElement, layer?: number) => void = this.customBuilder
43
34
  @ObjectLink node: TaroTextElement
35
+ @State overwriteStyle: Record<string, TaroAny> = {}
36
+
37
+ aboutToAppear(): void {
38
+ if (this.node) {
39
+ this.node._instance = this
40
+ }
41
+ }
44
42
 
45
43
  build () {
46
- if (this.node.nodeType === NodeType.TEXT_NODE && this.node.parentNode) {
47
- if ((this.node.parentNode as TaroElement).tagName === 'BUTTON') {
48
- Text(this.node.textContent)
49
- .textNormalFontStyle(getNormalAttributes(this.node.parentNode as TaroElement))
50
- .textSpecialFontStyle(getFontAttributes(this.node.parentNode as TaroElement))
51
- .fontSize((this.node.parentNode as TaroButtonElement).hmStyle.fontSize || getButtonFontSize(this.node.parentNode as TaroButtonElement))
52
- .fontColor((this.node.parentNode as TaroButtonElement).hmStyle.color || getButtonColor(this.node.parentNode as TaroButtonElement, BUTTON_THEME_COLOR.get((this.node.parentNode as TaroButtonElement)._attrs.type).text))
53
- } else {
54
- Text(this.node.textContent)
55
- .textNormalFontStyle(getNormalAttributes(this.node.parentNode as TaroElement))
56
- .textSpecialFontStyle(getFontAttributes(this.node.parentNode as TaroElement))
57
- .width(getNormalAttributes(this.node.parentNode as TaroElement).width)
58
- .height(getNormalAttributes(this.node.parentNode as TaroElement).height)
44
+ if (this.node.nodeType === NodeType.TEXT_NODE) {
45
+ if (this.node.parentNode) {
46
+ if ((this.node.parentNode as TaroElement).tagName === 'BUTTON') {
47
+ Text(this.node.textContent)
48
+ .attributeModifier(textModify.setNode(this.node?.parentElement as TaroElement, {
49
+ fontSize: getButtonFontSize(this.node.parentNode as TaroButtonElement),
50
+ color: getButtonColor(this.node.parentNode as TaroButtonElement, BUTTON_THEME_COLOR.get((this.node.parentNode as TaroButtonElement)._attrs.type || '').text)
51
+ }))
52
+ } else {
53
+ Text(this.node.textContent)
54
+ .attributeModifier(textModify.setNode(this.node?.parentElement as TaroElement))
55
+ .width(getTextInViewWidth(this.node.parentElement))
56
+ }
59
57
  }
60
58
  } else {
61
- Text(this.node.textContent)
62
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
63
- .attributeModifier(commonStyleModify.setNode(this.node))
64
- .textNormalFontStyle(getNormalAttributes(this.node))
65
- .textSpecialFontStyle(getFontAttributes(this.node))
59
+ Text(this.node.textContent) {
60
+ // text 下还有标签
61
+ if (this.node.childNodes.length > 1 || ((this.node.childNodes[0] && this.node.childNodes[0] as TaroElement)?.nodeType === NodeType.ELEMENT_NODE)) {
62
+ ForEach(this.node.childNodes, (item: TaroElement) => {
63
+ if (item.tagName === 'IMAGE') {
64
+ ImageSpan(item.getAttribute('src'))
65
+ .attributeModifier(commonStyleModify.setNode(item))
66
+ .objectFit(getImageMode(item.getAttribute('mode')))
67
+ .verticalAlign(getImageSpanAlignment(this.node?.hmStyle?.verticalAlign))
68
+ .onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', item) }, item, ['click']))
69
+ } else if (item.nodeType === NodeType.TEXT_NODE) {
70
+ Span(item.textContent)
71
+ } else if (item.tagName === 'TEXT') {
72
+ Span(item.textContent)
73
+ .attributeModifier(spanModify.setNode(item))
74
+ .letterSpacing(item._st.hmStyle.letterSpacing)
75
+ .textBackgroundStyle({
76
+ color: item._st.hmStyle.backgroundColor,
77
+ radius: {
78
+ topLeft: item._st.hmStyle.borderTopLeftRadius,
79
+ topRight: item._st.hmStyle.borderTopRightRadius,
80
+ bottomLeft: item._st.hmStyle.borderBottomLeftRadius,
81
+ bottomRight: item._st.hmStyle.borderBottomRightRadius,
82
+ }
83
+ })
84
+ .onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', item) }, item, ['click']))
85
+ }
86
+ }, (item: TaroElement) => `${item._nid}${this.node._updateTrigger}`)
87
+ }
88
+ }
89
+ .onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', this.node) }, this.node, ['click']))
90
+ .attributeModifier(textModify.setNode(this.node).withNormalStyle().setAnimationStyle(this.overwriteStyle))
66
91
  .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
67
92
  .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
68
93
  this.node._nodeInfo.areaInfo = res[1]
@@ -70,3 +95,34 @@ export default struct TaroText {
70
95
  }
71
96
  }
72
97
  }
98
+
99
+ function getImageSpanAlignment (align: TaroAny): TaroAny {
100
+ if (align === Alignment.Top) {
101
+ return ImageSpanAlignment.TOP
102
+ } else if (align === Alignment.Bottom) {
103
+ return ImageSpanAlignment.BOTTOM
104
+ } else if (align === Alignment.Center) {
105
+ return ImageSpanAlignment.CENTER
106
+ }
107
+ }
108
+
109
+ class SpanStyleModify implements AttributeModifier<SpanAttribute> {
110
+ node: TaroTextElement | null = null
111
+ style: HarmonyStyle | null = null
112
+ overwriteStyle: Record<string, TaroAny> = {}
113
+ withNormal = false
114
+
115
+ setNode (node: TaroTextElement) {
116
+ this.node = node
117
+ this.style = getNormalAttributes(this.node)
118
+ return this
119
+ }
120
+
121
+ applyNormalAttribute(instance: SpanAttribute): void {
122
+ if (this.node && this.style) {
123
+ setNormalTextAttributeIntoInstance(instance, this.style, this.node)
124
+ }
125
+ }
126
+ }
127
+
128
+ const spanModify = new SpanStyleModify()
@@ -1,10 +1,15 @@
1
1
  import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
2
2
 
3
3
  import commonStyleModify from './style'
4
- import { getNodeThresholds, getNormalAttributes, getFontAttributes, shouldBindEvent, parseStyles } from './utils/helper'
4
+ import { getNodeThresholds, getFontAttributes, shouldBindEvent, parseStyles } from './utils/helper'
5
5
 
6
6
  import type { TaroAny, TaroStyleType, TaroTextStyleType, TaroTextAreaElement, TaroEvent } from '@tarojs/runtime'
7
7
 
8
+ interface TextareaAttrs extends TaroTextStyleType {
9
+ autoFocus?: boolean
10
+ disabled?: boolean
11
+ }
12
+
8
13
  @Extend(TextArea)
9
14
  function textStyle (style: TaroStyleType) {
10
15
  .fontColor(style.color)
@@ -15,9 +20,18 @@ function textStyle (style: TaroStyleType) {
15
20
  }
16
21
 
17
22
  @Extend(TextArea)
18
- function textAttr(attr: TaroTextStyleType) {
23
+ function textAttr(attr: TextareaAttrs) {
19
24
  .textAlign(attr.textAlign)
20
25
  .maxLines(attr.WebkitLineClamp)
26
+ .defaultFocus(attr.autoFocus)
27
+ .enabled(!attr.disabled)
28
+ }
29
+
30
+ function getAttributes(node: TaroTextAreaElement): TextareaAttrs {
31
+ const attrs: TaroAny = getFontAttributes(node)
32
+ attrs.autoFocus = node._attrs.autoFocus || node._attrs.focus || false
33
+ attrs.disabled = node._attrs.disabled || false
34
+ return attrs
21
35
  }
22
36
 
23
37
  function getPlaceholderColor (node: TaroTextAreaElement): string {
@@ -30,7 +44,10 @@ function getPlaceholderColor (node: TaroTextAreaElement): string {
30
44
  export default struct TaroTextArea {
31
45
  @State value: string = ''
32
46
 
47
+ @Builder customBuilder() {}
48
+ @BuilderParam createLazyChildren: (node: TaroTextAreaElement, layer?: number) => void = this.customBuilder
33
49
  @ObjectLink node: TaroTextAreaElement
50
+ @State overwriteStyle: Record<string, TaroAny> = {}
34
51
 
35
52
  aboutToAppear () {
36
53
  if (this.node) {
@@ -45,37 +62,35 @@ export default struct TaroTextArea {
45
62
  }
46
63
 
47
64
  build () {
48
- if (this.node) {
49
- TextArea({ text: this.value, placeholder: this.node._attrs?.placeholder || '', controller: this.node.controller })
50
- .key(this.node._nid)
51
- .maxLength(Number(this.node._attrs?.maxlength) || null)
52
- .placeholderColor(getPlaceholderColor(this.node))
53
- .attributeModifier(commonStyleModify.setNode(this.node))
54
- .textStyle(getNormalAttributes(this.node))
55
- .textAttr(getFontAttributes(this.node))
56
- .onChange((value: string) => {
57
- const event: TaroEvent = createTaroEvent('input', { detail: { value } }, this.node)
58
-
59
- this.value = value
60
- this.node?.updateFormWidgetValue(value)
61
- eventHandler(event, 'input', this.node)
62
- })
63
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
64
- .onBlur(() => {
65
- const event: TaroEvent = createTaroEvent('blur', { detail: { value: this.value } }, this.node)
66
- eventHandler(event, 'blur', this.node)
67
- })
68
- .onFocus(() => {
69
- const event: TaroEvent = createTaroEvent('focus', { detail: { value: this.value, height: this.node?._height } }, this.node)
70
-
71
- eventHandler(event, 'focus', this.node)
72
- })
73
- .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
74
- if (this.node) {
75
- this.node._nodeInfo.areaInfo = res[1]
76
- }
77
- }))
78
- .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
79
- }
65
+ TextArea({ text: this.value, placeholder: this.node._attrs?.placeholder || '', controller: this.node.controller })
66
+ .key(this.node._nid.toString())
67
+ .maxLength(Number(this.node._attrs?.maxlength) || null)
68
+ .placeholderColor(getPlaceholderColor(this.node))
69
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
70
+ .textStyle(this.node?.hmStyle)
71
+ .textAttr(getAttributes(this.node))
72
+ .onChange((value: string) => {
73
+ const event: TaroEvent = createTaroEvent('input', { detail: { value } }, this.node)
74
+
75
+ this.value = value
76
+ this.node?.updateFormWidgetValue(value)
77
+ eventHandler(event, 'input', this.node)
78
+ })
79
+ .onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', this.node) }, this.node, ['click']))
80
+ .onBlur(() => {
81
+ const event: TaroEvent = createTaroEvent('blur', { detail: { value: this.value } }, this.node)
82
+ eventHandler(event, 'blur', this.node)
83
+ })
84
+ .onFocus(() => {
85
+ const event: TaroEvent = createTaroEvent('focus', { detail: { value: this.value, height: this.node?._height } }, this.node)
86
+
87
+ eventHandler(event, 'focus', this.node)
88
+ })
89
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
90
+ if (this.node) {
91
+ this.node._nodeInfo.areaInfo = res[1]
92
+ }
93
+ }))
94
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
80
95
  }
81
96
  }
@@ -60,7 +60,7 @@ class AttributeManager {
60
60
  const dataValue: string = AttributeManager.getNodeStyle(style, 'animation')
61
61
 
62
62
  if (dataValue) {
63
- let values: string[] = dataValue.trim().split(new RegExp("/\s+/"))
63
+ let values: string[] = dataValue.toString().trim().split(new RegExp("/\s+/"))
64
64
  switch (values.length) {
65
65
  case 4:
66
66
  res = { duration: values[0], curve: values[1], delay: values[2] }
@@ -140,7 +140,7 @@ class AttributeManager {
140
140
  }
141
141
  let resultTransform: matrix4.Matrix4Transit
142
142
 
143
- const matches = transform.match(new RegExp("/(\w+)\(([^)]+)\)/g")) || [];
143
+ const matches: string[] = transform.match(new RegExp("/(\w+)\(([^)]+)\)/g")) || [];
144
144
 
145
145
  // 处理matrix
146
146
 
@@ -11,7 +11,7 @@ export class DynamicCenter {
11
11
  if (!node._isCompileMode || !node._instance) return
12
12
 
13
13
  if (node._attrs?._dynamicID) {
14
- node._instance[node._attrs._dynamicID] = null
14
+ node._instance[node._attrs._dynamicID] = new TaroElement('Ignore')
15
15
  }
16
16
  node._instance = null
17
17
  }
@@ -36,4 +36,4 @@ export class DynamicCenter {
36
36
  this.bindComponentToNodeWithDFS(node.childNodes[i] as TaroElement, component)
37
37
  }
38
38
  }
39
- }
39
+ }
@@ -1,20 +1,20 @@
1
- import type { TaroElement } from '@tarojs/runtime'
1
+ import type { TaroElement, HarmonyStyle } from '@tarojs/runtime'
2
2
  import { isUndefined } from '@tarojs/shared'
3
+ import { getNormalAttributes } from './styles'
3
4
 
4
5
  interface IFlexOptions {
5
6
  direction: FlexDirection,
6
7
  justifyContent: FlexAlign,
7
- alignItems: VerticalAlign | HorizontalAlign,
8
- // Row 和 Column 不支持下面两个属性
9
- // wrap: FlexWrap,
10
- // alignContent: FlexAlignContent
8
+ alignItems: ItemAlign,
9
+ wrap?: FlexWrap,
10
+ alignContent?: FlexAlign
11
11
  }
12
12
 
13
13
  class FlexManager {
14
14
  static isFlexNode (node: TaroElement): boolean {
15
15
  return !!node.hmStyle?.display?.includes('flex')
16
16
  }
17
-
17
+
18
18
  static convertFlexAlignItemsToColumnOrRow (direction: FlexDirection, alignItems: ItemAlign | undefined): VerticalAlign | HorizontalAlign {
19
19
  if (direction === FlexDirection.Column) {
20
20
  switch (alignItems) {
@@ -37,23 +37,53 @@ class FlexManager {
37
37
  }
38
38
  }
39
39
 
40
+ static useFlexLayout (node: TaroElement): boolean {
41
+ const hmStyle: HarmonyStyle = getNormalAttributes(node) || {}
42
+ const isReverse = hmStyle.flexDirection && [FlexDirection.RowReverse, FlexDirection.ColumnReverse].indexOf(hmStyle.flexDirection) !== -1;
43
+ const isUnknownAlign = [ItemAlign.Stretch, ItemAlign.Baseline].indexOf(hmStyle.alignItems!) !== -1;
44
+ return !isUndefined(hmStyle.flexWrap) || isReverse || isUnknownAlign;
45
+ }
46
+
40
47
  static flexOptions (node: TaroElement): IFlexOptions {
41
- const hmStyle = node.hmStyle
48
+ const hmStyle: HarmonyStyle = getNormalAttributes(node) || {}
42
49
  const isFlex = FlexManager.isFlexNode(node)
43
- const justifyContent: FlexAlign = isFlex ? (isUndefined(hmStyle.justifyContent) ? FlexAlign.Start : hmStyle.justifyContent) : FlexAlign.Start
44
-
45
50
  let flexDirection = hmStyle.flexDirection
46
51
  if (!flexDirection && flexDirection !== 0) {
47
52
  flexDirection = hmStyle.display === 'flex' ? FlexDirection.Row : FlexDirection.Column
48
53
  }
49
54
 
50
- const alignItems = isFlex ? FlexManager.convertFlexAlignItemsToColumnOrRow(flexDirection, hmStyle.alignItems) : HorizontalAlign.Start
51
-
52
55
  return {
53
- alignItems,
54
- justifyContent,
56
+ alignItems: isFlex ? (isUndefined(hmStyle.alignItems) ? ItemAlign.Start : hmStyle.alignItems) : ItemAlign.Start,
57
+ justifyContent: isFlex ? (isUndefined(hmStyle.justifyContent) ? FlexAlign.Start : hmStyle.justifyContent) : FlexAlign.Start,
55
58
  direction: flexDirection,
59
+ wrap: isFlex ? hmStyle.flexWrap: FlexWrap.NoWrap,
60
+ alignContent: isFlex ? hmStyle.alignContent: FlexAlign.Start
61
+ }
62
+ }
63
+
64
+ static direction (node: TaroElement): FlexDirection {
65
+ const hmStyle: HarmonyStyle = getNormalAttributes(node)
66
+ let flexDirection = hmStyle.flexDirection
67
+ if (!flexDirection && flexDirection !== 0) {
68
+ flexDirection = hmStyle.display === 'flex' ? FlexDirection.Row : FlexDirection.Column
56
69
  }
70
+ return flexDirection
71
+ }
72
+
73
+ static alignItems<T> (node: TaroElement): T {
74
+ const hmStyle: HarmonyStyle = getNormalAttributes(node)
75
+ const isFlex = FlexManager.isFlexNode(node)
76
+ let flexDirection = hmStyle.flexDirection
77
+ if (!flexDirection && flexDirection !== 0) {
78
+ flexDirection = hmStyle.display === 'flex' ? FlexDirection.Row : FlexDirection.Column
79
+ }
80
+ return (isFlex ? FlexManager.convertFlexAlignItemsToColumnOrRow(flexDirection, hmStyle.alignItems) : HorizontalAlign.Start) as T
81
+ }
82
+
83
+ static justifyContent (node: TaroElement): FlexAlign {
84
+ const hmStyle: HarmonyStyle = getNormalAttributes(node)
85
+ const isFlex = FlexManager.isFlexNode(node)
86
+ return isFlex ? (isUndefined(hmStyle.justifyContent) ? FlexAlign.Start : hmStyle.justifyContent) : FlexAlign.Start
57
87
  }
58
88
  }
59
89
 
@@ -1,7 +1,8 @@
1
- import { getNormalAttributes, getStyle, getFontAttributes } from './styles'
1
+ import { VIEW } from '@tarojs/runtime'
2
2
 
3
- import type { TFunc } from '@tarojs/runtime/dist/runtime.esm'
4
- import type { TaroElement } from '@tarojs/runtime'
3
+ import { getNormalAttributes, getFontAttributes, getStyleAttr } from './styles'
4
+
5
+ import type { TaroAny, TaroElement, TaroNode } from '@tarojs/runtime'
5
6
 
6
7
  export const parseStyles = (styles = ''): Record<string, string> => {
7
8
  const styleObj: Record<string, string> = {}
@@ -9,7 +10,7 @@ export const parseStyles = (styles = ''): Record<string, string> => {
9
10
  .split(';')
10
11
  .filter((style) => style.split(':').length === 2)
11
12
  .map((style) => [
12
- style.split(':')[0].trim().replace(new RegExp("/-./g"), c => c.substring(1).toUpperCase()),
13
+ style.split(':')[0].trim().replace(new RegExp("-([a-z])", "g"), (_, letter: string): string => letter.toUpperCase()),
13
14
  style.split(':')[1].trim()
14
15
  ])
15
16
  .forEach((style) => {
@@ -20,7 +21,7 @@ export const parseStyles = (styles = ''): Record<string, string> => {
20
21
  return styleObj
21
22
  }
22
23
 
23
- export function shouldBindEvent (cb: TFunc, node: TaroElement | null, eventNames: string[], disabled = false) {
24
+ export function shouldBindEvent (cb: TaroAny, node: TaroElement | null, eventNames: string[], disabled = false): TaroAny {
24
25
  if (!node || node._attrs?.disabled || disabled) return null
25
26
  if (!node.__listeners) {
26
27
  return null
@@ -31,9 +32,20 @@ export function shouldBindEvent (cb: TFunc, node: TaroElement | null, eventNames
31
32
  }
32
33
 
33
34
  export function getNodeThresholds (node: TaroElement): number[] | null {
34
- if (!node) return null
35
+ return node?._nodeInfo?.thresholds || null
36
+ }
35
37
 
36
- return node?._nodeInfo.thresholds || null
38
+ export function isTagFirstChild (node: TaroElement, tagName = VIEW, level = 0): boolean {
39
+ const parent: TaroElement | null = node.parentElement
40
+ const list: TaroNode[] = node.parentNode?.childNodes || []
41
+ if (list.length < 1 || level < 0) return false
42
+ else if (!parent) return true
43
+
44
+ if (parent.nodeName === tagName.toUpperCase()) {
45
+ return list[0] === node
46
+ } else {
47
+ return (list[0] === node) && isTagFirstChild(parent, tagName, --level)
48
+ }
37
49
  }
38
50
 
39
- export { getNormalAttributes, getStyle, getFontAttributes }
51
+ export { getNormalAttributes, getFontAttributes, getStyleAttr }
@@ -99,5 +99,4 @@ function parseTag(htmlString, startIndex) {
99
99
  return tag
100
100
  }
101
101
 
102
-
103
- export default parseHTML
102
+ export default parseHTML
@@ -15,7 +15,7 @@ function buildDomTree(dom: TTreeNode) {
15
15
  case 'span': tagName = 'text'; break
16
16
  }
17
17
  if (!tagName) return null
18
-
18
+
19
19
  const ele = document.createElement(tagName)
20
20
  attributes && Object.keys(attributes).forEach(key => {
21
21
  if (key === 'style') {
@@ -1,5 +1,8 @@
1
1
  import { convertNumber2VP } from '@tarojs/runtime'
2
- import { isNumber } from '@tarojs/shared'
2
+ import { isNumber, isUndefined } from '@tarojs/shared'
3
+
4
+ import type { RichTextProps } from '@tarojs/components/types/RichText'
5
+ import type { TaroRichTextElement } from '@tarojs/runtime'
3
6
 
4
7
  export function getSingleSelector(range, rangeKey): any[] {
5
8
  return range.map((data) => data[rangeKey])
@@ -18,66 +21,67 @@ export function getMultiSelector(ctx, range, rangeKey, value) {
18
21
  }))
19
22
  }
20
23
 
21
- export function getUnit (val) {
22
- if (/\d+(vp)$/.test(val)) {
24
+ export function getUnit (val: string | number): string {
25
+ if (isNumber(val) || /\d+px$/.test(val)) {
26
+ return convertNumber2VP(parseFloat(val as string))
27
+ } else if (/\d+(vp)$/.test(val)) {
23
28
  return val
24
- } else if (isNumber(val) || /\d+px$/.test(val)) {
25
- return convertNumber2VP(parseFloat(val))
26
29
  }
27
30
  return val
28
31
  }
29
32
 
30
- function handleNodeStyleData (dataValue: string, handler: (values: string[]) => { [key: string]: string } | void) {
31
- let res: any = {}
32
- if (dataValue) {
33
- const values = dataValue.trim().split(/\s+/)
34
- const data = handler(values)
35
-
36
- if (!data) return res
37
-
38
- res = data
33
+ export function generateText (node: TaroRichTextElement): string {
34
+ return parseHtmlNode(node._attrs.nodes || '')
35
+ }
39
36
 
40
- Object.keys(res).forEach(key => {
41
- const exec = `${res[key]}`.match(/(\d+)(px)$/)
42
- if (exec && values.length > 1) {
43
- res[key] = getUnit(+exec[1])
44
- }
45
- })
37
+ // 将nodeTree转换成harmony需要的string结构
38
+ function nodeToHtml(node: RichTextProps.Text | RichTextProps.HTMLElement): string {
39
+ if (node.type === 'text') {
40
+ return node.text
41
+ }
42
+ if (node.attrs) {
43
+ const attributes = Object.entries(node.attrs)
44
+ .map((item: [string, string]) => `${item[0]}="${item[1]}"`)
45
+ .join(' ')
46
+ const childrenHtml: string = typeof node.children === 'string' ? node.children : (node.children || []).map((child: RichTextProps.Text | RichTextProps.HTMLElement) => nodeToHtml(child)).join('')
47
+ return `<${node.name}${attributes ? ' ' + attributes : ''}>${childrenHtml}</${node.name}>`
46
48
  }
49
+ return ''
50
+ }
47
51
 
48
- return res
52
+ function parseHtmlNode (nodes: Array<RichTextProps.Text | RichTextProps.HTMLElement> | string) {
53
+ return typeof nodes === 'string' ? nodes : `<div>${nodes.map(node => nodeToHtml(node)).join('')}</div>`
49
54
  }
50
55
 
51
- export function getNodeBorderRadiusData (dataValue: string) {
52
- return handleNodeStyleData(dataValue, values => {
53
- switch (values.length) {
54
- case 1:
55
- return { topLeft: values[0], topRight: values[0], bottomRight: values[0], bottomLeft: values[0] }
56
- case 2:
57
- return { topLeft: values[0], topRight: values[1], bottomRight: values[0], bottomLeft: values[1] }
58
- case 3:
59
- return { topLeft: values[0], topRight: values[1], bottomRight: values[2], bottomLeft: values[1] }
60
- case 4:
61
- return { topLeft: values[0], topRight: values[1], bottomRight: values[2], bottomLeft: values[3] }
62
- default:
63
- break
56
+ // 背景偏移算法:https://developer.mozilla.org/zh-CN/docs/Web/CSS/background-position
57
+ export function computeBackgroundPosition(style) {
58
+ let offsetX = style.backgroundPosition?.x || 0
59
+ let offsetY = style.backgroundPosition?.y || 0
60
+ if (style.backgroundSize && typeof style.backgroundSize !== 'number') {
61
+ if (!isUndefined(style.backgroundSize.width) && style.width) {
62
+ if (typeof style.backgroundPosition.x === 'string' && style.backgroundPosition.x.indexOf('%') > 0) {
63
+ // (container width - image width) * (position x%) = (x offset value)
64
+ const width = parseFloat(style.width)
65
+ const bgWidth = parseFloat(style.backgroundSize.width)
66
+ const bgOffsetX = parseFloat(style.backgroundPosition.x)
67
+ offsetX = Number((width - bgWidth) * (bgOffsetX) / 100) || 0
68
+ }
69
+ }
70
+ if (!isUndefined(style.backgroundSize.height) && style.height) {
71
+ if (typeof style.backgroundPosition.y === 'string' && style.backgroundPosition.y.indexOf('%') > 0) {
72
+ // (container height - image height) * (position y%) = (y offset value)
73
+ const height = parseFloat(style.height)
74
+ const bgHeight = parseFloat(style.backgroundSize.height)
75
+ const bgOffsetY = parseFloat(style.backgroundPosition.y)
76
+ offsetY = Number((height - bgHeight) * (bgOffsetY) / 100) || 0
77
+ }
64
78
  }
65
- })
79
+ }
80
+
81
+ return { offsetX, offsetY }
66
82
  }
67
83
 
68
- export function getNodeMarginOrPaddingData (dataValue: string) {
69
- return handleNodeStyleData(dataValue, values => {
70
- switch (values.length) {
71
- case 1:
72
- return { top: values[0], right: values[0], bottom: values[0], left: values[0] }
73
- case 2:
74
- return { top: values[0], right: values[1], bottom: values[0], left: values[1] }
75
- case 3:
76
- return { top: values[0], right: values[1], bottom: values[2], left: values[1] }
77
- case 4:
78
- return { top: values[0], right: values[1], bottom: values[2], left: values[3] }
79
- default:
80
- break
81
- }
82
- })
84
+ export function convertVp2Px(val: string | number) {
85
+ const vp = parseFloat(`${val}`)
86
+ return vp2px(vp)
83
87
  }