@tarojs/plugin-platform-harmony-ets 4.0.0-beta.4 → 4.0.0-beta.41

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 (107) hide show
  1. package/dist/apis/base/system.ts +53 -20
  2. package/dist/apis/canvas/index.ts +10 -1
  3. package/dist/apis/framework/index.ts +1 -5
  4. package/dist/apis/index.ts +32 -17
  5. package/dist/apis/network/request.ts +5 -5
  6. package/dist/apis/route/index.ts +15 -0
  7. package/dist/apis/storage/index.ts +126 -68
  8. package/dist/apis/ui/animation/animation.ts +2 -1
  9. package/dist/apis/utils/index.ts +1 -1
  10. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  11. package/dist/apis/wxml/index.ts +2 -0
  12. package/dist/apis/wxml/selectorQuery.ts +18 -9
  13. package/dist/components-harmony-ets/button.ets +48 -34
  14. package/dist/components-harmony-ets/canvas.ets +51 -0
  15. package/dist/components-harmony-ets/checkbox.ets +69 -61
  16. package/dist/components-harmony-ets/form.ets +51 -29
  17. package/dist/components-harmony-ets/icon.ets +34 -19
  18. package/dist/components-harmony-ets/image.ets +27 -14
  19. package/dist/components-harmony-ets/index.ets +76 -0
  20. package/dist/components-harmony-ets/innerHtml.ets +11 -6
  21. package/dist/components-harmony-ets/input.ets +41 -40
  22. package/dist/components-harmony-ets/label.ets +71 -42
  23. package/dist/components-harmony-ets/movableArea.ets +126 -0
  24. package/dist/components-harmony-ets/movableView.ets +73 -0
  25. package/dist/components-harmony-ets/picker.ets +42 -38
  26. package/dist/components-harmony-ets/progress.ets +52 -0
  27. package/dist/components-harmony-ets/pseudo.ets +80 -0
  28. package/dist/components-harmony-ets/radio.ets +71 -64
  29. package/dist/components-harmony-ets/richText.ets +14 -30
  30. package/dist/components-harmony-ets/scrollView.ets +64 -30
  31. package/dist/components-harmony-ets/slider.ets +15 -14
  32. package/dist/components-harmony-ets/style.ets +346 -130
  33. package/dist/components-harmony-ets/swiper.ets +38 -20
  34. package/dist/components-harmony-ets/switch.ets +30 -28
  35. package/dist/components-harmony-ets/text.ets +121 -51
  36. package/dist/components-harmony-ets/textArea.ets +35 -34
  37. package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
  38. package/dist/components-harmony-ets/utils/DynamicCenter.ts +1 -1
  39. package/dist/components-harmony-ets/utils/flexManager.ets +43 -19
  40. package/dist/components-harmony-ets/utils/helper.ets +4 -5
  41. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  42. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  43. package/dist/components-harmony-ets/utils/index.ts +50 -51
  44. package/dist/components-harmony-ets/utils/styles.ets +164 -92
  45. package/dist/components-harmony-ets/video.ets +34 -20
  46. package/dist/components-harmony-ets/view.ets +62 -29
  47. package/dist/components-harmony-ets/webView.ets +40 -34
  48. package/dist/index.d.ts +152 -0
  49. package/dist/index.js +74 -37
  50. package/dist/index.js.map +1 -1
  51. package/dist/runtime-ets/bom/document.ts +1 -1
  52. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
  53. package/dist/runtime-ets/bom/window.ts +7 -0
  54. package/dist/runtime-ets/current.ts +3 -0
  55. package/dist/runtime-ets/dom/bind.ts +20 -6
  56. package/dist/runtime-ets/dom/cssNesting.ts +393 -0
  57. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +12 -40
  58. package/dist/runtime-ets/dom/document.ts +23 -8
  59. package/dist/runtime-ets/dom/element/canvas.ts +136 -0
  60. package/dist/runtime-ets/dom/element/element.ts +218 -51
  61. package/dist/runtime-ets/dom/element/form.ts +15 -18
  62. package/dist/runtime-ets/dom/element/index.ts +18 -2
  63. package/dist/runtime-ets/dom/element/movableArea.ts +12 -0
  64. package/dist/runtime-ets/dom/element/movableView.ts +193 -0
  65. package/dist/runtime-ets/dom/element/normal.ts +13 -4
  66. package/dist/runtime-ets/dom/element/progress.ts +12 -0
  67. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  68. package/dist/runtime-ets/dom/element/text.ts +1 -8
  69. package/dist/runtime-ets/dom/element/video.ts +5 -3
  70. package/dist/runtime-ets/dom/element/webView.ts +8 -0
  71. package/dist/runtime-ets/dom/event.ts +0 -1
  72. package/dist/runtime-ets/dom/eventTarget.ts +0 -3
  73. package/dist/runtime-ets/dom/node.ts +45 -27
  74. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +330 -230
  75. package/dist/runtime-ets/dom/stylesheet/index.ts +28 -308
  76. package/dist/runtime-ets/dom/stylesheet/type.ts +28 -9
  77. package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
  78. package/dist/runtime-ets/index.ts +2 -2
  79. package/dist/runtime-ets/interface/event.ts +1 -1
  80. package/dist/runtime-ets/utils/index.ts +43 -10
  81. package/dist/runtime-ets/utils/info.ts +1 -1
  82. package/dist/runtime-framework/react/app.ts +7 -2
  83. package/dist/runtime-framework/react/index.ts +0 -2
  84. package/dist/runtime-framework/react/native-page.ts +22 -12
  85. package/dist/runtime-framework/react/page.ts +3 -8
  86. package/dist/runtime-framework/solid/app.ts +25 -45
  87. package/dist/runtime-framework/solid/connect.ts +21 -3
  88. package/dist/runtime-framework/solid/hooks.ts +16 -11
  89. package/dist/runtime-framework/solid/index.ts +6 -2
  90. package/dist/runtime-framework/solid/page.ts +84 -30
  91. package/dist/runtime-framework/solid/reconciler/props.ts +65 -20
  92. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  93. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  94. package/dist/runtime-framework/solid/utils/index.ts +0 -2
  95. package/dist/runtime-utils.d.ts +827 -0
  96. package/dist/runtime-utils.js +284 -126
  97. package/dist/runtime-utils.js.map +1 -1
  98. package/dist/runtime.d.ts +1 -0
  99. package/dist/runtime.js +284 -126
  100. package/dist/runtime.js.map +1 -1
  101. package/index.js +3 -1
  102. package/package.json +13 -13
  103. package/types/harmony.d.ts +4 -0
  104. package/types/index.d.ts +4 -0
  105. package/dist/runtime-ets/utils/bind.ts +0 -24
  106. /package/dist/components-harmony-ets/{index.ts → tag.ts} +0 -0
  107. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
