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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (239) hide show
  1. package/dist/apis/apis.ts +6 -2
  2. package/dist/apis/base/crypto.ts +4 -0
  3. package/dist/apis/base/debug.ts +5 -0
  4. package/dist/apis/base/index.ts +9 -1
  5. package/dist/apis/base/performance.ts +8 -0
  6. package/dist/apis/base/system.ts +74 -21
  7. package/dist/apis/base/update.ts +5 -0
  8. package/dist/apis/base/weapp/app-event.ts +75 -0
  9. package/dist/apis/base/weapp/life-cycle.ts +21 -0
  10. package/dist/apis/canvas/index.ts +27 -0
  11. package/dist/apis/data-analysis/index.ts +6 -0
  12. package/dist/apis/device/accelerometer.ts +2 -1
  13. package/dist/apis/device/accessibility.ts +4 -0
  14. package/dist/apis/device/battery.ts +2 -2
  15. package/dist/apis/device/bluetooth-ble.ts +19 -0
  16. package/dist/apis/device/bluetooth-peripheral.ts +6 -0
  17. package/dist/apis/device/bluetooth.ts +16 -0
  18. package/dist/apis/device/calendar.ts +5 -0
  19. package/dist/apis/device/clipboard.ts +17 -9
  20. package/dist/apis/device/compass.ts +21 -0
  21. package/dist/apis/device/contact.ts +5 -0
  22. package/dist/apis/device/crypto.ts +4 -0
  23. package/dist/apis/device/gyroscope.ts +7 -0
  24. package/dist/apis/device/iBeacon.ts +10 -0
  25. package/dist/apis/device/index.ts +15 -0
  26. package/dist/apis/device/keyboard.ts +2 -1
  27. package/dist/apis/device/memory.ts +10 -3
  28. package/dist/apis/device/motion.ts +6 -0
  29. package/dist/apis/device/network.ts +26 -9
  30. package/dist/apis/device/nfc.ts +10 -0
  31. package/dist/apis/device/phone.ts +2 -1
  32. package/dist/apis/device/scan.ts +4 -0
  33. package/dist/apis/device/screen.ts +2 -1
  34. package/dist/apis/device/sms.ts +4 -0
  35. package/dist/apis/device/vibrate.ts +19 -11
  36. package/dist/apis/device/wifi.ts +15 -0
  37. package/dist/apis/ext/index.ts +5 -0
  38. package/dist/apis/files/index.ts +2 -1
  39. package/dist/apis/files/manager.ts +2 -1
  40. package/dist/apis/framework/index.ts +3 -8
  41. package/dist/apis/index.ts +27 -17
  42. package/dist/apis/location/index.ts +61 -68
  43. package/dist/apis/media/EditorContext.ts +32 -0
  44. package/dist/apis/media/audio/index.ts +18 -0
  45. package/dist/apis/media/background-audio/index.ts +16 -0
  46. package/dist/apis/media/camera.ts +16 -0
  47. package/dist/apis/media/common.ts +2 -1
  48. package/dist/apis/media/{image.ts → image/index.ts} +4 -3
  49. package/dist/apis/media/index.ts +10 -0
  50. package/dist/apis/media/live.ts +5 -0
  51. package/dist/apis/media/map.ts +4 -0
  52. package/dist/apis/media/media-recorder.ts +4 -0
  53. package/dist/apis/media/recorder.ts +6 -0
  54. package/dist/apis/media/video/VideoContext.ts +68 -0
  55. package/dist/apis/media/{video.ts → video/index.ts} +13 -2
  56. package/dist/apis/media/video-decoder.ts +4 -0
  57. package/dist/apis/media/video-processing.ts +4 -0
  58. package/dist/apis/media/voip.ts +19 -0
  59. package/dist/apis/network/index.ts +3 -0
  60. package/dist/apis/network/mdns.ts +13 -0
  61. package/dist/apis/network/request.ts +7 -6
  62. package/dist/apis/network/tcp.ts +4 -0
  63. package/dist/apis/network/udp.ts +4 -0
  64. package/dist/apis/network/webSocket.ts +2 -6
  65. package/dist/apis/open-api/account.ts +4 -0
  66. package/dist/apis/open-api/address.ts +4 -0
  67. package/dist/apis/open-api/authorize.ts +5 -0
  68. package/dist/apis/open-api/card.ts +5 -0
  69. package/dist/apis/open-api/channels-live.ts +11 -0
  70. package/dist/apis/open-api/customer-service.ts +4 -0
  71. package/dist/apis/open-api/device-voip.ts +5 -0
  72. package/dist/apis/open-api/facial.ts +7 -0
  73. package/dist/apis/open-api/favorites.ts +5 -0
  74. package/dist/apis/open-api/group.ts +4 -0
  75. package/dist/apis/open-api/index.ts +20 -6
  76. package/dist/apis/open-api/invoice.ts +5 -0
  77. package/dist/apis/open-api/license-plate.ts +4 -0
  78. package/dist/apis/open-api/login.ts +6 -0
  79. package/dist/apis/open-api/my-miniprogram.ts +4 -0
  80. package/dist/apis/open-api/privacy.ts +7 -0
  81. package/dist/apis/open-api/red-package.ts +4 -0
  82. package/dist/apis/open-api/settings.ts +5 -0
  83. package/dist/apis/open-api/soter.ts +6 -0
  84. package/dist/apis/open-api/subscribe-message.ts +6 -0
  85. package/dist/apis/open-api/{user-info/index.ts → user-info.ts} +1 -16
  86. package/dist/apis/open-api/werun.ts +5 -0
  87. package/dist/apis/payment/index.ts +6 -0
  88. package/dist/apis/route/index.ts +19 -28
  89. package/dist/apis/share/index.ts +33 -0
  90. package/dist/apis/storage/background-fetch.ts +7 -0
  91. package/dist/apis/storage/cache-manager.ts +4 -0
  92. package/dist/apis/storage/index.ts +158 -88
  93. package/dist/apis/ui/{animation.ts → animation/animation.ts} +73 -31
  94. package/dist/apis/ui/animation/index.ts +7 -0
  95. package/dist/apis/ui/background.ts +4 -19
  96. package/dist/apis/ui/custom-component.ts +8 -0
  97. package/dist/apis/ui/fonts.ts +4 -0
  98. package/dist/apis/ui/index.ts +8 -10
  99. package/dist/apis/ui/interaction/index.ts +45 -59
  100. package/dist/apis/ui/menu.ts +4 -0
  101. package/dist/apis/ui/navigation-bar/index.ts +60 -21
  102. package/dist/apis/ui/pull-down-refresh.ts +10 -4
  103. package/dist/apis/{page → ui/scroll}/index.ts +32 -27
  104. package/dist/apis/ui/sticky.ts +4 -0
  105. package/dist/apis/{tabbar/index.ts → ui/tab-bar.ts} +6 -8
  106. package/dist/apis/ui/window.ts +20 -0
  107. package/dist/apis/utils/handler.ts +4 -4
  108. package/dist/apis/utils/index.ts +1 -1
  109. package/dist/apis/worker/index.ts +4 -0
  110. package/dist/apis/wxml/IntersectionObserver.ts +24 -25
  111. package/dist/apis/wxml/index.ts +7 -2
  112. package/dist/apis/wxml/nodesRef.ts +2 -2
  113. package/dist/apis/wxml/selectorQuery.ts +29 -17
  114. package/dist/components-harmony-ets/button.ets +106 -80
  115. package/dist/components-harmony-ets/canvas.ets +51 -0
  116. package/dist/components-harmony-ets/checkbox.ets +82 -148
  117. package/dist/components-harmony-ets/form.ets +45 -132
  118. package/dist/components-harmony-ets/icon.ets +66 -69
  119. package/dist/components-harmony-ets/image.ets +26 -61
  120. package/dist/components-harmony-ets/index.ets +92 -0
  121. package/dist/components-harmony-ets/innerHtml.ets +7 -70
  122. package/dist/components-harmony-ets/input.ets +60 -146
  123. package/dist/components-harmony-ets/label.ets +86 -92
  124. package/dist/components-harmony-ets/listView.ets +26 -0
  125. package/dist/components-harmony-ets/movableArea.ets +124 -0
  126. package/dist/components-harmony-ets/movableView.ets +93 -0
  127. package/dist/components-harmony-ets/navigationBar.ets +65 -0
  128. package/dist/components-harmony-ets/pageMeta.ets +94 -0
  129. package/dist/components-harmony-ets/picker.ets +172 -198
  130. package/dist/components-harmony-ets/progress.ets +52 -0
  131. package/dist/components-harmony-ets/pseudo.ets +80 -0
  132. package/dist/components-harmony-ets/radio.ets +85 -155
  133. package/dist/components-harmony-ets/richText.ets +15 -87
  134. package/dist/components-harmony-ets/scrollList.ets +94 -0
  135. package/dist/components-harmony-ets/scrollView.ets +81 -149
  136. package/dist/components-harmony-ets/slider.ets +47 -94
  137. package/dist/components-harmony-ets/stickySection.ets +42 -0
  138. package/dist/components-harmony-ets/style.ets +396 -0
  139. package/dist/components-harmony-ets/swiper.ets +51 -151
  140. package/dist/components-harmony-ets/switch.ets +35 -76
  141. package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
  142. package/dist/components-harmony-ets/text.ets +131 -76
  143. package/dist/components-harmony-ets/textArea.ets +64 -140
  144. package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
  145. package/dist/components-harmony-ets/utils/DynamicCenter.ts +4 -13
  146. package/dist/components-harmony-ets/utils/constant/style.ets +9 -6
  147. package/dist/components-harmony-ets/utils/flexManager.ets +68 -85
  148. package/dist/components-harmony-ets/utils/helper.ets +18 -65
  149. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  150. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  151. package/dist/components-harmony-ets/utils/index.ts +55 -51
  152. package/dist/components-harmony-ets/utils/styles.ets +177 -65
  153. package/dist/components-harmony-ets/video.ets +70 -116
  154. package/dist/components-harmony-ets/view.ets +58 -64
  155. package/dist/components-harmony-ets/webView.ets +56 -0
  156. package/dist/index.d.ts +152 -0
  157. package/dist/index.js +230 -60
  158. package/dist/index.js.map +1 -1
  159. package/dist/runtime-ets/bom/document.ts +6 -4
  160. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
  161. package/dist/runtime-ets/bom/window.ts +9 -2
  162. package/dist/runtime-ets/current.ts +3 -0
  163. package/dist/runtime-ets/dom/bind.ts +96 -0
  164. package/dist/runtime-ets/dom/class-list.ts +4 -6
  165. package/dist/runtime-ets/dom/comment.ts +1 -2
  166. package/dist/runtime-ets/dom/cssNesting.ts +409 -0
  167. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +30 -20
  168. package/dist/runtime-ets/dom/dataSource.ts +64 -0
  169. package/dist/runtime-ets/dom/document.ts +36 -51
  170. package/dist/runtime-ets/dom/element/canvas.ts +136 -0
  171. package/dist/runtime-ets/dom/element/element.ts +439 -0
  172. package/dist/runtime-ets/dom/element/form.ts +403 -0
  173. package/dist/runtime-ets/dom/element/index.ts +120 -0
  174. package/dist/runtime-ets/dom/element/movableArea.ts +11 -0
  175. package/dist/runtime-ets/dom/element/movableView.ts +242 -0
  176. package/dist/runtime-ets/dom/element/normal.ts +103 -0
  177. package/dist/runtime-ets/dom/element/progress.ts +11 -0
  178. package/dist/runtime-ets/dom/element/scrollView.ts +15 -0
  179. package/dist/runtime-ets/dom/element/text.ts +10 -0
  180. package/dist/runtime-ets/dom/element/video.ts +50 -0
  181. package/dist/runtime-ets/dom/element/webView.ts +68 -0
  182. package/dist/runtime-ets/dom/event.ts +26 -5
  183. package/dist/runtime-ets/dom/eventTarget.ts +3 -3
  184. package/dist/runtime-ets/dom/node.ts +114 -49
  185. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +805 -0
  186. package/dist/runtime-ets/dom/stylesheet/index.ts +122 -429
  187. package/dist/runtime-ets/dom/stylesheet/type.ts +93 -17
  188. package/dist/runtime-ets/dom/stylesheet/util.ts +145 -17
  189. package/dist/runtime-ets/index.ts +2 -3
  190. package/dist/runtime-ets/interface/event.ts +3 -2
  191. package/dist/runtime-ets/utils/index.ts +87 -17
  192. package/dist/runtime-ets/utils/info.ts +21 -47
  193. package/dist/runtime-framework/react/app.ts +20 -28
  194. package/dist/runtime-framework/react/hooks.ts +3 -4
  195. package/dist/runtime-framework/react/index.ts +1 -2
  196. package/dist/runtime-framework/react/native-page.ts +421 -0
  197. package/dist/runtime-framework/react/page.ts +5 -17
  198. package/dist/runtime-framework/solid/app.ts +25 -45
  199. package/dist/runtime-framework/solid/connect.ts +21 -3
  200. package/dist/runtime-framework/solid/hooks.ts +17 -12
  201. package/dist/runtime-framework/solid/index.ts +6 -2
  202. package/dist/runtime-framework/solid/page.ts +84 -36
  203. package/dist/runtime-framework/solid/reconciler/props.ts +70 -25
  204. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  205. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  206. package/dist/runtime-framework/solid/utils/index.ts +0 -2
  207. package/dist/runtime-utils.d.ts +827 -0
  208. package/dist/runtime-utils.js +1633 -549
  209. package/dist/runtime-utils.js.map +1 -1
  210. package/dist/runtime.d.ts +1 -0
  211. package/dist/runtime.js +1633 -549
  212. package/dist/runtime.js.map +1 -1
  213. package/index.js +3 -1
  214. package/package.json +14 -15
  215. package/static/media/cancel.svg +1 -0
  216. package/static/media/circle.svg +1 -0
  217. package/static/media/clear.svg +1 -0
  218. package/static/media/download.svg +1 -0
  219. package/static/media/info.svg +1 -0
  220. package/static/media/info_circle.svg +1 -0
  221. package/static/media/search.svg +1 -0
  222. package/static/media/success.svg +1 -0
  223. package/static/media/success_no_circle.svg +1 -0
  224. package/static/media/taro_arrow_left.svg +1 -0
  225. package/static/media/taro_home.svg +1 -0
  226. package/static/media/waiting.svg +1 -0
  227. package/static/media/warn.svg +1 -0
  228. package/types/harmony.d.ts +4 -0
  229. package/types/index.d.ts +4 -0
  230. package/types/runtime.d.ts +7 -1
  231. package/LICENSE +0 -160
  232. package/dist/components-harmony-ets/base.ets +0 -63
  233. package/dist/components-harmony-ets/element.ets +0 -223
  234. package/dist/components-harmony-ets/utils/constant/icon.ts +0 -19
  235. package/dist/runtime-ets/dom/element.ts +0 -457
  236. package/dist/runtime-ets/dom/text.ts +0 -19
  237. package/dist/runtime-ets/utils/bind.ts +0 -35
  238. package/types/api.d.ts +0 -4
  239. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
