@tarojs/plugin-platform-harmony-ets 4.0.0-beta.5 → 4.0.0-beta.50

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 (122) hide show
  1. package/dist/apis/base/system.ts +53 -20
  2. package/dist/apis/canvas/index.ts +10 -1
  3. package/dist/apis/device/clipboard.ts +4 -0
  4. package/dist/apis/framework/index.ts +1 -5
  5. package/dist/apis/index.ts +27 -17
  6. package/dist/apis/network/request.ts +5 -5
  7. package/dist/apis/route/index.ts +15 -0
  8. package/dist/apis/storage/index.ts +148 -80
  9. package/dist/apis/ui/animation/animation.ts +71 -28
  10. package/dist/apis/ui/background.ts +2 -1
  11. package/dist/apis/ui/interaction/index.ts +40 -49
  12. package/dist/apis/ui/navigation-bar/index.ts +1 -1
  13. package/dist/apis/utils/index.ts +1 -1
  14. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  15. package/dist/apis/wxml/index.ts +2 -0
  16. package/dist/apis/wxml/selectorQuery.ts +18 -9
  17. package/dist/components-harmony-ets/button.ets +48 -34
  18. package/dist/components-harmony-ets/canvas.ets +51 -0
  19. package/dist/components-harmony-ets/checkbox.ets +69 -61
  20. package/dist/components-harmony-ets/form.ets +51 -29
  21. package/dist/components-harmony-ets/icon.ets +31 -19
  22. package/dist/components-harmony-ets/image.ets +27 -14
  23. package/dist/components-harmony-ets/index.ets +85 -0
  24. package/dist/components-harmony-ets/innerHtml.ets +11 -6
  25. package/dist/components-harmony-ets/input.ets +41 -40
  26. package/dist/components-harmony-ets/label.ets +69 -42
  27. package/dist/components-harmony-ets/movableArea.ets +126 -0
  28. package/dist/components-harmony-ets/movableView.ets +73 -0
  29. package/dist/components-harmony-ets/navigationBar.ets +25 -0
  30. package/dist/components-harmony-ets/pageMeta.ets +28 -0
  31. package/dist/components-harmony-ets/picker.ets +42 -38
  32. package/dist/components-harmony-ets/progress.ets +52 -0
  33. package/dist/components-harmony-ets/pseudo.ets +80 -0
  34. package/dist/components-harmony-ets/radio.ets +71 -64
  35. package/dist/components-harmony-ets/richText.ets +14 -30
  36. package/dist/components-harmony-ets/scrollView.ets +61 -57
  37. package/dist/components-harmony-ets/slider.ets +15 -14
  38. package/dist/components-harmony-ets/style.ets +390 -130
  39. package/dist/components-harmony-ets/swiper.ets +38 -20
  40. package/dist/components-harmony-ets/switch.ets +30 -28
  41. package/dist/components-harmony-ets/{index.ts → tag.ts} +2 -0
  42. package/dist/components-harmony-ets/text.ets +121 -51
  43. package/dist/components-harmony-ets/textArea.ets +35 -34
  44. package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
  45. package/dist/components-harmony-ets/utils/DynamicCenter.ts +1 -1
  46. package/dist/components-harmony-ets/utils/flexManager.ets +47 -19
  47. package/dist/components-harmony-ets/utils/helper.ets +17 -5
  48. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  49. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  50. package/dist/components-harmony-ets/utils/index.ts +50 -51
  51. package/dist/components-harmony-ets/utils/styles.ets +170 -93
  52. package/dist/components-harmony-ets/video.ets +34 -20
  53. package/dist/components-harmony-ets/view.ets +63 -52
  54. package/dist/components-harmony-ets/webView.ets +40 -34
  55. package/dist/index.d.ts +152 -0
  56. package/dist/index.js +82 -39
  57. package/dist/index.js.map +1 -1
  58. package/dist/runtime-ets/bom/document.ts +6 -4
  59. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
  60. package/dist/runtime-ets/bom/window.ts +7 -0
  61. package/dist/runtime-ets/current.ts +3 -0
  62. package/dist/runtime-ets/dom/bind.ts +31 -13
  63. package/dist/runtime-ets/dom/cssNesting.ts +393 -0
  64. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +25 -39
  65. package/dist/runtime-ets/dom/document.ts +22 -8
  66. package/dist/runtime-ets/dom/element/canvas.ts +136 -0
  67. package/dist/runtime-ets/dom/element/element.ts +317 -51
  68. package/dist/runtime-ets/dom/element/form.ts +23 -26
  69. package/dist/runtime-ets/dom/element/index.ts +24 -2
  70. package/dist/runtime-ets/dom/element/movableArea.ts +12 -0
  71. package/dist/runtime-ets/dom/element/movableView.ts +193 -0
  72. package/dist/runtime-ets/dom/element/normal.ts +35 -8
  73. package/dist/runtime-ets/dom/element/progress.ts +12 -0
  74. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  75. package/dist/runtime-ets/dom/element/text.ts +1 -8
  76. package/dist/runtime-ets/dom/element/video.ts +5 -3
  77. package/dist/runtime-ets/dom/element/webView.ts +11 -3
  78. package/dist/runtime-ets/dom/event.ts +0 -1
  79. package/dist/runtime-ets/dom/eventTarget.ts +0 -3
  80. package/dist/runtime-ets/dom/node.ts +46 -28
  81. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +334 -230
  82. package/dist/runtime-ets/dom/stylesheet/index.ts +28 -308
  83. package/dist/runtime-ets/dom/stylesheet/type.ts +40 -9
  84. package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
  85. package/dist/runtime-ets/index.ts +2 -2
  86. package/dist/runtime-ets/interface/event.ts +1 -1
  87. package/dist/runtime-ets/utils/index.ts +66 -11
  88. package/dist/runtime-ets/utils/info.ts +1 -1
  89. package/dist/runtime-framework/react/app.ts +7 -2
  90. package/dist/runtime-framework/react/index.ts +0 -2
  91. package/dist/runtime-framework/react/native-page.ts +32 -14
  92. package/dist/runtime-framework/react/page.ts +3 -8
  93. package/dist/runtime-framework/solid/app.ts +25 -45
  94. package/dist/runtime-framework/solid/connect.ts +21 -3
  95. package/dist/runtime-framework/solid/hooks.ts +16 -11
  96. package/dist/runtime-framework/solid/index.ts +6 -2
  97. package/dist/runtime-framework/solid/page.ts +84 -30
  98. package/dist/runtime-framework/solid/reconciler/props.ts +65 -20
  99. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  100. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  101. package/dist/runtime-framework/solid/utils/index.ts +0 -2
  102. package/dist/runtime-utils.d.ts +827 -0
  103. package/dist/runtime-utils.js +399 -188
  104. package/dist/runtime-utils.js.map +1 -1
  105. package/dist/runtime.d.ts +1 -0
  106. package/dist/runtime.js +399 -188
  107. package/dist/runtime.js.map +1 -1
  108. package/index.js +3 -1
  109. package/package.json +13 -13
  110. package/static/media/cancel.svg +1 -1
  111. package/static/media/circle.svg +1 -1
  112. package/static/media/clear.svg +1 -1
  113. package/static/media/download.svg +1 -1
  114. package/static/media/info.svg +1 -1
  115. package/static/media/info_circle.svg +1 -1
  116. package/static/media/search.svg +1 -1
  117. package/static/media/success.svg +1 -1
  118. package/static/media/success_no_circle.svg +1 -1
  119. package/static/media/warn.svg +1 -1
  120. package/types/harmony.d.ts +4 -0
  121. package/types/index.d.ts +4 -0
  122. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
