@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
@@ -10,30 +10,33 @@ export class TEXT_DEFAULT_STYLE {
10
10
  }
11
11
 
12
12
  interface IBUTTON_THEME_COLOR {
13
- text: string
13
+ text: Color
14
14
  background: string
15
+ plainText: string | Color
15
16
  }
16
17
 
17
18
  export class BUTTON_THEME_COLOR {
18
19
  static get (type: string): IBUTTON_THEME_COLOR {
19
20
  switch (type) {
20
21
  case 'primary': return {
21
- text: '#fff',
22
+ text: Color.White,
22
23
  background: '#1aad19',
24
+ plainText: '#1aad19'
23
25
  }
24
26
  case 'warn': return {
25
- text: '#fff',
26
- background: '#e64340'
27
+ text: Color.White,
28
+ background: '#e64340',
29
+ plainText: '#e64340'
27
30
  }
28
31
  default: return {
29
- text: '#000',
32
+ text: Color.Black,
30
33
  background: '#f7f7f7',
34
+ plainText: Color.Black
31
35
  }
32
36
  }
33
37
  }
34
38
  }
35
39
 
36
-
37
40
  export class INPUT_TYPE_MAP {
38
41
  static get (type: string) {
39
42
  switch (type) {
@@ -1,106 +1,89 @@
1
- import type { TaroAny, TaroElement } from '@tarojs/runtime'
1
+ import type { TaroElement, HarmonyStyle } from '@tarojs/runtime'
2
+ import { isUndefined } from '@tarojs/shared'
3
+ import { getNormalAttributes } from './styles.ets'
4
+
5
+ interface IFlexOptions {
6
+ direction: FlexDirection,
7
+ justifyContent: FlexAlign,
8
+ alignItems: ItemAlign,
9
+ wrap?: FlexWrap,
10
+ alignContent?: FlexAlign
11
+ }
2
12
 
3
13
  class FlexManager {
4
- static flexOptions (node: TaroElement): FlexOptions {
5
- const hmStyle = node.hmStyle
14
+ static isFlexNode (node: TaroElement): boolean {
15
+ return !!node.hmStyle?.display?.includes('flex')
16
+ }
17
+
18
+ static convertFlexAlignItemsToColumnOrRow (direction: FlexDirection, alignItems: ItemAlign | undefined): VerticalAlign | HorizontalAlign {
19
+ if (direction === FlexDirection.Column) {
20
+ switch (alignItems) {
21
+ case ItemAlign.Center:
22
+ return HorizontalAlign.Center
23
+ case ItemAlign.End:
24
+ return HorizontalAlign.End
25
+ default:
26
+ return HorizontalAlign.Start
27
+ }
28
+ } else {
29
+ switch (alignItems) {
30
+ case ItemAlign.Center:
31
+ return VerticalAlign.Center
32
+ case ItemAlign.End:
33
+ return VerticalAlign.Bottom
34
+ default:
35
+ return VerticalAlign.Top
36
+ }
37
+ }
38
+ }
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
+ }
6
46
 
7
- let flexDirection = hmStyle.direction
47
+ static flexOptions (node: TaroElement): IFlexOptions {
48
+ const hmStyle: HarmonyStyle = getNormalAttributes(node) || {}
49
+ const isFlex = FlexManager.isFlexNode(node)
50
+ let flexDirection = hmStyle.flexDirection
8
51
  if (!flexDirection && flexDirection !== 0) {
9
52
  flexDirection = hmStyle.display === 'flex' ? FlexDirection.Row : FlexDirection.Column
10
53
  }
11
54
 
12
55
  return {
56
+ alignItems: isFlex ? (isUndefined(hmStyle.alignItems) ? ItemAlign.Start : hmStyle.alignItems) : ItemAlign.Start,
57
+ justifyContent: isFlex ? (isUndefined(hmStyle.justifyContent) ? FlexAlign.Start : hmStyle.justifyContent) : FlexAlign.Start,
13
58
  direction: flexDirection,
14
- justifyContent: hmStyle.justifyContent,
15
- alignItems: hmStyle.alignItems
16
- }
17
- }
18
-
19
- static flexAlign (value: string | number | undefined): FlexAlign {
20
- switch (value) {
21
- case 'flex-end':
22
- return FlexAlign.End
23
- case 'center':
24
- return FlexAlign.Center
25
- case 'space-between':
26
- return FlexAlign.SpaceBetween
27
- case 'space-around':
28
- return FlexAlign.SpaceAround
29
- case 'space-evenly':
30
- return FlexAlign.SpaceEvenly
31
- default:
32
- return FlexAlign.Start
59
+ wrap: isFlex ? hmStyle.flexWrap: FlexWrap.NoWrap,
60
+ alignContent: isFlex ? hmStyle.alignContent: FlexAlign.Start
33
61
  }
34
62
  }
35
63
 
36
- static direction (value: string): FlexDirection {
37
- switch (value) {
38
- case 'row': return FlexDirection.Row;
39
- case 'row-reverse': return FlexDirection.RowReverse;
40
- case 'column-reverse': return FlexDirection.ColumnReverse;
41
- default: return FlexDirection.Column;
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
42
69
  }
70
+ return flexDirection
43
71
  }
44
72
 
45
- static itemAlign (value: string | number | undefined): ItemAlign {
46
- switch (value) {
47
- case 'flex-start':
48
- return ItemAlign.Start
49
- case 'flex-end':
50
- return ItemAlign.End
51
- case 'center':
52
- return ItemAlign.Center
53
- case 'stretch':
54
- return ItemAlign.Stretch
55
- case 'baseline':
56
- return ItemAlign.Baseline
57
- default:
58
- return ItemAlign.Auto
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
59
79
  }
80
+ return (isFlex ? FlexManager.convertFlexAlignItemsToColumnOrRow(flexDirection, hmStyle.alignItems) : HorizontalAlign.Start) as T
60
81
  }
61
82
 
62
- static justifyContent (value: string): FlexAlign {
63
- return FlexManager.flexAlign(value)
64
- }
65
-
66
- static alignItems (value: string): ItemAlign {
67
- return FlexManager.itemAlign(value)
68
- }
69
-
70
- static alignSelf (value: string): ItemAlign {
71
- return FlexManager.itemAlign(value)
72
- }
73
-
74
- static flexWrap (value: string): FlexWrap {
75
- return value === 'wrap' ? FlexWrap.Wrap : FlexWrap.NoWrap
76
- }
77
-
78
- static alignContent (style: Record<string, string | number> = {}): FlexAlign | undefined {
79
- if (style.flexWrap !== 'wrap') return undefined
80
- const value = style.alignContent
81
- return FlexManager.flexAlign(value)
82
- }
83
-
84
- static flexSize (style: Record<string, string | number> = {}): [number, number, number | string] {
85
- const flex = style.flex
86
- const flexGrow = style.flexGrow || 0
87
- const flexShrink = style.flexShrink || 0
88
- const flexBasis = style.flexBasis || 'auto'
89
- let res: [number, number, number | string] = [Number(flexGrow), Number(flexShrink), flexBasis]
90
-
91
- if (typeof flex === 'number') {
92
- res = [flex, 1, 0]
93
- } else if (flex === 'auto') {
94
- res = [1, 1, 'auto']
95
- } else if (flex === 'none') {
96
- res = [0, 0, 'auto']
97
- } else if (typeof flex === 'string') {
98
- const FlexList = flex.replace(new RegExp("/\s+/g"), ' ').split(' ')
99
- FlexList.forEach((item, index) => {
100
- res[index] = index < 2 ? Number(item) : item
101
- })
102
- }
103
- return res
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
104
87
  }
105
88
  }
106
89
 
@@ -1,8 +1,9 @@
1
- import { getNormalAttributes, getFontAttributes } from './styles'
2
- import { bindAttributesCallback, ObjectAssign } from '@tarojs/runtime'
1
+ import { VIEW } from '@tarojs/runtime/dist/runtime.esm'
3
2
 
4
- import type { TaroAny, TaroElement } from '@tarojs/runtime'
5
- import type { Func } from '@tarojs/runtime/dist/runtime.esm'
3
+ import { getNormalAttributes, getFontAttributes, getStyleAttr } from './styles'
4
+
5
+ import type { TFunc } from '@tarojs/runtime/dist/runtime.esm'
6
+ import type { TaroElement, TaroNode } from '@tarojs/runtime'
6
7
 
7
8
  export const parseStyles = (styles = ''): Record<string, string> => {
8
9
  const styleObj: Record<string, string> = {}
@@ -21,8 +22,7 @@ export const parseStyles = (styles = ''): Record<string, string> => {
21
22
  return styleObj
22
23
  }
23
24
 
24
-
25
- export function shouldBindEvent (cb: Func, node: TaroElement, eventNames: string[], disabled = false) {
25
+ export function shouldBindEvent (cb: TFunc, node: TaroElement | null, eventNames: string[], disabled = false) {
26
26
  if (!node || node._attrs?.disabled || disabled) return null
27
27
  if (!node.__listeners) {
28
28
  return null
@@ -33,67 +33,20 @@ export function shouldBindEvent (cb: Func, node: TaroElement, eventNames: string
33
33
  }
34
34
 
35
35
  export function getNodeThresholds (node: TaroElement): number[] | null {
36
- if (!node) return null
37
-
38
- const id = node._nid
39
- const instance: TaroAny = node._instance
40
-
41
- return instance?.nodeInfoMap?.[id]?.thresholds || null
36
+ return node?._nodeInfo?.thresholds || null
42
37
  }
43
38
 
44
- function convertToCamelCase(str: string) {
45
- return str.replace(new RegExp("/-(.)/g"), (_, char: string) => char.toUpperCase()).replace(new RegExp("/^\w/"), firstChar => firstChar.toUpperCase())
46
- }
47
-
48
- // 动画绑定
49
- export function bindAnimation (node: TaroElement) {
50
- bindAttributesCallback(node, 'animation', async (animation: TaroAny) => {
51
- if (animation && animation.actions) {
52
- for (let i = 0; i < animation.actions.length; i++) {
53
- const anim: TaroAny = animation.actions[i]
54
- // 动画队列
55
- await new Promise<TaroAny>((resolve: TaroAny) => {
56
- const timingFunction: TaroAny = anim.timingFunction
57
- const animateParams: AnimateParam = {
58
- duration: anim.duration,
59
- delay: anim.delay,
60
- tempo: 1,
61
- // TODO: ETS转TS
62
- playMode: PlayMode.Normal,
63
- iterations: 1,
64
- onFinish: resolve
65
- }
66
- if (timingFunction === 'step-start') {
67
- animateParams.tempo = 0
68
- } else if (timingFunction === 'step-end') {
69
- animateParams.tempo = 0
70
- animateParams.delay = anim.duration + anim.delay
71
- animateParams.duration = 0
72
- }
73
- animateParams.curve = Curve[convertToCamelCase(timingFunction)] || Curve.EaseInOut
74
- animateTo(animateParams, () => {
75
- const component: TaroAny = node._instance
76
- const transformOrigin: string = anim.transformOrigin
39
+ export function isTagFirstChild (node: TaroElement, tagName = VIEW, level = 0): boolean {
40
+ const parent: TaroElement | null = node.parentElement
41
+ const list: TaroNode[] = node.parentNode?.childNodes || []
42
+ if (list.length < 1 || level < 0) return false
43
+ else if (!parent) return true
77
44
 
78
- if (transformOrigin) {
79
- const splitOrigin = transformOrigin.split(' ')
80
- Object.keys(anim.rule).forEach(key => {
81
- if (['scale', 'rotate'].includes(key)) {
82
- anim.rule[key] = ObjectAssign(anim.rule[key], {
83
- centerX: splitOrigin[0],
84
- centerY: splitOrigin[1],
85
- })
86
- }
87
- })
88
- }
89
-
90
- component.nodeInfoMap[node._nid].overwriteStyle = anim.rule
91
- node.updateComponent()
92
- })
93
- })
94
- }
95
- }
96
- })
45
+ if (parent.nodeName === tagName.toUpperCase()) {
46
+ return list[0] === node
47
+ } else {
48
+ return (list[0] === node) && isTagFirstChild(parent, tagName, --level)
49
+ }
97
50
  }
98
51
 
99
- export { getNormalAttributes, getFontAttributes }
52
+ 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,7 +1,10 @@
1
1
  import { convertNumber2VP } from '@tarojs/runtime'
2
- import { isNumber } from '@tarojs/shared'
2
+ import { isNumber, isUndefined } from '@tarojs/shared'
3
3
 
4
- export function getSingleSelector(ctx, range, rangeKey): any[] {
4
+ import type { RichTextProps } from '@tarojs/components/types/RichText'
5
+ import type { TaroRichTextElement } from '@tarojs/runtime'
6
+
7
+ export function getSingleSelector(range, rangeKey): any[] {
5
8
  return range.map((data) => data[rangeKey])
6
9
  }
7
10
 
@@ -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
  }