@@ -1,91 +1,203 @@
1
+ import { isUndefined } from '@tarojs/shared'
1
2
  import { ObjectAssign } from '@tarojs/runtime'
2
3
 
3
- import { AttributeManager } from './AttributeManager'
4
- import { TEXT_DEFAULT_STYLE } from './constant/style'
4
+ import { FlexManager } from './flexManager'
5
5
 
6
- import type { TaroAny, TaroElement, TaroStyleType, TaroTextStyleType, HarmonyType, HarmonyStyle } from '@tarojs/runtime'
7
- import type { StandardProps } from '@tarojs/components/types'
6
+ import type { StandardProps, TextProps } from '@tarojs/components/types'
7
+ import type { TaroAny, TaroElement, TaroStyleType, TaroTextStyleType, HarmonyStyle } from '@tarojs/runtime'
8
8
 
9
9
  export function getFontAttributes (node: TaroElement): TaroTextStyleType {
10
- const hmStyle = node.hmStyle
10
+ let hmStyle = getNormalAttributes(node)
11
+ const attrs: TextProps = node._attrs || {}
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
+ }
11
70
 
12
71
  const attributes: TaroAny = {
13
- maxLines: hmStyle.maxLines || Infinity,
72
+ textAlign,
73
+ verticalAlign,
74
+ WebkitLineClamp: WebkitLineClamp,
14
75
  // 已做处理的属性
15
76
  letterSpacing: hmStyle.letterSpacing,
16
- textAlign: hmStyle.textAlign,
17
- textOverflow: hmStyle.textOverflow
77
+ textOverflow: hmStyle.textOverflow,
78
+ lineHeight: lineHeight
18
79
  }