@@ -1,125 +1,197 @@
1
1
  import { isUndefined } from '@tarojs/shared'
2
2
  import { ObjectAssign } from '@tarojs/runtime'
3
3
 
4
- import { FlexManager } from './FlexManager'
5
- import { TEXT_DEFAULT_STYLE } from './constant/style'
4
+ import { FlexManager } from './flexManager'
6
5
 
7
6
  import type { StandardProps, TextProps } from '@tarojs/components/types'
8
- import type { TaroAny, TaroElement, TaroStyleType, TaroTextStyleType, HarmonyType, HarmonyStyle } from '@tarojs/runtime'
7
+ import type { TaroAny, TaroElement, TaroStyleType, TaroTextStyleType, HarmonyStyle } from '@tarojs/runtime'
9
8
 
10
9
  export function getFontAttributes (node: TaroElement): TaroTextStyleType {
11
- const hmStyle = node.hmStyle
10
+ let hmStyle = getNormalAttributes(node)
12
11
  const attrs: TextProps = node._attrs || {}
13
12
 
13
+ if (!hmStyle) return {}
14
+
15
+ let lineHeight = hmStyle.lineHeight
16
+ if (!isUndefined(hmStyle.verticalAlign)) {
17
+ lineHeight = 0
18
+ }
19
+
20
+ let WebkitLineClamp = attrs.maxLines || hmStyle.WebkitLineClamp || Infinity
21
+ if (hmStyle.textOverflow && !isUndefined(hmStyle.textOverflow.overflow)) {
22
+ switch (hmStyle.textOverflow.overflow) {
23
+ case TextOverflow.Clip:
24
+ case TextOverflow.Ellipsis:
25
+ case TextOverflow.None: WebkitLineClamp = WebkitLineClamp || 1; break
26
+ default: break
27
+ }
28
+ }
29
+
30
+ const isFlexText = hmStyle.display === 'flex'
31
+ let textAlign = hmStyle.textAlign
32
+ let verticalAlign = hmStyle.verticalAlign
33
+
34
+ // 按照 w3c 规范,一旦设置了 display: flex,textAlign 和 verticalAlign 都会直接失效
35
+ // 需要使用 justifyContent 和 alignItems
36
+ if (isFlexText) {
37
+ switch (hmStyle.justifyContent) {
38
+ case FlexAlign.Start:
39
+ textAlign = TextAlign.Start
40
+ break
41
+ case FlexAlign.Center:
42
+ textAlign = TextAlign.Center
43
+ break
44
+ case FlexAlign.End:
45
+ textAlign = TextAlign.End
46
+ break
47
+ case FlexAlign.SpaceBetween:
48
+ case FlexAlign.SpaceAround:
49
+ textAlign = TextAlign.JUSTIFY
50
+ break
51
+ default:
52
+ textAlign = TextAlign.Start
53
+ break
54
+ }
55
+ switch (hmStyle.alignItems) {
56
+ case ItemAlign.Start:
57
+ verticalAlign = Alignment.Top
58
+ break
59
+ case ItemAlign.Center:
60
+ verticalAlign = Alignment.Center
61
+ break
62
+ case ItemAlign.End:
63
+ verticalAlign = Alignment.End
64
+ break
65
+ default:
66
+ verticalAlign = Alignment.Top
67
+ break
68
+ }
69
+ }
70
+
14
71
  const attributes: TaroAny = {
15
- WebkitLineClamp: attrs.maxLines || hmStyle.WebkitLineClamp || Infinity,
72
+ textAlign,
73
+ verticalAlign,
74
+ WebkitLineClamp: WebkitLineClamp,
16
75
  // 已做处理的属性
17
76
  letterSpacing: hmStyle.letterSpacing,
18
- textAlign: hmStyle.textAlign,
19
- textOverflow: hmStyle.textOverflow
77
+ textOverflow: hmStyle.textOverflow,
78
+ lineHeight: lineHeight
20
79
  }
21
80
 
22
81
  return attributes
23
82
  }