@@ -2,141 +2,86 @@
2
2
 
3
3
  import { CSSProperties } from 'react'
4
4
 
5
+ import { TaroElement } from '../element/element'
5
6
  import { BORDER_STYLE_MAP, capitalizeFirstLetter, FlexManager, getNodeMarginOrPaddingData, getUnit } from './util'
6
7
 
7
- export const WEB_STYLE_MAP = {
8
- padding: ['_paddingTop', '_paddingRight', '_paddingBottom', '_paddingLeft'],
9
- paddingTop: ['_paddingTop'],
10
- paddingRight: ['_paddingRight'],
11
- paddingBottom: ['_paddingBottom'],
12
- paddingLeft: ['_paddingLeft'],
13
- margin: ['_marginTop', '_marginRight', '_marginBottom', '_marginLeft'],
14
- marginTop: ['_marginTop'],
15
- marginRight: ['_marginRight'],
16
- marginBottom: ['_marginBottom'],
17
- marginLeft: ['_marginLeft'],
18
- top: ['_top'],
19
- left: ['_left'],
20
- flex: ['_flexGrow', '_flexShrink', '_flexBasis'],
21
- flexGrow: ['_flexGrow'],
22
- flexShrink: ['_flexShrink'],
23
- flexBasis: ['_flexBasis'],
24
- alignSelf: ['_alignSelf'],
25
- flexDirection: ['_flexDirection'],
26
- justifyContent: ['_justifyContent'],
27
- alignItems: ['_alignItems'],
28
- alignContent: ['_alignContent'],
29
- flexWrap: ['_flexWrap'],
30
- width: ['_width'],
31
- height: ['_height'],
32
- minWidth: ['_minWidth'],
33
- minHeight: ['_minHeight'],
34
- maxWidth: ['_maxWidth'],
35
- maxHeight: ['_maxHeight'],
36
- background: ['_backgroundColor', '_backgroundImage', '_backgroundRepeat', '_backgroundSize', '_backgroundPosition'],
37
- backgroundColor: ['_backgroundColor'],
38
- backgroundImage: ['_backgroundImage'],
39
- backgroundRepeat: ['_backgroundRepeat'],
40
- backgroundSize: ['_backgroundSize'],
41
- backgroundPosition: ['_backgroundPosition'],
42
- border: ['_borderTopWidth', '_borderRightWidth', '_borderBottomWidth', '_borderLeftWidth', '_borderTopStyle', '_borderRightStyle', '_borderBottomStyle', '_borderLeftStyle', '_borderTopColor', '_borderRightColor', '_borderBottomColor', '_borderLeftColor'],
43
- borderTop: ['_borderTopWidth', '_borderTopStyle', '_borderTopColor'],
44
- borderRight: ['_borderRightWidth', '_borderRightStyle', '_borderRightColor'],
45
- borderBottom: ['_borderBottomWidth', '_borderBottomStyle', '_borderBottomColor'],
46
- borderLeft: ['_borderLeftWidth', '_borderLeftStyle', '_borderLeftColor'],
47
- borderWidth: ['_borderTopWidth', '_borderRightWidth', '_borderBottomWidth', '_borderLeftWidth'],
48
- borderLeftWidth: ['_borderLeftWidth'],
49
- borderRightWidth: ['_borderRightWidth'],
50
- borderTopWidth: ['_borderTopWidth'],
51
- borderBottomWidth: ['_borderBottomWidth'],
52
- borderStyle: ['_borderTopStyle', '_borderRightStyle', '_borderBottomStyle', '_borderLeftStyle'],
53
- borderLeftStyle: ['_borderLeftStyle'],
54
- borderRightStyle: ['_borderRightStyle'],
55
- borderTopStyle: ['_borderTopStyle'],
56
- borderBottomStyle: ['_borderBottomStyle'],
57
- borderColor: ['_borderTopColor', '_borderRightColor', '_borderBottomColor', '_borderLeftColor'],
58
- borderLeftColor: ['_borderLeftColor'],
59
- borderRightColor: ['_borderRightColor'],
60
- borderTopColor: ['_borderTopColor'],
61
- borderBottomColor: ['_borderBottomColor'],
62
- borderRadius: ['_borderTopLeftRadius', '_borderTopRightRadius', '_borderBottomLeftRadius', '_borderBottomRightRadius'],
63
- borderTopLeftRadius: ['_borderTopLeftRadius'],
64
- borderTopRightRadius: ['_borderTopRightRadius'],
65
- borderBottomLeftRadius: ['_borderBottomLeftRadius'],
66
- borderBottomRightRadius: ['_borderBottomRightRadius'],
67
- color: ['_color'],
68
- fontSize: ['_fontSize'],
69
- fontWeight: ['_fontWeight'],
70
- fontStyle: ['_fontStyle'],
71
- textAlign: ['_textAlign'],
72
- lineHeight: ['_lineHeight'],
73
- letterSpacing: ['_letterSpacing'],
74
- textDecoration: ['_textDecoration'],
75
- textOverflow: ['_textOverflow'],
76
- WebkitLineClamp: ['_WebkitLineClamp'],
77
- transform: ['_transform']
8
+ // 背景解析正则
9
+ const BACKGROUND_REGEX = {
10
+ IMAGE: /url\((['"])?(.*?)\1\)|(linear|radial)-gradient\([^)]*\)/,
11
+ COLOR: /(#[0-9a-fA-F]{3,6}|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
78
15
  }
79
16
 
80
- // 将web端的style转换为hm端的style
81
- export default function convertWebStyle2HmStyle(webStyle: CSSProperties) {
82
- const hmStyle: Record<string, any> = {}
17
+ // Note: web 端的 style 转换为 hm 端的 style
18
+ export default function convertWebStyle2HmStyle(webStyle: CSSProperties, node?: TaroElement) {
19
+ const hmStyle: Record<string, any> = node?._st?.hmStyle || {}
83
20
  Object.keys(webStyle).forEach((key) => {
84
21
  const value = webStyle[key]
85
22
  switch (key) {
86
23
  case 'padding': {
87
24
  const { top, bottom, left, right } = getNodeMarginOrPaddingData(value)
88
- hmStyle._paddingTop = top
89
- hmStyle._paddingBottom = bottom
90
- hmStyle._paddingLeft = left
91
- hmStyle._paddingRight = right
25
+ hmStyle.paddingTop = top
26
+ hmStyle.paddingBottom = bottom
27
+ hmStyle.paddingLeft = left
28
+ hmStyle.paddingRight = right
92
29
  break
93
30
  }
94
31
  case 'paddingTop': {
95
- hmStyle._paddingTop = getUnit(value)
32
+ hmStyle.paddingTop = getUnit(value)
96
33
  break
97
34
  }
98
35
  case 'paddingBottom': {
99
- hmStyle._paddingBottom = getUnit(value)
36
+ hmStyle.paddingBottom = getUnit(value)
100
37
  break
101
38
  }
102
39
  case 'paddingLeft': {
103
- hmStyle._paddingLeft = getUnit(value)
40
+ hmStyle.paddingLeft = getUnit(value)
104
41
  break
105
42
  }
106
43
  case 'paddingRight': {
107
- hmStyle._paddingRight = getUnit(value)
44
+ hmStyle.paddingRight = getUnit(value)
108
45
  break
109
46
  }
110
47
  case 'margin': {
111
48
  const { top, bottom, left, right } = getNodeMarginOrPaddingData(value)
112
- hmStyle._marginTop = top
113
- hmStyle._marginBottom = bottom
114
- hmStyle._marginLeft = left
115
- hmStyle._marginRight = right
49
+ hmStyle.marginTop = top
50
+ hmStyle.marginBottom = bottom
51
+ hmStyle.marginLeft = left
52
+ hmStyle.marginRight = right
116
53
  break
117
54
  }
118
55
  case 'marginTop': {
119
- hmStyle._marginTop = getUnit(value)
56
+ hmStyle.marginTop = getUnit(value)
120
57
  break
121
58
  }
122
59
  case 'marginBottom': {
123
- hmStyle._marginBottom = getUnit(value)
60
+ hmStyle.marginBottom = getUnit(value)
124
61
  break
125
62
  }
126
63
  case 'marginLeft': {
127
- hmStyle._marginLeft = getUnit(value)
64
+ hmStyle.marginLeft = getUnit(value)
128
65
  break
129
66
  }
130
67
  case 'marginRight': {
131
- hmStyle._marginRight = getUnit(value)
68
+ hmStyle.marginRight = getUnit(value)
132
69
  break
133
70
  }
134
71
  case 'top': {
135
- hmStyle._top = getUnit(value)
72
+ hmStyle.top = getUnit(value)
136
73
  break
137
74
  }
138
75
  case 'left': {
139
- hmStyle._left = getUnit(value)
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)
140
85
  break
141
86
  }
142
87
  case 'flex': {
@@ -153,77 +98,82 @@ export default function convertWebStyle2HmStyle(webStyle: CSSProperties) {
153
98
  res[index] = index < 2 ? Number(item) : item
154
99
  })
155
100
  }
156
- hmStyle._flexGrow = getUnit(res[0])
157
- hmStyle._flexShrink = Number(res[1])
158
- hmStyle._flexBasis = Number(res[2])
101
+ hmStyle.flexGrow = getUnit(res[0])
102
+ hmStyle.flexShrink = Number(res[1])
103
+ hmStyle.flexBasis = Number(res[2])
159
104
  break
160
105
  }
161
106
  case 'flexGrow': {
162
- hmStyle._flexGrow = getUnit(value)
107
+ hmStyle.flexGrow = getUnit(value)
163
108
  break
164
109
  }
165
110
  case 'flexShrink': {
166
- hmStyle._flexShrink = Number(value)
111
+ hmStyle.flexShrink = Number(value)
167
112
  break
168
113
  }
169
114
  case 'flexBasis': {
170
- hmStyle._flexBasis = Number(value)
115
+ hmStyle.flexBasis = Number(value)
171
116
  break
172
117
  }
173
118
  case 'alignSelf': {
174
- hmStyle._alignSelf = FlexManager.itemAlign(value)
119
+ hmStyle.alignSelf = FlexManager.itemAlign(value)
175
120
  break
176
121
  }
177
122
  case 'flexDirection': {
178
- hmStyle._flexDirection = FlexManager.direction(value)
123
+ hmStyle.flexDirection = FlexManager.direction(value)
179
124
  break
180
125
  }
181
126
  case 'justifyContent': {
182
- hmStyle._justifyContent = FlexManager.flexAlign(value)
127
+ hmStyle.justifyContent = FlexManager.flexAlign(value)
183
128
  break
184
129
  }
185
130
  case 'alignItems': {
186
- hmStyle._alignItems = FlexManager.itemAlign(value)
131
+ hmStyle.alignItems = FlexManager.itemAlign(value)
187
132
  break
188
133
  }
189
134
  case 'alignContent': {
190
- hmStyle._alignContent = FlexManager.flexAlign(value)
135
+ hmStyle.alignContent = FlexManager.flexAlign(value)
191
136
  break
192
137
  }
193
138
  case 'flexWrap': {
194
- hmStyle._flexWrap = FlexManager.flexWrap(value)
139
+ hmStyle.flexWrap = FlexManager.flexWrap(value)
195
140
  break
196
141
  }
197
142
  case 'width': {
198
- hmStyle._width = getUnit(value)
143
+ hmStyle.width = getUnit(value)
199
144
  break
200
145
  }
201
146
  case 'height': {
202
- hmStyle._height = getUnit(value)
147
+ hmStyle.height = getUnit(value)
203
148
  break
204
149
  }
205
150
  case 'minWidth': {
206
- hmStyle._minWidth = getUnit(value)
151
+ hmStyle.minWidth = getUnit(value)
207
152
  break
208
153
  }
209
154
  case 'minHeight': {
210
- hmStyle._minHeight = getUnit(value)
155
+ hmStyle.minHeight = getUnit(value)
211
156
  break
212
157
  }
213
158
  case 'maxWidth': {
214
- hmStyle._maxWidth = getUnit(value)
159
+ hmStyle.maxWidth = getUnit(value)
215
160
  break
216
161
  }
217
162
  case 'maxHeight': {
218
- hmStyle._maxHeight = getUnit(value)
163
+ hmStyle.maxHeight = getUnit(value)
219
164
  break
220
165
  }
221
166
  case 'background': {
222
- // TODO: 暂未实现
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'])
223
173
  break
224
174
  }
225
175
  case 'backgroundColor': {
226
- hmStyle._backgroundColor = value
176
+ hmStyle.backgroundColor = value
227
177
  break
228
178
  }
229
179
  case 'backgroundImage': {
@@ -244,146 +194,146 @@ export default function convertWebStyle2HmStyle(webStyle: CSSProperties) {
244
194
  }
245
195
  case 'border': {
246
196
  const [width, style, color] = value.split(' ')
247
- hmStyle._borderTopWidth = getUnit(width)
248
- hmStyle._borderRightWidth = getUnit(width)
249
- hmStyle._borderBottomWidth = getUnit(width)
250
- hmStyle._borderLeftWidth = getUnit(width)
251
- hmStyle._borderTopStyle = BORDER_STYLE_MAP.get(style)
252
- hmStyle._borderRightStyle = BORDER_STYLE_MAP.get(style)
253
- hmStyle._borderBottomStyle = BORDER_STYLE_MAP.get(style)
254
- hmStyle._borderLeftStyle = BORDER_STYLE_MAP.get(style)
255
- hmStyle._borderTopColor = color
256
- hmStyle._borderRightColor = color
257
- hmStyle._borderBottomColor = color
258
- hmStyle._borderLeftColor = color
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
259
209
  break
260
210
  }
261
211
  case 'borderTop': {
262
212
  const [width, style, color] = value.split(' ')
263
- hmStyle._borderTopWidth = getUnit(width)
264
- hmStyle._borderTopStyle = BORDER_STYLE_MAP.get(style)
265
- hmStyle._borderTopColor = color
213
+ hmStyle.borderTopWidth = getUnit(width)
214
+ hmStyle.borderTopStyle = BORDER_STYLE_MAP.get(style)
215
+ hmStyle.borderTopColor = color
266
216
  break
267
217
  }
268
218
  case 'borderRight': {
269
219
  const [width, style, color] = value.split(' ')
270
- hmStyle._borderRightWidth = getUnit(width)
271
- hmStyle._borderRightStyle = BORDER_STYLE_MAP.get(style)
272
- hmStyle._borderRightColor = color
220
+ hmStyle.borderRightWidth = getUnit(width)
221
+ hmStyle.borderRightStyle = BORDER_STYLE_MAP.get(style)
222
+ hmStyle.borderRightColor = color
273
223
  break
274
224
  }
275
225
  case 'borderBottom': {
276
226
  const [width, style, color] = value.split(' ')
277
- hmStyle._borderBottomWidth = getUnit(width)
278
- hmStyle._borderBottomStyle = BORDER_STYLE_MAP.get(style)
279
- hmStyle._borderBottomColor = color
227
+ hmStyle.borderBottomWidth = getUnit(width)
228
+ hmStyle.borderBottomStyle = BORDER_STYLE_MAP.get(style)
229
+ hmStyle.borderBottomColor = color
280
230
  break
281
231
  }
282
232
  case 'borderLeft': {
283
233
  const [width, style, color] = value.split(' ')
284
- hmStyle._borderLeftWidth = getUnit(width)
285
- hmStyle._borderLeftStyle = BORDER_STYLE_MAP.get(style)
286
- hmStyle._borderLeftColor = color
234
+ hmStyle.borderLeftWidth = getUnit(width)
235
+ hmStyle.borderLeftStyle = BORDER_STYLE_MAP.get(style)
236
+ hmStyle.borderLeftColor = color
287
237
  break
288
238
  }
289
239
  case 'borderWidth': {
290
- hmStyle._borderTopWidth = getUnit(value)
291
- hmStyle._borderRightWidth = getUnit(value)
292
- hmStyle._borderBottomWidth = getUnit(value)
293
- hmStyle._borderLeftWidth = getUnit(value)
240
+ hmStyle.borderTopWidth = getUnit(value)
241
+ hmStyle.borderRightWidth = getUnit(value)
242
+ hmStyle.borderBottomWidth = getUnit(value)
243
+ hmStyle.borderLeftWidth = getUnit(value)
294
244
  break
295
245
  }
296
246
  case 'borderLeftWidth': {
297
- hmStyle._borderLeftWidth = getUnit(value)
247
+ hmStyle.borderLeftWidth = getUnit(value)
298
248
  break
299
249
  }
300
250
  case 'borderRightWidth': {
301
- hmStyle._borderRightWidth = getUnit(value)
251
+ hmStyle.borderRightWidth = getUnit(value)
302
252
  break
303
253
  }
304
254
  case 'borderTopWidth': {
305
- hmStyle._borderTopWidth = getUnit(value)
255
+ hmStyle.borderTopWidth = getUnit(value)
306
256
  break
307
257
  }
308
258
  case 'borderBottomWidth': {
309
- hmStyle._borderBottomWidth = getUnit(value)
259
+ hmStyle.borderBottomWidth = getUnit(value)
310
260
  break
311
261
  }
312
262
  case 'borderStyle': {
313
- hmStyle._borderTopStyle = BORDER_STYLE_MAP.get(value)
314
- hmStyle._borderRightStyle = BORDER_STYLE_MAP.get(value)
315
- hmStyle._borderBottomStyle = BORDER_STYLE_MAP.get(value)
316
- hmStyle._borderLeftStyle = BORDER_STYLE_MAP.get(value)
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)
317
267
  break
318
268
  }
319
269
  case 'borderLeftStyle': {
320
- hmStyle._borderLeftStyle = BORDER_STYLE_MAP.get(value)
270
+ hmStyle.borderLeftStyle = BORDER_STYLE_MAP.get(value)
321
271
  break
322
272
  }
323
273
  case 'borderRightStyle': {
324
- hmStyle._borderRightStyle = BORDER_STYLE_MAP.get(value)
274
+ hmStyle.borderRightStyle = BORDER_STYLE_MAP.get(value)
325
275
  break
326
276
  }
327
277
  case 'borderTopStyle': {
328
- hmStyle._borderTopStyle = BORDER_STYLE_MAP.get(value)
278
+ hmStyle.borderTopStyle = BORDER_STYLE_MAP.get(value)
329
279
  break
330
280
  }
331
281
  case 'borderBottomStyle': {
332
- hmStyle._borderBottomStyle = BORDER_STYLE_MAP.get(value)
282
+ hmStyle.borderBottomStyle = BORDER_STYLE_MAP.get(value)
333
283
  break
334
284
  }
335
285
  case 'borderColor': {
336
- hmStyle._borderTopColor = value
337
- hmStyle._borderRightColor = value
338
- hmStyle._borderBottomColor = value
339
- hmStyle._borderLeftColor = value
286
+ hmStyle.borderTopColor = value
287
+ hmStyle.borderRightColor = value
288
+ hmStyle.borderBottomColor = value
289
+ hmStyle.borderLeftColor = value
340
290
  break
341
291
  }
342
292
  case 'borderLeftColor': {
343
- hmStyle._borderLeftColor = value
293
+ hmStyle.borderLeftColor = value
344
294
  break
345
295
  }
346
296
  case 'borderRightColor': {
347
- hmStyle._borderRightColor = value
297
+ hmStyle.borderRightColor = value
348
298
  break
349
299
  }
350
300
  case 'borderTopColor': {
351
- hmStyle._borderTopColor = value
301
+ hmStyle.borderTopColor = value
352
302
  break
353
303
  }
354
304
  case 'borderBottomColor': {
355
- hmStyle._borderBottomColor = value
305
+ hmStyle.borderBottomColor = value
356
306
  break
357
307
  }
358
308
  case 'borderRadius': {
359
- hmStyle._borderTopLeftRadius = getUnit(value)
360
- hmStyle._borderTopRightRadius = getUnit(value)
361
- hmStyle._borderBottomLeftRadius = getUnit(value)
362
- hmStyle._borderBottomRightRadius = getUnit(value)
309
+ hmStyle.borderTopLeftRadius = getUnit(value)
310
+ hmStyle.borderTopRightRadius = getUnit(value)
311
+ hmStyle.borderBottomLeftRadius = getUnit(value)
312
+ hmStyle.borderBottomRightRadius = getUnit(value)
363
313
  break
364
314
  }
365
315
  case 'borderTopLeftRadius': {
366
- hmStyle._borderTopLeftRadius = getUnit(value)
316
+ hmStyle.borderTopLeftRadius = getUnit(value)
367
317
  break
368
318
  }
369
319
  case 'borderTopRightRadius': {
370
- hmStyle._borderTopRightRadius = getUnit(value)
320
+ hmStyle.borderTopRightRadius = getUnit(value)
371
321
  break
372
322
  }
373
323
  case 'borderBottomLeftRadius': {
374
- hmStyle._borderBottomLeftRadius = getUnit(value)
324
+ hmStyle.borderBottomLeftRadius = getUnit(value)
375
325
  break
376
326
  }
377
327
  case 'borderBottomRightRadius': {
378
- hmStyle._borderBottomRightRadius = getUnit(value)
328
+ hmStyle.borderBottomRightRadius = getUnit(value)
379
329
  break
380
330
  }
381
331
  case 'color': {
382
- hmStyle._color = value
332
+ hmStyle.color = value
383
333
  break
384
334
  }
385
335
  case 'fontSize': {
386
- hmStyle._fontSize = getUnit(value)
336
+ hmStyle.fontSize = getUnit(value)
387
337
  break
388
338
  }
389
339
  case 'fontWeight': {
@@ -393,45 +343,63 @@ export default function convertWebStyle2HmStyle(webStyle: CSSProperties) {
393
343
  case 'fontStyle': {
394
344
  switch (value) {
395
345
  case 'italic':
396
- hmStyle._fontStyle = FontStyle.Italic
346
+ hmStyle.fontStyle = FontStyle.Italic
397
347
  break
398
348
  default:
399
- hmStyle._fontStyle = FontStyle.Normal
349
+ hmStyle.fontStyle = FontStyle.Normal
400
350
  }
401
351
  break
402
352
  }
403
353
  case 'textAlign': {
404
354
  switch (value) {
405
355
  case 'left':
406
- hmStyle._textAlign = TextAlign.Start
356
+ hmStyle.textAlign = TextAlign.Start
407
357
  break
408
358
  case 'center':
409
- hmStyle._textAlign = TextAlign.Center
359
+ hmStyle.textAlign = TextAlign.Center
410
360
  break
411
361
  case 'right':
412
- hmStyle._textAlign = TextAlign.End
362
+ hmStyle.textAlign = TextAlign.End
413
363
  break
414
364
  default:
415
- hmStyle._textAlign = TextAlign.Start
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
416
384
  break
417
385
  }
418
386
  break
419
387
  }
420
388
  case 'lineHeight': {
421
- hmStyle._lineHeight = getUnit(value)
389
+ hmStyle.lineHeight = getUnit(value)
422
390
  break
423
391
  }
424
392
  case 'letterSpacing': {
425
- hmStyle._letterSpacing = getUnit(value)
393
+ hmStyle.letterSpacing = getUnit(value)
426
394
  break
427
395
  }
428
396
  case 'textDecoration': {
429
397
  if (typeof value === 'string') {
430
398
  switch (value) {
431
- case 'underline': hmStyle._textDecoration = TextDecorationType.Underline; break
432
- case 'overline': hmStyle._textDecoration = TextDecorationType.Overline; break
433
- case 'line-through': hmStyle._textDecoration = TextDecorationType.LineThrough; break
434
- default: hmStyle._textDecoration = TextDecorationType.None; break
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
435
403
  }
436
404
  }
437
405
  break
@@ -444,18 +412,51 @@ export default function convertWebStyle2HmStyle(webStyle: CSSProperties) {
444
412
  case 'ellipsis': overflow = TextOverflow.Ellipsis; break
445
413
  case 'marquee': overflow = TextOverflow.MARQUEE; break
446
414
  }
447
- hmStyle._textOverflow = {
415
+ hmStyle.textOverflow = {
448
416
  overflow
449
417
  }
450
418
  }
451
419
  break
452
420
  }
453
421
  case 'WebkitLineClamp': {
454
- hmStyle._WebkitLineClamp = Number(value)
455
- break
422
+ hmStyle.WebkitLineClamp = Number(value)
423
+ break
456
424
  }
457
425
  case 'transform': {
458
- hmStyle._transform = parseTransform(value)
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上的动画参数
459
460
  break
460
461
  }
461
462
  default: {
@@ -472,31 +473,94 @@ function setBackgroundImage(hmStyle, value) {
472
473
  // 如果包含 url(),则说明是 background-image 属性
473
474
  const match = value.match(new RegExp('url\\([\'"]?(.*?)[\'"]?\\)'))
474
475
  if (match) {
475
- hmStyle._backgroundImage = [{
476
+ hmStyle.backgroundImage = {
476
477
  src: match[1]
477
- }]
478
+ }
478
479
  }
479
480
  }
481
+ // todo 渐变需要处理
482
+ }
483
+
484
+ // 解析background属性
485
+ function setBackground (backgroundValue: string) {
486
+ const result = {
487
+ 'background-color': '',
488
+ 'background-image': '',
489
+ 'background-repeat': '',
490
+ 'background-position': '',
491
+ 'background-size': ''
492
+ }
493
+
494
+ if (!backgroundValue) return result
495
+
496
+ // 匹配background-image
497
+ const imageMatch = backgroundValue.match(BACKGROUND_REGEX.IMAGE)
498
+ if (imageMatch) {
499
+ result['background-image'] = imageMatch[0]
500
+ backgroundValue = backgroundValue.replace(imageMatch[0], '').trim()
501
+ }
502
+
503
+ // 匹配background-color
504
+ const colorMatch = backgroundValue.match(BACKGROUND_REGEX.COLOR)
505
+ if (colorMatch) {
506
+ result['background-color'] = colorMatch[0]
507
+ backgroundValue = backgroundValue.replace(colorMatch[0], '').trim()
508
+ }
509
+
510
+ // 匹配background-repeat
511
+ const repeatMatch = backgroundValue.match(BACKGROUND_REGEX.REPEAT)
512
+ if (repeatMatch) {
513
+ result['background-repeat'] = repeatMatch[0]
514
+ backgroundValue = backgroundValue.replace(repeatMatch[0], '').trim()
515
+ }
516
+
517
+ // 匹配background-position,background-size
518
+ // 先分割 / 分割出background-position\background-size
519
+ const positionSize = backgroundValue.split('/')
520
+ const [position, size] = positionSize
521
+ // 匹配background-position
522
+ if (position) {
523
+ const positionMatch = position.match(BACKGROUND_REGEX.POSITION)
524
+ if (positionMatch) {
525
+ result['background-position'] = positionMatch.join(' ')
526
+ }
527
+ }
528
+ if (size) {
529
+ // 匹配background-size
530
+ const sizeMatch = size.match(BACKGROUND_REGEX.SIZE)
531
+ if (sizeMatch) {
532
+ result['background-size'] = sizeMatch.join(' ')
533
+ }
534
+ }
535
+
536
+ return result
480
537
  }
481
538
 
482
539
  function setBackgroundRepeat(hmStyle, value) {
483
540
  if (typeof value === 'string') {
484
541
  switch (value) {
485
- case 'repeat-x': hmStyle._backgroundRepeat = [ImageRepeat.X]; break
486
- case 'repeat-y': hmStyle._backgroundRepeat = [ImageRepeat.Y]; break
487
- case 'no-repeat': hmStyle._backgroundRepeat = [ImageRepeat.NoRepeat]; break
488
- default: hmStyle._backgroundRepeat = [ImageRepeat.XY]; break
542
+ case 'repeat-x': hmStyle.backgroundRepeat = ImageRepeat.X; break
543
+ case 'repeat-y': hmStyle.backgroundRepeat = ImageRepeat.Y; break
544
+ case 'no-repeat': hmStyle.backgroundRepeat = ImageRepeat.NoRepeat; break
545
+ default: hmStyle.backgroundRepeat = ImageRepeat.XY; break
489
546
  }
490
547
  }
491
548
  }
492
549
 
493
550
  function setBackgroundSize(hmStyle, value) {
494
551
  if (typeof value === 'string') {
552
+ if (value === 'cover') {
553
+ hmStyle.backgroundSize = ImageSize.Cover
554
+ return
555
+ } else if (value === 'contain') {
556
+ hmStyle.backgroundSize = ImageSize.Contain
557
+ return
558
+ }
495
559
  const sizes = value.split(' ')
496
560
  if (sizes.length === 1) {
497
- hmStyle._backgroundSize = [{ width: getUnit(sizes[0]) }]
561
+ hmStyle.backgroundSize = { width: getUnit(sizes[0]) }
498
562
  } else if (sizes.length === 2) {
499
- hmStyle._backgroundSize = [{ width: getUnit(sizes[0]), height: getUnit(sizes[1]) }]
563
+ hmStyle.backgroundSize = { width: getUnit(sizes[0]), height: getUnit(sizes[1]) }
500
564
  }
501
565
  }
502
566
  }
@@ -505,31 +569,31 @@ function setBackgroundPosistion (hmStyle, value) {
505
569
  if (typeof value === 'string') {
506
570
  const positions = value.split(' ')
507
571
  const horizontal = positions[0].toLowerCase()
508
- const vertical = positions[1].toLowerCase() || 'top'
572
+ const vertical = positions[1]?.toLowerCase() || 'top'
509
573
 
510
574
  if (horizontal === 'left' && vertical === 'top') {
511
- hmStyle._backgroundPosition = [Alignment.TopStart]
575
+ hmStyle.backgroundPosition = Alignment.TopStart
512
576
  } else if (horizontal === 'center' && vertical === 'top') {
513
- hmStyle._backgroundPosition = [Alignment.Top]
577
+ hmStyle.backgroundPosition = Alignment.Top
514
578
  } else if (horizontal === 'right' && vertical === 'top') {
515
- hmStyle._backgroundPosition = [Alignment.TopEnd]
579
+ hmStyle.backgroundPosition = Alignment.TopEnd
516
580
  } else if (horizontal === 'left' && vertical === 'center') {
517
- hmStyle._backgroundPosition = [Alignment.Start]
581
+ hmStyle.backgroundPosition = Alignment.Start
518
582
  } else if (horizontal === 'center' && vertical === 'center') {
519
- hmStyle._backgroundPosition = [Alignment.Center]
583
+ hmStyle.backgroundPosition = Alignment.Center
520
584
  } else if (horizontal === 'right' && vertical === 'center') {
521
- hmStyle._backgroundPosition = [Alignment.End]
585
+ hmStyle.backgroundPosition = Alignment.End
522
586
  } else if (horizontal === 'left' && vertical === 'bottom') {
523
- hmStyle._backgroundPosition = [Alignment.BottomStart]
587
+ hmStyle.backgroundPosition = Alignment.BottomStart
524
588
  } else if (horizontal === 'center' && vertical === 'bottom') {
525
- hmStyle._backgroundPosition = [Alignment.Bottom]
589
+ hmStyle.backgroundPosition = Alignment.Bottom
526
590
  } else if (horizontal === 'right' && vertical === 'bottom') {
527
- hmStyle._backgroundPosition = [Alignment.BottomEnd]
591
+ hmStyle.backgroundPosition = Alignment.BottomEnd
528
592
  } else {
529
593
  if (/^\d+(\.\d+)?(px|%|vw|vh)$/.test(horizontal)) {
530
- hmStyle._backgroundPosition = [{ x: getUnit(horizontal) }]
594
+ hmStyle.backgroundPosition = { x: getUnit(horizontal) }
531
595
  if (/^\d+(\.\d+)?(px|%|vw|vh)$/.test(vertical)) {
532
- hmStyle._backgroundPosition = [{ x: getUnit(horizontal), y: getUnit(vertical) }]
596
+ hmStyle.backgroundPosition = { x: getUnit(horizontal), y: getUnit(vertical) }
533
597
  }
534
598
  }
535
599
  }
@@ -538,22 +602,23 @@ function setBackgroundPosistion (hmStyle, value) {
538
602
 
539
603
  function setFontWeight (hmStyle, value) {
540
604
  switch (value) {
541
- case 'normal': hmStyle._fontWeight = FontWeight.Normal; break
542
- case 'bold': hmStyle._fontWeight = FontWeight.Bold; break
543
- case 'bolder': hmStyle._fontWeight = FontWeight.Bolder; break
544
- case 'lighter': hmStyle._fontWeight = FontWeight.Lighter; break
545
- default: hmStyle._fontWeight = Number(value); break
605
+ case 'normal': hmStyle.fontWeight = FontWeight.Normal; break
606
+ case 'bold': hmStyle.fontWeight = FontWeight.Bold; break
607
+ case 'bolder': hmStyle.fontWeight = FontWeight.Bolder; break
608
+ case 'lighter': hmStyle.fontWeight = FontWeight.Lighter; break
609
+ default: hmStyle.fontWeight = Number(value); break
546
610
  }
547
611
  }
548
612
 
613
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
549
614
  function parseTransform(transformString) {
550
615
  const transformRegex = /(\w+)\(([^)]+)\)/g
551
- const transforms = []
616
+ const transform = {}
552
617
 
553
618
  let matchs
554
619
  while ((matchs = transformRegex.exec(transformString)) !== null) {
555
620
  const [, type, valueString] = matchs
556
- const values = valueString.split(/\s*,\s*/).map(parseFloat)
621
+ const values = valueString.split(/\s*,\s*/)
557
622
 
558
623
  const transformObj = {
559
624
  type: capitalizeFirstLetter(type),
@@ -563,62 +628,101 @@ function parseTransform(transformString) {
563
628
  switch (type) {
564
629
  case 'translate':
565
630
  case 'translate3d':
566
- transformObj.value.x = parseFloat(getUnit(values[0])) || 0
567
- transformObj.value.y = parseFloat(getUnit(values[1])) || 0
568
- transformObj.value.z = parseFloat(getUnit(values[2])) || 0
631
+ transformObj.value.x = (getUnit(values[0])) || 0
632
+ transformObj.value.y = (getUnit(values[1])) || 0
633
+ transformObj.value.z = (getUnit(values[2])) || 0
569
634
  break
570
635
  case 'translateX':
571
- transformObj.value.x = parseFloat(getUnit(values[0])) || 0
636
+ transformObj.value.x = (getUnit(values[0])) || 0
572
637
  break
573
638
  case 'translateY':
574
- transformObj.value.y = parseFloat(getUnit(values[0])) || 0
639
+ transformObj.value.y = (getUnit(values[0])) || 0
575
640
  break
576
641
  case 'translateZ':
577
- transformObj.value.z = parseFloat(getUnit(values[0])) || 0
642
+ transformObj.value.z = (getUnit(values[0])) || 0
578
643
  break
579
644
  case 'rotate':
580
- transformObj.value.angle = parseFloat(getUnit(values[0])) || 0
645
+ case 'rotateZ':
646
+ transformObj.value.angle = (getUnit(values[0])) || 0
581
647
  transformObj.value.x = 0
582
648
  transformObj.value.y = 0
583
649
  transformObj.value.z = 1
584
650
  break
585
651
  case 'rotate3d':
586
- transformObj.value.angle = parseFloat(getUnit(values[0])) || 0
652
+ transformObj.value.angle = getUnit(values[0]) || 0
587
653
  transformObj.value.x = values[1] || 0
588
654
  transformObj.value.y = values[2] || 0
589
655
  transformObj.value.z = values[3] || 0
590
656
  break
591
657
  case 'rotateX':
592
- transformObj.value.angle = parseFloat(getUnit(values[0])) || 0
658
+ transformObj.value.angle = getUnit(values[0]) || 0
593
659
  transformObj.value.x = 1
594
660
  transformObj.value.y = 0
595
661
  transformObj.value.z = 0
596
662
  break
597
663
  case 'rotateY':
598
- transformObj.value.angle = parseFloat(getUnit(values[0])) || 0
664
+ transformObj.value.angle = getUnit(values[0]) || 0
599
665
  transformObj.value.x = 0
600
666
  transformObj.value.y = 1
601
667
  transformObj.value.z = 0
602
668
  break
603
669
  case 'scale':
604
670
  case 'scale3d':
605
- transformObj.value.x = values[0] || 1
606
- transformObj.value.y = values[1] || values[0] || 1
607
- transformObj.value.z = values[2] || 1
671
+ transformObj.value.x = parseFloat(values[0]) || 1
672
+ transformObj.value.y = parseFloat(values[1] || values[0]) || 1
673
+ transformObj.value.z = parseFloat(values[2]) || 1
608
674
  break
609
675
  case 'scaleX':
610
- transformObj.value.x = values[0] || 1
676
+ transformObj.value.x = parseFloat(values[0]) || 1
611
677
  break
612
678
  case 'scaleY':
613
- transformObj.value.y = values[0] || 1
679
+ transformObj.value.y = parseFloat(values[0]) || 1
614
680
  break
615
681
  default:
616
682
  // Handle unrecognized transform types or ignore them
617
683
  break
618
684
  }
619
685
 
620
- transforms.push(transformObj)
686
+ transform[transformObj.type] = transformObj.value
687
+ }
688
+
689
+ return transform
690
+ }
691
+
692
+ // 方向转百分比
693
+ function directionToPercent(direction: string) {
694
+ switch (direction) {
695
+ case 'top':
696
+ case 'left':
697
+ return '0%'
698
+ case 'center':
699
+ return '50%'
700
+ case 'bottom':
701
+ case 'right':
702
+ return '100%'
703
+ default:
704
+ return direction
621
705
  }
706
+ }
622
707
 
623
- return transforms
708
+ // 解析transform-orgin
709
+ function parseTransformOrigin (value: string) {
710
+ if (typeof value === 'string') {
711
+ const values = value.split(' ')
712
+ if (values.length === 1) {
713
+ return {
714
+ x: getUnit(directionToPercent(values[0])),
715
+ y: getUnit(directionToPercent(values[0]))
716
+ }
717
+ } else if (values.length === 2) {
718
+ return {
719
+ x: getUnit(directionToPercent(values[0])),
720
+ y: getUnit(directionToPercent(values[1]))
721
+ }
722
+ }
723
+ }
724
+ return {
725
+ x: 0,
726
+ y: 0
727
+ }
624
728
  }