19
80
 
20
81
  return attributes
21
82
  }
22
83
 
23
- export function getNormalAttributes (node: TaroElement): TaroStyleType {
84
+ // 模拟 div 自动撑满父元素的情况
85
+ export function isMaxWidthView (node: TaroElement) {
86
+ const parentNode: TaroElement = node.parentNode as TaroElement
87
+
88
+ return node.tagName === 'VIEW' && parentNode && parentNode.tagName === 'VIEW' && !FlexManager.isFlexNode(parentNode)
89
+ }
90
+
91
+ export function getNormalAttributes (node: TaroElement, initStyle?: HarmonyStyle): HarmonyStyle {
24
92
  const hmStyle = node.hmStyle
93
+
94
+ if (!hmStyle) return {}
25
95
 
26
96
  const _nid = node._nid
27
97
  const _attrs: StandardProps = node._attrs || {}
28
98
 
29
- const transform: TaroAny = hmStyle.transform
30
- const transformRotate: HarmonyType.Transform.Rotate = transform?.rotate?.[0]
31
- const transformTranslate: HarmonyType.Transform.Translate = transform?.translate?.[0]
32
- const transformScale: HarmonyType.Transform.Scale = transform?.scale?.[0]
33
- const transformTransform: HarmonyType.Transform.Transform = transform?.transform?.[0]
34
-
35
- let normalAttributes: HarmonyStyle = {
36
- // Flex相关
37
- flexBasis: hmStyle.flexBasis,
38
- flexGrow: hmStyle.flexGrow,
39
- flexShrink: hmStyle.flexShrink,
40
- alignSelf: hmStyle.alignSelf,
41
- // 尺寸相关
42
- width: hmStyle.width,
43
- height: hmStyle.height,
44
- constraintSize: hmStyle.constraintSize,
45
- margin: hmStyle.margin,
46
- padding: hmStyle.padding,
47
- // 边框相关
48
- borderStyle: hmStyle.borderStyle,
49
- borderWidth: hmStyle.borderWidth,
50
- borderColor: hmStyle.borderColor,
51
- borderRadius: hmStyle.borderRadius,
52
- // 背景相关
53
- backgroundColor: hmStyle.backgroundColor,
54
- backgroundImage: hmStyle.backgroundImage,
55
- backgroundImageSize: hmStyle.backgroundImageSize,
56
- backgroundRepeat: hmStyle.backgroundRepeat,
57
- linearGradient: hmStyle.linearGradient,
58
- // 变换相关
59
- rotate: transformRotate,
60
- translate: transformTranslate,
61
- scale: transformScale,
62
- transform: transformTransform,
63
- // 通用文本相关
64
- color: hmStyle.color,
65
- fontSize: hmStyle.fontSize,
66
- fontStyle: hmStyle.fontStyle,
67
- fontWeight: hmStyle.fontWeight,
68
- fontFamily: hmStyle.fontFamily || TEXT_DEFAULT_STYLE.FONT_FAMILY,
69
- lineHeight: hmStyle.lineHeight,
70
- decoration: hmStyle.decoration,
71
- // 其他
72
- clip: hmStyle.clip,
73
- id: _attrs.id || _nid,
74
- // focus: _attrs.focus || false,
75
- }
99
+ let normalAttributes = hmStyle
76
100
 
101
+ // 覆盖属性
102
+ normalAttributes.id = _attrs.id || _nid
77
103
 
78
- const id = node._nid
79
- const component: TaroAny = node._instance
104
+ let pseudoStylesheet = getPseudoClass(node)
105
+ if (pseudoStylesheet) {
106
+ normalAttributes = ObjectAssign({}, normalAttributes, pseudoStylesheet)
107
+ }
80
108
 
81
- // taro_page 等写死在运行时里的节点,没有 _instance
82
- if (component) {
83
- const overwriteStyle: TaroStyleType = component.nodeInfoMap[id].overwriteStyle
109
+ // 初始化默认的值
110
+ if (initStyle) {
111
+ normalAttributes = ObjectAssign({}, initStyle, normalAttributes)
112
+ }
113
+ return normalAttributes
114
+ }
84
115
 
85
- // 处理覆盖属性:如动画的覆盖
86
- if (overwriteStyle) {
87
- 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
+ case "::empty": {
139
+ if (node.children?.length === 0) {
140
+ return pseudoStylesheet.hmStyle
141
+ }
142
+ break
143
+ }
144
+ default: {
145
+ // 解析nth-child()
146
+ // 找出当前节点在父节点中的位置
147
+ // 公式
148
+ let matchs: [number, number] | null = null
149
+ if (pseudoKey === '::nth-child(odd)') {
150
+ matchs = [2, 1]
151
+ } else if (pseudoKey === '::nth-child(even)') {
152
+ matchs = [2, 0]
153
+ } else {
154
+ matchs = parseNthChild(pseudoKey)
155
+ }
156
+ if (matchs) {
157
+ let index = node.parentNode?.childNodes.findIndex((child) => child._nid === node._nid)
158
+ if (isUndefined(index)) return null
159
+ else {
160
+ index = index + 1
161
+ if (matchs[0] === 0) {
162
+ if (index === matchs[1]) {
163
+ return pseudoStylesheet.hmStyle
164
+ }
165
+ } else {
166
+ if ((index - matchs[1]) % matchs[0] === 0) {
167
+ return pseudoStylesheet.hmStyle
168
+ }
169
+ }
170
+ }
171
+ }
172
+ }
173
+ }
88
174
  }
89
175
  }