24
83
 
25
84
  // 模拟 div 自动撑满父元素的情况
26
- function isMaxWidthView (node: TaroElement) {
85
+ export function isMaxWidthView (node: TaroElement) {
27
86
  const parentNode: TaroElement = node.parentNode as TaroElement
28
-
29
- return node.tagName === 'VIEW' && parentNode && parentNode.tagName === 'VIEW' &&
30
- !(FlexManager.isFlexNode(parentNode) && FlexManager.flexOptions(parentNode).direction !== FlexDirection.Column)
87
+
88
+ return node.tagName === 'VIEW' && parentNode && parentNode.tagName === 'VIEW' && !FlexManager.isFlexNode(parentNode)
31
89
  }
32
90
 
33
- export function getNormalAttributes (node: TaroElement): TaroStyleType {
91
+ export function getNormalAttributes (node: TaroElement, initStyle?: HarmonyStyle): HarmonyStyle {
34
92
  const hmStyle = node.hmStyle
93
+
94
+ if (!hmStyle) return {}
35
95
 
36
96
  const _nid = node._nid
37
97
  const _attrs: StandardProps = node._attrs || {}
38
98
 
39
- let linearGradient: HarmonyType.LinearGradient | undefined = undefined
40
- // 渐变
41
- if (hmStyle.backgroundImage?.colors) {
42
- linearGradient = hmStyle.backgroundImage
43
- }
99
+ let normalAttributes = hmStyle
100
+
101
+ // 覆盖属性
102
+ normalAttributes.id = _attrs.id || _nid
44
103
 
45
- let normalAttributes: HarmonyStyle = {
46
- // Flex相关
47
- flexBasis: hmStyle.flexBasis,
48
- flexGrow: hmStyle.flexGrow,
49
- flexShrink: hmStyle.flexShrink,
50
- alignSelf: hmStyle.alignSelf,
51
- // 尺寸相关
52
- width: isMaxWidthView(node) && isUndefined(hmStyle.width) ? '100%' : hmStyle.width,
53
- height: hmStyle.height,
54
- minHeight: hmStyle.minHeight,
55
- maxHeight: hmStyle.maxHeight,
56
- minWidth: hmStyle.minWidth,
57
- maxWidth: hmStyle.maxWidth,
58
- marginTop: hmStyle.marginTop,
59
- marginRight: hmStyle.marginRight,
60
- marginBottom: hmStyle.marginBottom,
61
- marginLeft: hmStyle.marginLeft,
62
- paddingTop: hmStyle.paddingTop,
63
- paddingRight: hmStyle.paddingRight,
64
- paddingBottom: hmStyle.paddingBottom,
65
- paddingLeft: hmStyle.paddingLeft,
66
- // 边框相关
67
- borderStyle: hmStyle.borderStyle,
68
- borderTopStyle: hmStyle.borderTopStyle,
69
- borderRightStyle: hmStyle.borderRightStyle,
70
- borderBottomStyle: hmStyle.borderBottomStyle,
71
- borderLeftStyle: hmStyle.borderLeftStyle,
72
- borderWidth: hmStyle.borderWidth,
73
- borderTopWidth: hmStyle.borderTopWidth,
74
- borderRightWidth: hmStyle.borderRightWidth,
75
- borderBottomWidth: hmStyle.borderBottomWidth,
76
- borderLeftWidth: hmStyle.borderLeftWidth,
77
- borderColor: hmStyle.borderColor,
78
- borderTopColor: hmStyle.borderTopColor,
79
- borderRightColor: hmStyle.borderRightColor,
80
- borderBottomColor: hmStyle.borderBottomColor,
81
- borderLeftColor: hmStyle.borderLeftColor,
82
- borderRadius: hmStyle.borderRadius,
83
- borderTopLeftRadius: hmStyle.borderTopLeftRadius,
84
- borderTopRightRadius: hmStyle.borderTopRightRadius,
85
- borderBottomRightRadius: hmStyle.borderBottomRightRadius,
86
- borderBottomLeftRadius: hmStyle.borderBottomLeftRadius,
87
- // 背景相关
88
- backgroundColor: hmStyle.backgroundColor,
89
- backgroundImage: hmStyle.backgroundImage,
90
- backgroundSize: hmStyle.backgroundSize,
91
- backgroundRepeat: hmStyle.backgroundRepeat,
92
- backgroundPosition: hmStyle.backgroundPosition,
93
- linearGradient,
94
- // 变换相关
95
- transform: hmStyle.transform,
96
- transformOrigin: {
97
- x: hmStyle.transformOrigin?.x || 0,
98
- y: hmStyle.transformOrigin?.y || 0
99
- },
100
- // 通用文本相关
101
- color: hmStyle.color,
102
- fontSize: hmStyle.fontSize,
103
- fontStyle: hmStyle.fontStyle,
104
- fontWeight: hmStyle.fontWeight,
105
- fontFamily: hmStyle.fontFamily || TEXT_DEFAULT_STYLE.FONT_FAMILY,
106
- lineHeight: hmStyle.lineHeight,
107
- textDecoration: hmStyle.textDecoration,
108
- // 其他
109
- overflow: hmStyle.overflow,
110
- id: _attrs.id || _nid,
111
- opacity: hmStyle.opacity,
112
- // focus: _attrs.focus || false,
104
+ let pseudoStylesheet = getPseudoClass(node)
105
+ if (pseudoStylesheet) {
106
+ normalAttributes = ObjectAssign({}, normalAttributes, pseudoStylesheet)
113
107
  }
114
108
 
115
- // taro_page 等写死在运行时里的节点,没有 _nodeInfo
116
- if (node._nodeInfo) {
117
- const overwriteStyle: TaroStyleType = node._nodeInfo?.overwriteStyle
109
+ // 初始化默认的值
110
+ if (initStyle) {
111
+ normalAttributes = ObjectAssign({}, initStyle, normalAttributes)
112
+ }
113
+ return normalAttributes
114
+ }
118
115
 
119
- // 处理覆盖属性:如动画的覆盖
120
- if (overwriteStyle) {
121
- normalAttributes = ObjectAssign(normalAttributes, overwriteStyle)
116
+ // 应用伪类样式
117
+ function getPseudoClass (node: TaroElement): HarmonyStyle | null {
118
+ // 伪类
119
+ const _pseudo_class = Object.keys(node._pseudo_class)
120
+ if (_pseudo_class.length) {
121
+ for (let i = 0; i < _pseudo_class.length; i++) {
122
+ const pseudoKey = _pseudo_class[i]
123
+ const pseudoStylesheet = node._pseudo_class[pseudoKey]
124
+ if (!pseudoStylesheet) continue
125
+ switch(pseudoKey) {
126
+ case "::first-child": {
127
+ if (node.parentNode?.firstChild?._nid === node._nid) {
128
+ return pseudoStylesheet.hmStyle
129
+ }
130
+ break
131
+ }
132
+ case "::last-child": {
133
+ if (node.parentNode?.lastChild?._nid === node._nid) {
134
+ return pseudoStylesheet.hmStyle
135
+ }
136
+ break
137
+ }
138
+ default: {
139
+ // 解析nth-child()
140
+ // 找出当前节点在父节点中的位置
141
+ // 公式
142
+ let matchs: [number, number] | null = null
143
+ if (pseudoKey === '::nth-child(odd)') {
144
+ matchs = [2, 1]
145
+ } else if (pseudoKey === '::nth-child(even)') {
146
+ matchs = [2, 0]
147
+ } else {
148
+ matchs = parseNthChild(pseudoKey)
149
+ }
150
+ if (matchs) {
151
+ let index = node.parentNode?.childNodes.findIndex((child) => child._nid === node._nid)
152
+ if (isUndefined(index)) return null
153
+ else {
154
+ index = index + 1
155
+ if (matchs[0] === 0) {
156
+ if (index === matchs[1]) {
157
+ return pseudoStylesheet.hmStyle
158
+ }
159
+ } else {
160
+ if ((index - matchs[1]) % matchs[0] === 0) {
161
+ return pseudoStylesheet.hmStyle
162
+ }
163
+ }
164
+ }
165
+ }
166
+ }
167
+ }
122
168
  }
123
169
  }
124
- return normalAttributes
170
+ return null
171
+ }
172
+
173
+ // 正则匹配nth-child
174
+ function parseNthChild(selector: string): [number, number] | null {
175
+ const regex = /nth-child\((?:(-?\d*)n\s*)?([+-]?\s*\d+)?\)/;
176
+ const match = selector.match(regex);
177
+
178
+ if (match) {
179
+ const a = match[1] ? parseInt(match[1]) : 0;
180
+ const b = match[2] ? parseInt(match[2]) : 0;
181
+ return [a, b];
182
+ } else {
183
+ return null;
184
+ }
125
185
  }
186
+
187
+
188
+ export function getStyleAttr(node: TaroElement | null, key: string): TaroAny {
189
+ if (!node) return null
190
+ const hmStyle = node.hmStyle
191
+ if (!hmStyle) return null
192
+ // 覆盖属性
193
+ if (key === 'width') {
194
+ return isMaxWidthView(node) && isUndefined(hmStyle.width) ? '100%' : hmStyle.width
195
+ }
196
+ return hmStyle[key]
197
+ }
@@ -73,30 +73,44 @@ function getVideoProps (node: TaroVideoElement): VideoAttrs {
73
73
  }
74
74
 
75
75
  function handleUpdate (node: TaroVideoElement, e: VideoUpdateEvent) {
76
- node._currentTime = e.time
76
+ node._nodeInfo._currentTime = e.time
77
77
 
78
78
  emitEvent(node, 'timeUpdate', { currentTime: e.time})
79
79
  }
80
80
 
81
- @Builder
82
- export default function TaroVideo (node: TaroVideoElement) {
83
- Video(getVideoData(node))
84
- .attributeModifier(commonStyleModify.setNode(node))
85
- .props(getVideoProps(node))
81
+ @Component
82
+ export default struct TaroVideo {
83
+ @Builder customBuilder() {}
84
+ @BuilderParam createLazyChildren: (node: TaroVideoElement) => void = this.customBuilder
85
+ @ObjectLink node: TaroVideoElement
86
+ @State overwriteStyle: Record<string, TaroAny> = {}
87
+
88
+ aboutToAppear(): void {
89
+ if (this.node) {
90
+ this.node._instance = this
91
+ }
92
+ }
93
+
94
+ build () {
95
+ Video(getVideoData(this.node))
96
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
97
+ .props(getVideoProps(this.node))
86
98
  .aspectRatio(4 / 3)
87
- .onStart(shouldBindEvent(() => { emitEvent(node, 'play') }, node, ['play']))
88
- .onPause(shouldBindEvent(() => { emitEvent(node, 'pause') }, node, ['pause']))
89
- .onFinish(shouldBindEvent(() => { emitEvent(node, 'ended') }, node, ['ended']))
90
- .onError(shouldBindEvent(() => { emitEvent(node, 'error') }, node, ['error']))
91
- .onUpdate((e) => { handleUpdate(node, e) })
92
- .onPrepared(shouldBindEvent((e: TaroAny) => { emitEvent(node, 'loadedMetaData', { duration: e.duration }) }, node, ['loadedmetadata']))
93
- .onSeeking(shouldBindEvent((e: TaroAny) => { emitEvent(node, 'seeking', { duration: e.time }) }, node, ['seeking']))
94
- .onSeeked(shouldBindEvent(() => { emitEvent(node, 'seeked') }, node, ['seeked']))
95
- .onFullscreenChange(shouldBindEvent((e: TaroAny) => { emitEvent(node, 'fullScreenChange', { fullScreen: e.fullscreen}) }, node, ['fullscreenchange']))
96
- .onClick((e: ClickEvent) => { eventHandler(e, 'click', node) })
97
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
98
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
99
- node._nodeInfo.areaInfo = res[1]
99
+ .onStart(shouldBindEvent(() => { emitEvent(this.node, 'play') }, this.node, ['play']))
100
+ .onPause(shouldBindEvent(() => { emitEvent(this.node, 'pause') }, this.node, ['pause']))
101
+ .onFinish(shouldBindEvent(() => { emitEvent(this.node, 'ended') }, this.node, ['ended']))
102
+ .onError(shouldBindEvent(() => { emitEvent(this.node, 'error') }, this.node, ['error']))
103
+ .onUpdate((e) => { handleUpdate(this.node, e) })
104
+ .onPrepared(shouldBindEvent((e: TaroAny) => { emitEvent(this.node, 'loadedMetaData', { duration: e.duration }) }, this.node, ['loadedmetadata']))
105
+ .onSeeking(shouldBindEvent((e: TaroAny) => { emitEvent(this.node, 'seeking', { duration: e.time }) }, this.node, ['seeking']))
106
+ .onSeeked(shouldBindEvent(() => { emitEvent(this.node, 'seeked') }, this.node, ['seeked']))
107
+ .onFullscreenChange(shouldBindEvent((e: TaroAny) => { emitEvent(this.node, 'fullScreenChange', { fullScreen: e.fullscreen}) }, this.node, ['fullscreenchange']))
108
+ .onClick((e: ClickEvent) => { eventHandler(e, 'click', this.node) })
109
+ .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
110
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
111
+ this.node._nodeInfo.areaInfo = res[1]
100
112
  }))
101
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
113
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
114
+ }
115
+
102
116
  }
@@ -1,40 +1,73 @@
1
1
  import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME } from '@tarojs/runtime'
2
2
 
3
- import commonStyleModify from './style'
4
- import { createLazyChildren } from './render'
3
+ import commonStyleModify, { rowModify, columnModify } from './style'
4
+ import PseduoChildren from './pseudo'
5
5
  import { TOUCH_EVENT_MAP } from './utils/constant/event'
6
- import { FlexManager } from './utils/FlexManager'
6
+ import { FlexManager } from './utils/flexManager'
7
7
  import { getNodeThresholds, shouldBindEvent } from './utils/helper'
8
8
 
9
9
  import type { TaroViewElement, TaroAny } from '@tarojs/runtime'
10
+ import { isUndefined } from '@tarojs/shared'
10
11
 
11
- @Builder
12
- export default function TaroView (node: TaroViewElement) {
13
- if (FlexManager.isFlexNode(node) && FlexManager.flexOptions(node).direction !== FlexDirection.Column) {
14
- Row() {
15
- createLazyChildren(node)
12
+ @Component
13
+ export default struct TaroView {
14
+ @Builder customBuilder() {}
15
+ @BuilderParam createLazyChildren: (node: TaroViewElement) => void = this.customBuilder
16
+ @ObjectLink node: TaroViewElement
17
+ @State overwriteStyle: Record<string, TaroAny> = {}
18
+
19
+ aboutToAppear(): void {
20
+ if (this.node) {
21
+ this.node._instance = this
16
22
  }
17
- .attributeModifier(commonStyleModify.setNode(node))
18
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
19
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
20
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
21
- node._nodeInfo.areaInfo = res[1]
22
- }))
23
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
24
- .alignItems(FlexManager.flexOptions(node).alignItems as VerticalAlign)
25
- .justifyContent(FlexManager.flexOptions(node).justifyContent)
26
- } else {
27
- Column() {
28
- createLazyChildren(node)
23
+ }
24
+
25
+ build () {
26
+ if (!isUndefined(this.node._st.hmStyle.flexWrap)) {
27
+ Flex(FlexManager.flexOptions(this.node)) {
28
+ if (this.node._pseudo_before || this.node._pseudo_after) {
29
+ PseduoChildren({ node: this.node, createLazyChildren: this.createLazyChildren })
30
+ } else {
31
+ this.createLazyChildren(this.node)
32
+ }
33
+ }
34
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
35
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
36
+ .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
37
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
38
+ this.node._nodeInfo.areaInfo = res[1]
39
+ }))
40
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
41
+ } else if (FlexManager.isFlexNode(this.node) && FlexManager.direction(this.node) !== FlexDirection.Column) {
42
+ Row() {
43
+ if (this.node._pseudo_before || this.node._pseudo_after) {
44
+ PseduoChildren({ node: this.node, createLazyChildren: this.createLazyChildren })
45
+ } else {
46
+ this.createLazyChildren(this.node)
47
+ }
48
+ }
49
+ .attributeModifier(rowModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
50
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
51
+ .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
52
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
53
+ this.node._nodeInfo.areaInfo = res[1]
54
+ }))
55
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
56
+ } else {
57
+ Column() {
58
+ if (this.node._pseudo_before || this.node._pseudo_after) {
59
+ PseduoChildren({ node: this.node, createLazyChildren: this.createLazyChildren })
60
+ } else {
61
+ this.createLazyChildren(this.node)
62
+ }
63
+ }
64
+ .attributeModifier(columnModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
65
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
66
+ .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
67
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
68
+ this.node._nodeInfo.areaInfo = res[1]
69
+ }))
70
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
29
71
  }
