@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
@@ -0,0 +1,805 @@
1
+ // @ts-nocheck
2
+
3
+ import { CSSProperties } from 'react'
4
+
5
+ import { TaroElement } from '../element/element'
6
+ import { BORDER_STYLE_MAP, capitalizeFirstLetter, FlexManager, getNodeMarginOrPaddingData, getUnit } from './util'
7
+
8
+ // 背景解析正则
9
+ const BACKGROUND_REGEX = {
10
+ IMAGE: /url\((['"])?(.*?)\1\)|((linear|radial)-gradient\([^)]*\))/g,
11
+ COLOR: /(#[0-9a-fA-F]{3,8}|rgb\(\d+,\s*\d+,\s*\d+\)|rgba?\(\d+,\s*\d+,\s*\d+,\s*(?:0?\.\d+|\d+%)\)|transparent)/,
12
+ REPEAT: /(repeat-x|repeat-y|repeat|space|round|no-repeat)/,
13
+ POSITION: /(top|left|center|right|bottom|\d+(\.\d+)?(px|%|vw|vh)?)+/g,
14
+ SIZE: /(cover|contain|\d+(\.\d+)?(px|%|vw|vh)?)+/g
15
+ }
16
+
17
+ // Note: 将 web 端的 style 转换为 hm 端的 style
18
+ export default function convertWebStyle2HmStyle(webStyle: CSSProperties, node?: TaroElement) {
19
+ const hmStyle: Record<string, any> = node?._st?.hmStyle || {}
20
+ Object.keys(webStyle).forEach((key) => {
21
+ const value = webStyle[key]
22
+ switch (key) {
23
+ case 'padding': {
24
+ const { top, bottom, left, right } = getNodeMarginOrPaddingData(value)
25
+ hmStyle.paddingTop = top
26
+ hmStyle.paddingBottom = bottom
27
+ hmStyle.paddingLeft = left
28
+ hmStyle.paddingRight = right
29
+ break
30
+ }
31
+ case 'paddingTop': {
32
+ hmStyle.paddingTop = getUnit(value)
33
+ break
34
+ }
35
+ case 'paddingBottom': {
36
+ hmStyle.paddingBottom = getUnit(value)
37
+ break
38
+ }
39
+ case 'paddingLeft': {
40
+ hmStyle.paddingLeft = getUnit(value)
41
+ break
42
+ }
43
+ case 'paddingRight': {
44
+ hmStyle.paddingRight = getUnit(value)
45
+ break
46
+ }
47
+ case 'margin': {
48
+ const { top, bottom, left, right } = getNodeMarginOrPaddingData(value)
49
+ hmStyle.marginTop = top
50
+ hmStyle.marginBottom = bottom
51
+ hmStyle.marginLeft = left
52
+ hmStyle.marginRight = right
53
+ break
54
+ }
55
+ case 'marginTop': {
56
+ hmStyle.marginTop = getUnit(value)
57
+ break
58
+ }
59
+ case 'marginBottom': {
60
+ hmStyle.marginBottom = getUnit(value)
61
+ break
62
+ }
63
+ case 'marginLeft': {
64
+ hmStyle.marginLeft = getUnit(value)
65
+ break
66
+ }
67
+ case 'marginRight': {
68
+ hmStyle.marginRight = getUnit(value)
69
+ break
70
+ }
71
+ case 'top': {
72
+ hmStyle.top = getUnit(value)
73
+ break
74
+ }
75
+ case 'left': {
76
+ hmStyle.left = getUnit(value)
77
+ break
78
+ }
79
+ case 'right': {
80
+ hmStyle.right = getUnit(value)
81
+ break
82
+ }
83
+ case 'bottom': {
84
+ hmStyle.bottom = getUnit(value)
85
+ break
86
+ }
87
+ case 'flex': {
88
+ let res: [number, number, number | string] = [0, 0, 'auto']
89
+ if (typeof value === 'number') {
90
+ res = [value, 1, 0]
91
+ } else if (value === 'auto') {
92
+ res = [1, 1, 'auto']
93
+ } else if (value === 'none') {
94
+ res = [0, 0, 'auto']
95
+ } else if (typeof value === 'string') {
96
+ const FlexList = value.replace(new RegExp('/\\s+/g'), ' ').split(' ')
97
+ FlexList.forEach((item, index) => {
98
+ res[index] = index < 2 ? Number(item) : item
99
+ })
100
+ }
101
+ hmStyle.flexGrow = getUnit(res[0])
102
+ hmStyle.flexShrink = Number(res[1])
103
+ hmStyle.flexBasis = Number(res[2])
104
+ break
105
+ }
106
+ case 'flexGrow': {
107
+ hmStyle.flexGrow = getUnit(value)
108
+ break
109
+ }
110
+ case 'flexShrink': {
111
+ hmStyle.flexShrink = Number(value)
112
+ break
113
+ }
114
+ case 'flexBasis': {
115
+ hmStyle.flexBasis = Number(value)
116
+ break
117
+ }
118
+ case 'alignSelf': {
119
+ hmStyle.alignSelf = FlexManager.itemAlign(value)
120
+ break
121
+ }
122
+ case 'flexDirection': {
123
+ hmStyle.flexDirection = FlexManager.direction(value)
124
+ break
125
+ }
126
+ case 'justifyContent': {
127
+ hmStyle.justifyContent = FlexManager.flexAlign(value)
128
+ break
129
+ }
130
+ case 'alignItems': {
131
+ hmStyle.alignItems = FlexManager.itemAlign(value)
132
+ break
133
+ }
134
+ case 'alignContent': {
135
+ hmStyle.alignContent = FlexManager.flexAlign(value)
136
+ break
137
+ }
138
+ case 'flexWrap': {
139
+ hmStyle.flexWrap = FlexManager.flexWrap(value)
140
+ break
141
+ }
142
+ case 'width': {
143
+ hmStyle.width = getUnit(value)
144
+ break
145
+ }
146
+ case 'height': {
147
+ hmStyle.height = getUnit(value)
148
+ break
149
+ }
150
+ case 'minWidth': {
151
+ hmStyle.minWidth = getUnit(value)
152
+ break
153
+ }
154
+ case 'minHeight': {
155
+ hmStyle.minHeight = getUnit(value)
156
+ break
157
+ }
158
+ case 'maxWidth': {
159
+ hmStyle.maxWidth = getUnit(value)
160
+ break
161
+ }
162
+ case 'maxHeight': {
163
+ hmStyle.maxHeight = getUnit(value)
164
+ break
165
+ }
166
+ case 'background': {
167
+ const bg = setBackground(value)
168
+ if (bg['background-color']) { hmStyle.backgroundColor = bg['background-color'] }
169
+ bg['background-image'] && setBackgroundImage(hmStyle, bg['background-image'])
170
+ bg['background-repeat'] && setBackgroundRepeat(hmStyle, bg['background-repeat'])
171
+ bg['background-position'] && setBackgroundPosistion(hmStyle, bg['background-position'])
172
+ bg['background-size'] && setBackgroundSize(hmStyle, bg['background-size'])
173
+ break
174
+ }
175
+ case 'backgroundColor': {
176
+ hmStyle.backgroundColor = value
177
+ break
178
+ }
179
+ case 'backgroundImage': {
180
+ setBackgroundImage(hmStyle, value)
181
+ break
182
+ }
183
+ case 'backgroundRepeat': {
184
+ setBackgroundRepeat(hmStyle, value)
185
+ break
186
+ }
187
+ case 'backgroundSize': {
188
+ setBackgroundSize(hmStyle, value)
189
+ break
190
+ }
191
+ case 'backgroundPosition': {
192
+ setBackgroundPosistion(hmStyle, value)
193
+ break
194
+ }
195
+ case 'border': {
196
+ const [width, style, color] = value.split(' ')
197
+ hmStyle.borderTopWidth = getUnit(width)
198
+ hmStyle.borderRightWidth = getUnit(width)
199
+ hmStyle.borderBottomWidth = getUnit(width)
200
+ hmStyle.borderLeftWidth = getUnit(width)
201
+ hmStyle.borderTopStyle = BORDER_STYLE_MAP.get(style)
202
+ hmStyle.borderRightStyle = BORDER_STYLE_MAP.get(style)
203
+ hmStyle.borderBottomStyle = BORDER_STYLE_MAP.get(style)
204
+ hmStyle.borderLeftStyle = BORDER_STYLE_MAP.get(style)
205
+ hmStyle.borderTopColor = color
206
+ hmStyle.borderRightColor = color
207
+ hmStyle.borderBottomColor = color
208
+ hmStyle.borderLeftColor = color
209
+ break
210
+ }
211
+ case 'borderTop': {
212
+ const [width, style, color] = value.split(' ')
213
+ hmStyle.borderTopWidth = getUnit(width)
214
+ hmStyle.borderTopStyle = BORDER_STYLE_MAP.get(style)
215
+ hmStyle.borderTopColor = color
216
+ break
217
+ }
218
+ case 'borderRight': {
219
+ const [width, style, color] = value.split(' ')
220
+ hmStyle.borderRightWidth = getUnit(width)
221
+ hmStyle.borderRightStyle = BORDER_STYLE_MAP.get(style)
222
+ hmStyle.borderRightColor = color
223
+ break
224
+ }
225
+ case 'borderBottom': {
226
+ const [width, style, color] = value.split(' ')
227
+ hmStyle.borderBottomWidth = getUnit(width)
228
+ hmStyle.borderBottomStyle = BORDER_STYLE_MAP.get(style)
229
+ hmStyle.borderBottomColor = color
230
+ break
231
+ }
232
+ case 'borderLeft': {
233
+ const [width, style, color] = value.split(' ')
234
+ hmStyle.borderLeftWidth = getUnit(width)
235
+ hmStyle.borderLeftStyle = BORDER_STYLE_MAP.get(style)
236
+ hmStyle.borderLeftColor = color
237
+ break
238
+ }
239
+ case 'borderWidth': {
240
+ hmStyle.borderTopWidth = getUnit(value)
241
+ hmStyle.borderRightWidth = getUnit(value)
242
+ hmStyle.borderBottomWidth = getUnit(value)
243
+ hmStyle.borderLeftWidth = getUnit(value)
244
+ break
245
+ }
246
+ case 'borderLeftWidth': {
247
+ hmStyle.borderLeftWidth = getUnit(value)
248
+ break
249
+ }
250
+ case 'borderRightWidth': {
251
+ hmStyle.borderRightWidth = getUnit(value)
252
+ break
253
+ }
254
+ case 'borderTopWidth': {
255
+ hmStyle.borderTopWidth = getUnit(value)
256
+ break
257
+ }
258
+ case 'borderBottomWidth': {
259
+ hmStyle.borderBottomWidth = getUnit(value)
260
+ break
261
+ }
262
+ case 'borderStyle': {
263
+ hmStyle.borderTopStyle = BORDER_STYLE_MAP.get(value)
264
+ hmStyle.borderRightStyle = BORDER_STYLE_MAP.get(value)
265
+ hmStyle.borderBottomStyle = BORDER_STYLE_MAP.get(value)
266
+ hmStyle.borderLeftStyle = BORDER_STYLE_MAP.get(value)
267
+ break
268
+ }
269
+ case 'borderLeftStyle': {
270
+ hmStyle.borderLeftStyle = BORDER_STYLE_MAP.get(value)
271
+ break
272
+ }
273
+ case 'borderRightStyle': {
274
+ hmStyle.borderRightStyle = BORDER_STYLE_MAP.get(value)
275
+ break
276
+ }
277
+ case 'borderTopStyle': {
278
+ hmStyle.borderTopStyle = BORDER_STYLE_MAP.get(value)
279
+ break
280
+ }
281
+ case 'borderBottomStyle': {
282
+ hmStyle.borderBottomStyle = BORDER_STYLE_MAP.get(value)
283
+ break
284
+ }
285
+ case 'borderColor': {
286
+ hmStyle.borderTopColor = value
287
+ hmStyle.borderRightColor = value
288
+ hmStyle.borderBottomColor = value
289
+ hmStyle.borderLeftColor = value
290
+ break
291
+ }
292
+ case 'borderLeftColor': {
293
+ hmStyle.borderLeftColor = value
294
+ break
295
+ }
296
+ case 'borderRightColor': {
297
+ hmStyle.borderRightColor = value
298
+ break
299
+ }
300
+ case 'borderTopColor': {
301
+ hmStyle.borderTopColor = value
302
+ break
303
+ }
304
+ case 'borderBottomColor': {
305
+ hmStyle.borderBottomColor = value
306
+ break
307
+ }
308
+ case 'borderRadius': {
309
+ hmStyle.borderTopLeftRadius = getUnit(value)
310
+ hmStyle.borderTopRightRadius = getUnit(value)
311
+ hmStyle.borderBottomLeftRadius = getUnit(value)
312
+ hmStyle.borderBottomRightRadius = getUnit(value)
313
+ break
314
+ }
315
+ case 'borderTopLeftRadius': {
316
+ hmStyle.borderTopLeftRadius = getUnit(value)
317
+ break
318
+ }
319
+ case 'borderTopRightRadius': {
320
+ hmStyle.borderTopRightRadius = getUnit(value)
321
+ break
322
+ }
323
+ case 'borderBottomLeftRadius': {
324
+ hmStyle.borderBottomLeftRadius = getUnit(value)
325
+ break
326
+ }
327
+ case 'borderBottomRightRadius': {
328
+ hmStyle.borderBottomRightRadius = getUnit(value)
329
+ break
330
+ }
331
+ case 'color': {
332
+ hmStyle.color = value
333
+ break
334
+ }
335
+ case 'fontSize': {
336
+ hmStyle.fontSize = getUnit(value)
337
+ break
338
+ }
339
+ case 'fontWeight': {
340
+ setFontWeight(hmStyle, value)
341
+ break
342
+ }
343
+ case 'fontStyle': {
344
+ switch (value) {
345
+ case 'italic':
346
+ hmStyle.fontStyle = FontStyle.Italic
347
+ break
348
+ default:
349
+ hmStyle.fontStyle = FontStyle.Normal
350
+ }
351
+ break
352
+ }
353
+ case 'textAlign': {
354
+ switch (value) {
355
+ case 'left':
356
+ hmStyle.textAlign = TextAlign.Start
357
+ break
358
+ case 'center':
359
+ hmStyle.textAlign = TextAlign.Center
360
+ break
361
+ case 'right':
362
+ hmStyle.textAlign = TextAlign.End
363
+ break
364
+ default:
365
+ hmStyle.textAlign = TextAlign.Start
366
+ break
367
+ }
368
+ break
369
+ }
370
+ case 'verticalAlign': {
371
+ switch (value) {
372
+ case 'supper':
373
+ case 'top':
374
+ case 'text-top':
375
+ hmStyle.verticalAlign = Alignment.Top
376
+ break
377
+ case 'middle':
378
+ hmStyle.verticalAlign = Alignment.Center
379
+ break
380
+ case 'sub':
381
+ case 'text-bottom':
382
+ case 'bottom':
383
+ hmStyle.verticalAlign = Alignment.Bottom
384
+ break
385
+ }
386
+ break
387
+ }
388
+ case 'lineHeight': {
389
+ hmStyle.lineHeight = getUnit(value)
390
+ break
391
+ }
392
+ case 'letterSpacing': {
393
+ hmStyle.letterSpacing = getUnit(value)
394
+ break
395
+ }
396
+ case 'textDecoration': {
397
+ if (typeof value === 'string') {
398
+ switch (value) {
399
+ case 'underline': hmStyle.textDecoration = { type: TextDecorationType.Underline }; break
400
+ case 'overline': hmStyle.textDecoration = { type: TextDecorationType.Overline }; break
401
+ case 'line-through': hmStyle.textDecoration = { type: TextDecorationType.LineThrough }; break
402
+ default: hmStyle.textDecoration = { type: TextDecorationType.None }; break
403
+ }
404
+ }
405
+ break
406
+ }
407
+ case 'textOverflow': {
408
+ if (typeof value === 'string') {
409
+ let overflow = TextOverflow.None
410
+ switch (value) {
411
+ case 'clip': overflow = TextOverflow.Clip; break
412
+ case 'ellipsis': overflow = TextOverflow.Ellipsis; break
413
+ case 'marquee': overflow = TextOverflow.MARQUEE; break
414
+ }
415
+ hmStyle.textOverflow = {
416
+ overflow
417
+ }
418
+ }
419
+ break
420
+ }
421
+ case 'WebkitLineClamp': {
422
+ hmStyle.WebkitLineClamp = Number(value)
423
+ break
424
+ }
425
+ case 'transform': {
426
+ hmStyle.transform = parseTransform(value)
427
+ break
428
+ }
429
+ case 'transformOrigin': {
430
+ hmStyle.transformOrigin = parseTransformOrigin(value)
431
+ break
432
+ }
433
+ case 'position': {
434
+ hmStyle.position = value
435
+ break
436
+ }
437
+ case 'display': {
438
+ hmStyle.display = value
439
+ break
440
+ }
441
+ case 'zIndex': {
442
+ hmStyle.zIndex = Number(value)
443
+ break
444
+ }
445
+ case 'opacity': {
446
+ const val = Number(value)
447
+ hmStyle.opacity = Number.isNaN(val) ? 1 : val
448
+ break
449
+ }
450
+ case 'overflow': {
451
+ if (value === 'auto') {
452
+ hmStyle.overflow = 'scroll'
453
+ } else {
454
+ hmStyle.overflow = value
455
+ }
456
+ break
457
+ }
458
+ case 'animation': {
459
+ // TODO:不支持解析Style上的动画参数
460
+ break
461
+ }
462
+ default: {
463
+ hmStyle[key] = value
464
+ break
465
+ }
466
+ }
467
+ })
468
+ return hmStyle
469
+ }
470
+
471
+ function setBackgroundImage(hmStyle, value) {
472
+ if (typeof value === 'string') {
473
+ if (value.indexOf('url(') !== -1 && value.indexOf(')') !== -1) {
474
+ // 如果包含 url(),则说明是 background-image 属性
475
+ const match = value.match(new RegExp('url\\([\'"]?(.*?)[\'"]?\\)'))
476
+ if (match) {
477
+ hmStyle.backgroundImage = {
478
+ src: match[1]
479
+ }
480
+ }
481
+ } else if (value.indexOf('linear-gradient(') !== -1) {
482
+ hmStyle.backgroundImage = parseGradient(value)
483
+ }
484
+ }
485
+ }
486
+
487
+ // 解析background属性
488
+ function setBackground (backgroundValue: string) {
489
+ backgroundValue = preprocessCss(backgroundValue)
490
+ const result = {
491
+ 'background-color': '',
492
+ 'background-image': '',
493
+ 'background-repeat': '',
494
+ 'background-position': '',
495
+ 'background-size': ''
496
+ }
497
+
498
+ if (!backgroundValue) return result
499
+
500
+ // 匹配background-image
501
+ const imageMatch = backgroundValue.match(BACKGROUND_REGEX.IMAGE)
502
+ if (imageMatch) {
503
+ result['background-image'] = imageMatch[0]
504
+ backgroundValue = backgroundValue.replace(imageMatch[0], '').trim()
505
+ }
506
+
507
+ // 匹配background-color
508
+ const colorMatch = backgroundValue.match(BACKGROUND_REGEX.COLOR)
509
+ if (colorMatch) {
510
+ result['background-color'] = colorMatch[0]
511
+ backgroundValue = backgroundValue.replace(colorMatch[0], '').trim()
512
+ }
513
+
514
+ // 匹配background-repeat
515
+ const repeatMatch = backgroundValue.match(BACKGROUND_REGEX.REPEAT)
516
+ if (repeatMatch) {
517
+ result['background-repeat'] = repeatMatch[0]
518
+ backgroundValue = backgroundValue.replace(repeatMatch[0], '').trim()
519
+ }
520
+
521
+ // 匹配background-position,background-size
522
+ // 先分割 / 分割出background-position\background-size
523
+ const positionSize = backgroundValue.split('/')
524
+ const [position, size] = positionSize
525
+ // 匹配background-position
526
+ if (position) {
527
+ const positionMatch = position.match(BACKGROUND_REGEX.POSITION)
528
+ if (positionMatch) {
529
+ result['background-position'] = positionMatch.join(' ')
530
+ }
531
+ }
532
+ if (size) {
533
+ // 匹配background-size
534
+ const sizeMatch = size.match(BACKGROUND_REGEX.SIZE)
535
+ if (sizeMatch) {
536
+ result['background-size'] = sizeMatch.join(' ')
537
+ }
538
+ }
539
+
540
+ return result
541
+ }
542
+
543
+ function setBackgroundRepeat(hmStyle, value) {
544
+ if (typeof value === 'string') {
545
+ switch (value) {
546
+ case 'repeat-x': hmStyle.backgroundRepeat = ImageRepeat.X; break
547
+ case 'repeat-y': hmStyle.backgroundRepeat = ImageRepeat.Y; break
548
+ case 'no-repeat': hmStyle.backgroundRepeat = ImageRepeat.NoRepeat; break
549
+ default: hmStyle.backgroundRepeat = ImageRepeat.XY; break
550
+ }
551
+ }
552
+ }
553
+
554
+ function setBackgroundSize(hmStyle, value) {
555
+ if (typeof value === 'string') {
556
+ if (value === 'cover') {
557
+ hmStyle.backgroundSize = ImageSize.Cover
558
+ return
559
+ } else if (value === 'contain') {
560
+ hmStyle.backgroundSize = ImageSize.Contain
561
+ return
562
+ }
563
+ const sizes = value.split(' ')
564
+ if (sizes.length === 1) {
565
+ hmStyle.backgroundSize = { width: getUnit(sizes[0]) }
566
+ } else if (sizes.length === 2) {
567
+ hmStyle.backgroundSize = { width: getUnit(sizes[0]), height: getUnit(sizes[1]) }
568
+ }
569
+ }
570
+ }
571
+
572
+ function setBackgroundPosistion (hmStyle, value) {
573
+ if (typeof value === 'string') {
574
+ const positions = value.split(' ')
575
+ const horizontal = positions[0].toLowerCase()
576
+ const vertical = positions[1]?.toLowerCase() || 'top'
577
+
578
+ if (horizontal === 'left' && vertical === 'top') {
579
+ hmStyle.backgroundPosition = Alignment.TopStart
580
+ } else if (horizontal === 'center' && vertical === 'top') {
581
+ hmStyle.backgroundPosition = Alignment.Top
582
+ } else if (horizontal === 'right' && vertical === 'top') {
583
+ hmStyle.backgroundPosition = Alignment.TopEnd
584
+ } else if (horizontal === 'left' && vertical === 'center') {
585
+ hmStyle.backgroundPosition = Alignment.Start
586
+ } else if (horizontal === 'center' && vertical === 'center') {
587
+ hmStyle.backgroundPosition = Alignment.Center
588
+ } else if (horizontal === 'right' && vertical === 'center') {
589
+ hmStyle.backgroundPosition = Alignment.End
590
+ } else if (horizontal === 'left' && vertical === 'bottom') {
591
+ hmStyle.backgroundPosition = Alignment.BottomStart
592
+ } else if (horizontal === 'center' && vertical === 'bottom') {
593
+ hmStyle.backgroundPosition = Alignment.Bottom
594
+ } else if (horizontal === 'right' && vertical === 'bottom') {
595
+ hmStyle.backgroundPosition = Alignment.BottomEnd
596
+ } else {
597
+ if (/^\d+(\.\d+)?(px|%|vw|vh)$/.test(horizontal)) {
598
+ hmStyle.backgroundPosition = { x: getUnit(horizontal) }
599
+ if (/^\d+(\.\d+)?(px|%|vw|vh)$/.test(vertical)) {
600
+ hmStyle.backgroundPosition = { x: getUnit(horizontal), y: getUnit(vertical) }
601
+ }
602
+ }
603
+ }
604
+ }
605
+ }
606
+
607
+ function setFontWeight (hmStyle, value) {
608
+ switch (value) {
609
+ case 'normal': hmStyle.fontWeight = FontWeight.Normal; break
610
+ case 'bold': hmStyle.fontWeight = FontWeight.Bold; break
611
+ case 'bolder': hmStyle.fontWeight = FontWeight.Bolder; break
612
+ case 'lighter': hmStyle.fontWeight = FontWeight.Lighter; break
613
+ default: hmStyle.fontWeight = Number(value); break
614
+ }
615
+ }
616
+
617
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
618
+ function parseTransform(transformString) {
619
+ const transformRegex = /(\w+)\(([^)]+)\)/g
620
+ const transform = {}
621
+
622
+ let matchs
623
+ while ((matchs = transformRegex.exec(transformString)) !== null) {
624
+ const [, type, valueString] = matchs
625
+ const values = valueString.split(/\s*,\s*/)
626
+
627
+ const transformObj = {
628
+ type: capitalizeFirstLetter(type),
629
+ value: {}
630
+ }
631
+
632
+ switch (type) {
633
+ case 'translate':
634
+ case 'translate3d':
635
+ transformObj.value.x = (getUnit(values[0])) || 0
636
+ transformObj.value.y = (getUnit(values[1])) || 0
637
+ transformObj.value.z = (getUnit(values[2])) || 0
638
+ break
639
+ case 'translateX':
640
+ transformObj.value.x = (getUnit(values[0])) || 0
641
+ break
642
+ case 'translateY':
643
+ transformObj.value.y = (getUnit(values[0])) || 0
644
+ break
645
+ case 'translateZ':
646
+ transformObj.value.z = (getUnit(values[0])) || 0
647
+ break
648
+ case 'rotate':
649
+ case 'rotateZ':
650
+ transformObj.value.angle = (getUnit(values[0])) || 0
651
+ transformObj.value.x = 0
652
+ transformObj.value.y = 0
653
+ transformObj.value.z = 1
654
+ break
655
+ case 'rotate3d':
656
+ transformObj.value.angle = getUnit(values[0]) || 0
657
+ transformObj.value.x = values[1] || 0
658
+ transformObj.value.y = values[2] || 0
659
+ transformObj.value.z = values[3] || 0
660
+ break
661
+ case 'rotateX':
662
+ transformObj.value.angle = getUnit(values[0]) || 0
663
+ transformObj.value.x = 1
664
+ transformObj.value.y = 0
665
+ transformObj.value.z = 0
666
+ break
667
+ case 'rotateY':
668
+ transformObj.value.angle = getUnit(values[0]) || 0
669
+ transformObj.value.x = 0
670
+ transformObj.value.y = 1
671
+ transformObj.value.z = 0
672
+ break
673
+ case 'scale':
674
+ case 'scale3d':
675
+ transformObj.value.x = parseFloat(values[0]) || 1
676
+ transformObj.value.y = parseFloat(values[1] || values[0]) || 1
677
+ transformObj.value.z = parseFloat(values[2]) || 1
678
+ break
679
+ case 'scaleX':
680
+ transformObj.value.x = parseFloat(values[0]) || 1
681
+ break
682
+ case 'scaleY':
683
+ transformObj.value.y = parseFloat(values[0]) || 1
684
+ break
685
+ default:
686
+ // Handle unrecognized transform types or ignore them
687
+ break
688
+ }
689
+
690
+ transform[transformObj.type] = transformObj.value
691
+ }
692
+
693
+ return transform
694
+ }
695
+
696
+ // 方向转百分比
697
+ function directionToPercent(direction: string) {
698
+ switch (direction) {
699
+ case 'top':
700
+ case 'left':
701
+ return '0%'
702
+ case 'center':
703
+ return '50%'
704
+ case 'bottom':
705
+ case 'right':
706
+ return '100%'
707
+ default:
708
+ return direction
709
+ }
710
+ }
711
+
712
+ // 解析transform-orgin
713
+ function parseTransformOrigin (value: string) {
714
+ if (typeof value === 'string') {
715
+ const values = value.split(' ')
716
+ if (values.length === 1) {
717
+ return {
718
+ x: getUnit(directionToPercent(values[0])),
719
+ y: getUnit(directionToPercent(values[0]))
720
+ }
721
+ } else if (values.length === 2) {
722
+ return {
723
+ x: getUnit(directionToPercent(values[0])),
724
+ y: getUnit(directionToPercent(values[1]))
725
+ }
726
+ }
727
+ }
728
+ return {
729
+ x: 0,
730
+ y: 0
731
+ }
732
+ }
733
+
734
+ function directionToAngle(direction) {
735
+ const map = {
736
+ 'to top': 270,
737
+ 'to bottom': 90,
738
+ 'to left': 180,
739
+ 'to right': 0,
740
+ 'to top left': 225,
741
+ 'to left top': 225,
742
+ 'to top right': 315,
743
+ 'to right top': 315,
744
+ 'to bottom left': 135,
745
+ 'to left bottom': 135,
746
+ 'to bottom right': 45,
747
+ 'to right bottom': 45
748
+ }
749
+ return map[direction.toLowerCase()] || 0 // 默认为0度(to right)
750
+ }
751
+
752
+ function parseGradient(gradientString) {
753
+ const directionPattern = /linear-gradient\((to [a-z ]+|\d+deg),/
754
+ const directionMatch = gradientString.match(directionPattern)
755
+ let angle
756
+
757
+ if (directionMatch) {
758
+ const direction = directionMatch[1]
759
+ if (direction.includes('deg')) {
760
+ angle = parseInt(direction, 10)
761
+ } else {
762
+ angle = directionToAngle(direction)
763
+ }
764
+ } else {
765
+ angle = 0 // 默认方向为向右(0度)
766
+ }
767
+ const colorPattern = /(?:(#[0-9a-f]{3,8}|rgba?\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*(?:,\s*\d*\.?\d+\s*)?\)))\s*(\d*%|)/gi
768
+ const colors = []
769
+ let match
770
+ while ((match = colorPattern.exec(gradientString)) !== null) {
771
+ const color = match[1] ? match[1].trim() : null
772
+ const position = match[2] ? parseInt(match[2], 10) / 100 : null
773
+ colors.push([color, position])
774
+ }
775
+
776
+ if (colors.some(color => color[1] === null)) {
777
+ const step = 1 / (colors.length - 1)
778
+ colors.forEach((color, index) => (color[1] = index * step))
779
+ }
780
+
781
+ return {
782
+ angle: angle,
783
+ colors: colors
784
+ }
785
+ }
786
+
787
+ function rgbaToHex(rgba) {
788
+ const parts = rgba.match(/rgba?\((\d+),\s*(\d+),\s*(\d+),?\s*(\d*\.?\d+)?\)/)
789
+ if (!parts) return rgba // 如果匹配失败,返回原字符串
790
+
791
+ const r = parseInt(parts[1]).toString(16).padStart(2, '0')
792
+ const g = parseInt(parts[2]).toString(16).padStart(2, '0')
793
+ const b = parseInt(parts[3]).toString(16).padStart(2, '0')
794
+ if (parts[4]) {
795
+ const a = parts[4] ? Math.round(parseFloat(parts[4]) * 255).toString(16).padStart(2, '0') : 'ff'
796
+ return `#${a}${r}${g}${b}`
797
+ } else {
798
+ return `#${r}${g}${b}`
799
+ }
800
+ }
801
+ function preprocessCss(css) {
802
+ return css.replace(/rgba?\((\d+\s*,\s*\d+\s*,\s*\d+\s*,?\s*\d*\.?\d*)\)/g, (match) => {
803
+ return rgbaToHex(match)
804
+ })
805
+ }