90
- return normalAttributes
176
+ return null
91
177
  }
178
+
179
+ // 正则匹配nth-child
180
+ function parseNthChild(selector: string): [number, number] | null {
181
+ const regex = /nth-child\((?:(-?\d*)n\s*)?([+-]?\s*\d+)?\)/;
182
+ const match = selector.match(regex);
183
+
184
+ if (match) {
185
+ const a = match[1] ? parseInt(match[1]) : 0;
186
+ const b = match[2] ? parseInt(match[2]) : 0;
187
+ return [a, b];
188
+ } else {
189
+ return null;
190
+ }
191
+ }
192
+
193
+
194
+ export function getStyleAttr(node: TaroElement | null, key: string): TaroAny {
195
+ if (!node) return null
196
+ const hmStyle = node.hmStyle
197
+ if (!hmStyle) return null
198
+ // 覆盖属性
199
+ if (key === 'width') {
200
+ return isMaxWidthView(node) && isUndefined(hmStyle.width) ? '100%' : hmStyle.width
201
+ }
202
+ return hmStyle[key]
203
+ }
@@ -1,13 +1,10 @@
1
- import { bindInstanceToNode, AREA_CHANGE_EVENT_NAME, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME, initComponentNodeInfo, getPageScrollerOrNode,
2
- TaroEvent, TaroAny } from '@tarojs/runtime'
1
+ import { AREA_CHANGE_EVENT_NAME, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
3
2
 
4
- import TaroComponentWrapper from './base'
3
+ import commonStyleModify from './style'
5
4
  import { TOUCH_EVENT_MAP } from './utils/constant/event'
6
- import { createTaroEvent } from './utils/events'
7
- import { getNormalAttributes, shouldBindEvent, getNodeThresholds, bindAnimation } from './utils/helper'
5
+ import { shouldBindEvent, getNodeThresholds } from './utils/helper'
8
6
 
9
- import type { TaroVideoElement } from './element'
10
- import type { TaroStyleType } from '@tarojs/runtime'
7
+ import type { TaroAny, TaroVideoElement, TaroEvent } from '@tarojs/runtime'
11
8
 
12
9
  export interface VideoOptions {
13
10
  src?: string | Resource
@@ -25,137 +22,94 @@ export interface VideoUpdateEvent {
25
22
  time: number
26
23
  }
27
24
 
28
- @Extend(Video)
29
- function attrs (style: TaroStyleType) {
30
- .id(style.id)
31
- .key(style.id)
32
- .padding(style.padding)
33
- .margin(style.margin)
34
- .width(style.width)
35
- .height(style.height)
36
- .constraintSize(style.constraintSize)
37
- .flexGrow(style.flexGrow)
38
- .flexShrink(style.flexShrink)
39
- .flexBasis(style.flexBasis)
40
- .alignSelf(style.alignSelf)
41
- .backgroundColor(style.backgroundColor)
42
- .backgroundImage(style.backgroundImage, style.backgroundRepeat)
43
- .backgroundImageSize(style.backgroundImageSize)
44
- .rotate(style.rotate)
45
- .scale(style.scale)
46
- .translate(style.translate)
47
- .transform(style.transform)
48
- .borderStyle(style.borderStyle)
49
- .borderWidth(style.borderWidth)
50
- .borderColor(style.borderColor)
51
- .borderRadius(style.borderRadius)
52
- .linearGradient(style.linearGradient)
53
- .zIndex(style.zIndex)
54
- .opacity(style.opacity)
55
- .clip(style.clip)
56
- }
57
-
58
25
  @Extend(Video)
59
26
  function props(attr: VideoAttrs) {
60
27
  .muted(attr.muted)
61
28
  .autoPlay(attr.autoPlay)
62
29
  .controls(attr.controls)
63
30
  .objectFit(attr.objectFit)
64
- .loop(attr.loop)
31
+ .loop(attr.loop || false)
65
32
  }
66
33
 
67
- @Component
68
- export default struct TaroVideo {
69
- nodeInfoMap: TaroAny = {}
70
-
71
- @Styles visibleChangeEvent () {
72
- .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
73
- }
34
+ function emitEvent (node: TaroVideoElement, type: string, detail?: TaroAny) {
35
+ const event: TaroEvent = createTaroEvent(type, { detail }, node)
74
36
 
75
- @ObjectLink node: TaroVideoElement
76
-
77
- controller: VideoController = new VideoController()
37
+ event.stopPropagation()
38
+ eventHandler(event, type, node)
39
+ }
78
40
 
79
- aboutToAppear () {
80
- initComponentNodeInfo(this, this.node)
81
- bindInstanceToNode(this.node, this)
82
- // 绑定动画
83
- bindAnimation(this.node)
41
+ function getVideoData (node: TaroVideoElement): VideoOptions {
42
+ const src = node._attrs.src
43
+ const poster = node._attrs.poster
44
+ return {
45
+ src,
46
+ previewUri: poster,
47
+ controller: node.controller
84
48
  }
49
+ }
85
50
 
86
- @Styles defaultEvent () {
87
- .onClick((e: ClickEvent) => {
88
- eventHandler(e, 'click', this.node)
89
- })
90
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
91
- .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, res => {
92
- const eventResult: TaroAny = res.eventResult
93
- this.nodeInfoMap[this.node._nid].areaInfo = eventResult[1]
94
- }))
51
+ function getObjectFit (node: TaroVideoElement) {
52
+ switch (node._attrs.objectFit) {
53
+ case 'contain': return ImageFit.Contain
54
+ case 'cover': return ImageFit.Cover
55
+ case 'fill': return ImageFit.Fill
56
+ default: return ImageFit.Contain
95
57
  }
58
+ }
96
59
 
97
- emitEvent = (type: string, detail?: TaroAny) => {
98
- const event: TaroEvent = createTaroEvent(type, { detail }, this.node)
99
- event.stopPropagation()
100
- eventHandler(event, type, this.node)
60
+ function getVideoProps (node: TaroVideoElement): VideoAttrs {
61
+ const muted: boolean = node._attrs.muted || false
62
+ const autoPlay: boolean = node._attrs.autoplay || false
63
+ const controls: boolean = node._attrs.controls || false
64
+ const objectFit: ImageFit = getObjectFit(node)
65
+ const loop: boolean = node._attrs.loop || false
66
+ return {
67
+ muted,
68
+ controls,
69
+ objectFit,
70
+ loop,
71
+ autoPlay
101
72
  }
73
+ }
102
74
 
75
+ function handleUpdate (node: TaroVideoElement, e: VideoUpdateEvent) {
76
+ node._nodeInfo._currentTime = e.time
103
77
 
104
- getVideoData (): VideoOptions {
105
- const src = this.node._attrs.src
106
- const poster = this.node._attrs.poster
107
- return {
108
- src,
109
- previewUri: poster,
110
- controller: this.controller
111
- }
112
- }
78
+ emitEvent(node, 'timeUpdate', { currentTime: e.time})
79
+ }
113
80
 
114
- getObjectFit () {
115
- switch (this.node._attrs.objectFit) {
116
- case 'contain': return ImageFit.Contain
117
- case 'cover': return ImageFit.Cover
118
- case 'fill': return ImageFit.Fill
119
- default: return ImageFit.Contain
120
- }
121
- }
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> = {}
122
87
 
123
- getVideoProps (): VideoAttrs {
124
- const muted: boolean = this.node._attrs.muted || false
125
- const autoPlay: boolean = this.node._attrs.autoplay || false
126
- const controls: boolean = this.node._attrs.controls || false
127
- const objectFit: ImageFit = this.getObjectFit()
128
- const loop: boolean = this.node._attrs.loop || false
129
- return {
130
- muted,
131
- controls,
132
- objectFit,
133
- loop,
134
- autoPlay
88
+ aboutToAppear(): void {
89
+ if (this.node) {
90
+ this.node._instance = this
135
91
  }
136
92
  }
137
93
 
138
- handleUpdate (e: VideoUpdateEvent) {
139
- this.nodeInfoMap[this.node._nid].currentTime = e.time
140
- this.emitEvent('timeUpdate', { currentTime: e.time})
94
+ build () {
95
+ Video(getVideoData(this.node))
96
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
97
+ .props(getVideoProps(this.node))
98
+ .onStart(shouldBindEvent(() => { emitEvent(this.node, 'play') }, this.node, ['play']))
99
+ .onPause(shouldBindEvent(() => { emitEvent(this.node, 'pause') }, this.node, ['pause']))
100
+ .onFinish(shouldBindEvent(() => { emitEvent(this.node, 'ended') }, this.node, ['ended']))
101
+ .onError(shouldBindEvent(() => { emitEvent(this.node, 'error') }, this.node, ['error']))
102
+ .onUpdate((e) => { handleUpdate(this.node, e) })
103
+ .onPrepared(shouldBindEvent((e: TaroAny) => { emitEvent(this.node, 'loadedMetaData', { duration: e.duration }) }, this.node, ['loadedmetadata']))
104
+ .onSeeking(shouldBindEvent((e: TaroAny) => { emitEvent(this.node, 'seeking', { duration: e.time }) }, this.node, ['seeking']))
105
+ .onSeeked(shouldBindEvent(() => { emitEvent(this.node, 'seeked') }, this.node, ['seeked']))
106
+ .onFullscreenChange(shouldBindEvent((e: TaroAny) => { emitEvent(this.node, 'fullScreenChange', { fullScreen: e.fullscreen}) }, this.node, ['fullscreenchange']))
107
+ .onClick((e: ClickEvent) => { eventHandler(e, 'click', this.node) })
108
+ .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
109
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
110
+ this.node._nodeInfo.areaInfo = res[1]
111
+ }))
112
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
141
113
  }
142
114
 
143
- build() {
144
- TaroComponentWrapper({ node: this.node }) {
145
- Video(this.getVideoData())
146
- .attrs(getNormalAttributes(this.node))
147
- .props(this.getVideoProps())
148
- .defaultEvent()
149
- .visibleChangeEvent()
150
- .onStart(shouldBindEvent(() => { this.emitEvent('play') }, this.node, ['play']))
151
- .onPause(shouldBindEvent(() => { this.emitEvent('pause') }, this.node, ['pause']))
152
- .onFinish(shouldBindEvent(() => { this.emitEvent('ended') }, this.node, ['ended']))
153
- .onError(shouldBindEvent(() => { this.emitEvent('error') }, this.node, ['error']))
154
- .onUpdate((e) => { this.handleUpdate(e) })
155
- .onPrepared(shouldBindEvent((e: TaroAny) => { this.emitEvent('loadedMetaData', { duration: e.duration }) }, this.node, ['loadedmetadata']))
156
- .onSeeking(shouldBindEvent((e: TaroAny) => { this.emitEvent('seeking', { duration: e.time }) }, this.node, ['seeking']))
157
- .onSeeked(shouldBindEvent(() => { this.emitEvent('seeked') }, this.node, ['seeked']))
158
- .onFullscreenChange(shouldBindEvent((e: TaroAny) => { this.emitEvent('fullScreenChange', { fullScreen: e.fullscreen}) }, this.node, ['fullscreenchange']))
159
- }
160
- }
161
115
  }
@@ -1,79 +1,73 @@
1
- import { bindInstanceToNode, eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, initComponentNodeInfo, TaroAny } from '@tarojs/runtime'
1
+ import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME } from '@tarojs/runtime'
2
2
 
3
- import { createNode } from './render'
4
- import TaroComponentWrapper from './base'
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'
7
- import { getNodeThresholds, getNormalAttributes, shouldBindEvent, bindAnimation } from './utils/helper'
6
+ import { FlexManager } from './utils/flexManager'
7
+ import { getNodeThresholds, shouldBindEvent } from './utils/helper'
8
8
 
9
- import type { TaroViewElement, TaroElement } from './element'
10
- import type { TaroStyleType } from '@tarojs/runtime'
11
-
12
- @Extend(Flex)
13
- function attrs (style: TaroStyleType) {
14
- .id(style.id)
15
- .key(style.id)
16
- .padding(style.padding)
17
- .margin(style.margin)
18
- .width(style.width)
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)
26
- .backgroundImage(style.backgroundImage, style.backgroundRepeat)
27
- .backgroundImageSize(style.backgroundImageSize)
28
- .rotate(style.rotate)
29
- .scale(style.scale)
30
- .translate(style.translate)
31
- .transform(style.transform)
32
- .borderStyle(style.borderStyle)
33
- .borderWidth(style.borderWidth)
34
- .borderColor(style.borderColor)
35
- .borderRadius(style.borderRadius)
36
- .linearGradient(style.linearGradient)
37
- .zIndex(style.zIndex)
38
- .opacity(style.opacity)
39
- .clip(style.clip)
40
- }
9
+ import type { TaroViewElement, TaroAny } from '@tarojs/runtime'
10
+ import { isUndefined } from '@tarojs/shared'
41
11
 
42
12
  @Component
43
13
  export default struct TaroView {
44
- nodeInfoMap: TaroAny = {}
45
-
46
- @Styles visibleChangeEvent () {
47
- .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
48
- }
49
-
14
+ @Builder customBuilder() {}
15
+ @BuilderParam createLazyChildren: (node: TaroViewElement) => void = this.customBuilder
50
16
  @ObjectLink node: TaroViewElement
17
+ @State overwriteStyle: Record<string, TaroAny> = {}
51
18
 
52
- aboutToAppear () {
53
- initComponentNodeInfo(this, this.node)
54
- bindInstanceToNode(this.node, this)
55
- // 绑定动画
56
- bindAnimation(this.node)
19
+ aboutToAppear(): void {
20
+ if (this.node) {
21
+ this.node._instance = this
22
+ }
57
23
  }
58
24
 
59
- @Styles defaultEvent () {
60
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
61
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
62
- .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, res => {
63
- const eventResult: TaroAny = res.eventResult
64
- this.nodeInfoMap[this.node._nid].areaInfo = eventResult[1]
65
- }))
66
- }
67
- build() {
68
- TaroComponentWrapper({ node: this.node }) {
25
+ build () {
26
+ if (FlexManager.useFlexLayout(this.node)) {
69
27
  Flex(FlexManager.flexOptions(this.node)) {
70
- ForEach(this.node.childNodes, (item: TaroElement) => {
71
- createNode(item)
72
- }, (item: TaroElement) => item._nid)
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
+ }
73
63
  }
74
- .attrs(getNormalAttributes(this.node))
75
- .defaultEvent()
76
- .visibleChangeEvent()
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))
77
71
  }
78
72
  }
79
73
  }