30
- .attributeModifier(commonStyleModify.setNode(node))
31
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
32
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
33
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
34
- node._nodeInfo.areaInfo = res[1]
35
- }))
36
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
37
- .alignItems(FlexManager.flexOptions(node).alignItems as HorizontalAlign)
38
- .justifyContent(FlexManager.flexOptions(node).justifyContent)
39
72
  }
40
73
  }
@@ -1,9 +1,9 @@
1
1
  import { AREA_CHANGE_EVENT_NAME, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
2
2
 
3
3
  import commonStyleModify from './style'
4
- import { getNormalAttributes, shouldBindEvent, getNodeThresholds } from './utils/helper'
4
+ import { shouldBindEvent, getNodeThresholds } from './utils/helper'
5
5
 
6
- import type { TaroAny, TaroWebViewElement, TaroStyleType, TaroEvent } from '@tarojs/runtime'
6
+ import type { TaroAny, TaroWebViewElement, TaroEvent } from '@tarojs/runtime'
7
7
 
8
8
  interface IPageLoad {
9
9
  url: string
@@ -14,37 +14,43 @@ interface IError {
14
14
  error: WebResourceError
15
15
  }
16
16
 
17
- @Builder
18
- export default function TaroWebView (node: TaroWebViewElement) {
19
- Web({ src: node._attrs.src, controller: node.controller })
20
- .attributeModifier(commonStyleModify.setNode(node))
21
- .onPageEnd((e: IPageLoad) => {
22
- // 1. 创建消息端口
23
- node.ports = node.controller.createWebMessagePorts(true)
24
- // 2. 发送端口1到HTML5
25
- node.controller.postMessage('init_web_messageport', [node.ports[1]], '*');
26
- // 3. 保存端口0到本地
27
- node.nativePort = node.ports[0]
28
- // 4. 设置回调函数
29
- node.nativePort.onMessageEventExt((result) => {
30
- const message = node.handleMessageFromWeb(result)
31
- const messageEvent: TaroEvent = createTaroEvent('message', { detail: { data: message } }, node)
32
-
33
- eventHandler(messageEvent, 'message', node)
17
+ @Component
18
+ export default struct TaroWebView {
19
+ @Builder customBuilder() {}
20
+ @BuilderParam createLazyChildren: (node: TaroWebViewElement) => void = this.customBuilder
21
+ @ObjectLink node: TaroWebViewElement
22
+
23
+ build () {
24
+ Web({ src: this.node._attrs.src, controller: this.node.controller })
25
+ .attributeModifier(commonStyleModify.setNode(this.node))
26
+ .onPageEnd((e: IPageLoad) => {
27
+ // 1. 创建消息端口
28
+ this.node.ports = this.node.controller.createWebMessagePorts(true)
29
+ // 2. 发送端口1到HTML5
30
+ this.node.controller.postMessage('init_web_messageport', [this.node.ports[1]], '*');
31
+ // 3. 保存端口0到本地
32
+ this.node.nativePort = this.node.ports[0]
33
+ // 4. 设置回调函数
34
+ this.node.nativePort.onMessageEventExt((result) => {
35
+ const message = this.node.handleMessageFromWeb(result)
36
+ const messageEvent: TaroEvent = createTaroEvent('message', { detail: { data: message } }, this.node)
37
+
38
+ eventHandler(messageEvent, 'message', this.node)
39
+ })
40
+
41
+ const onLoadEvent: TaroEvent = createTaroEvent('load', { detail: { src: this.node._attrs.src } }, this.node)
42
+
43
+ eventHandler(onLoadEvent, 'load', this.node)
34
44
  })
35
-
36
- const onLoadEvent: TaroEvent = createTaroEvent('load', { detail: { src: node._attrs.src } }, node)
37
-
38
- eventHandler(onLoadEvent, 'load', node)
39
- })
40
- .onErrorReceive(shouldBindEvent((e: IError) => {
41
- const event: TaroEvent = createTaroEvent('error', { detail: { url: node._attrs.src, fullUrl: e.request.getRequestUrl() } }, node)
42
-
43
- eventHandler(event, 'error', node)
44
- }, node, ['error']))
45
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
46
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
47
- node._nodeInfo.areaInfo = res[1]
48
- }))
49
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
45
+ .onErrorReceive(shouldBindEvent((e: IError) => {
46
+ const event: TaroEvent = createTaroEvent('error', { detail: { url: this.node._attrs.src, fullUrl: e.request.getRequestUrl() } }, this.node)
47
+
48
+ eventHandler(event, 'error', this.node)
49
+ }, this.node, ['error']))
50
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
51
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
52
+ this.node._nodeInfo.areaInfo = res[1]
53
+ }))
54
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
55
+ }
50
56
  }