@tarojs/plugin-platform-harmony-ets 4.0.0-alpha.2 → 4.0.0-alpha.21

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 (129) hide show
  1. package/dist/apis/base/system.ts +73 -20
  2. package/dist/apis/canvas/index.ts +10 -1
  3. package/dist/apis/device/clipboard.ts +16 -8
  4. package/dist/apis/framework/index.ts +1 -5
  5. package/dist/apis/index.ts +25 -17
  6. package/dist/apis/media/image/index.ts +1 -1
  7. package/dist/apis/storage/index.ts +146 -78
  8. package/dist/apis/ui/animation/animation.ts +71 -29
  9. package/dist/apis/ui/background.ts +2 -1
  10. package/dist/apis/ui/interaction/index.ts +42 -59
  11. package/dist/apis/ui/navigation-bar/index.ts +1 -1
  12. package/dist/apis/ui/pull-down-refresh.ts +9 -3
  13. package/dist/apis/ui/scroll/index.ts +5 -5
  14. package/dist/apis/ui/tab-bar.ts +3 -3
  15. package/dist/apis/utils/index.ts +2 -1
  16. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  17. package/dist/apis/wxml/selectorQuery.ts +26 -13
  18. package/dist/components-harmony-ets/button.ets +64 -34
  19. package/dist/components-harmony-ets/canvas.ets +51 -0
  20. package/dist/components-harmony-ets/checkbox.ets +72 -61
  21. package/dist/components-harmony-ets/form.ets +51 -29
  22. package/dist/components-harmony-ets/icon.ets +31 -19
  23. package/dist/components-harmony-ets/image.ets +34 -14
  24. package/dist/components-harmony-ets/index.ets +92 -0
  25. package/dist/components-harmony-ets/innerHtml.ets +11 -6
  26. package/dist/components-harmony-ets/input.ets +49 -41
  27. package/dist/components-harmony-ets/label.ets +71 -44
  28. package/dist/components-harmony-ets/listView.ets +26 -0
  29. package/dist/components-harmony-ets/movableArea.ets +126 -0
  30. package/dist/components-harmony-ets/movableView.ets +93 -0
  31. package/dist/components-harmony-ets/navigationBar.ets +65 -0
  32. package/dist/components-harmony-ets/pageMeta.ets +94 -0
  33. package/dist/components-harmony-ets/picker.ets +42 -38
  34. package/dist/components-harmony-ets/progress.ets +52 -0
  35. package/dist/components-harmony-ets/pseudo.ets +80 -0
  36. package/dist/components-harmony-ets/radio.ets +74 -64
  37. package/dist/components-harmony-ets/richText.ets +14 -30
  38. package/dist/components-harmony-ets/scrollList.ets +94 -0
  39. package/dist/components-harmony-ets/scrollView.ets +61 -57
  40. package/dist/components-harmony-ets/slider.ets +18 -14
  41. package/dist/components-harmony-ets/stickySection.ets +42 -0
  42. package/dist/components-harmony-ets/style.ets +381 -130
  43. package/dist/components-harmony-ets/swiper.ets +61 -20
  44. package/dist/components-harmony-ets/switch.ets +36 -32
  45. package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
  46. package/dist/components-harmony-ets/text.ets +135 -49
  47. package/dist/components-harmony-ets/textArea.ets +50 -35
  48. package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
  49. package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -2
  50. package/dist/components-harmony-ets/utils/flexManager.ets +49 -19
  51. package/dist/components-harmony-ets/utils/helper.ets +18 -5
  52. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  53. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  54. package/dist/components-harmony-ets/utils/index.ts +54 -50
  55. package/dist/components-harmony-ets/utils/styles.ets +170 -93
  56. package/dist/components-harmony-ets/video.ets +34 -21
  57. package/dist/components-harmony-ets/view.ets +63 -52
  58. package/dist/components-harmony-ets/webView.ets +40 -34
  59. package/dist/index.d.ts +152 -0
  60. package/dist/index.js +99 -55
  61. package/dist/index.js.map +1 -1
  62. package/dist/runtime-ets/bom/document.ts +6 -4
  63. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
  64. package/dist/runtime-ets/bom/window.ts +7 -0
  65. package/dist/runtime-ets/current.ts +3 -0
  66. package/dist/runtime-ets/dom/bind.ts +28 -12
  67. package/dist/runtime-ets/dom/class-list.ts +2 -2
  68. package/dist/runtime-ets/dom/cssNesting.ts +419 -0
  69. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +28 -42
  70. package/dist/runtime-ets/dom/document.ts +8 -11
  71. package/dist/runtime-ets/dom/element/canvas.ts +136 -0
  72. package/dist/runtime-ets/dom/element/element.ts +348 -57
  73. package/dist/runtime-ets/dom/element/form.ts +31 -26
  74. package/dist/runtime-ets/dom/element/index.ts +30 -2
  75. package/dist/runtime-ets/dom/element/movableArea.ts +11 -0
  76. package/dist/runtime-ets/dom/element/movableView.ts +244 -0
  77. package/dist/runtime-ets/dom/element/normal.ts +35 -8
  78. package/dist/runtime-ets/dom/element/progress.ts +11 -0
  79. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  80. package/dist/runtime-ets/dom/element/text.ts +1 -8
  81. package/dist/runtime-ets/dom/element/video.ts +5 -4
  82. package/dist/runtime-ets/dom/element/webView.ts +12 -5
  83. package/dist/runtime-ets/dom/event.ts +2 -4
  84. package/dist/runtime-ets/dom/eventTarget.ts +2 -3
  85. package/dist/runtime-ets/dom/node.ts +54 -29
  86. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +416 -235
  87. package/dist/runtime-ets/dom/stylesheet/index.ts +29 -311
  88. package/dist/runtime-ets/dom/stylesheet/type.ts +51 -9
  89. package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
  90. package/dist/runtime-ets/index.ts +2 -1
  91. package/dist/runtime-ets/interface/event.ts +1 -1
  92. package/dist/runtime-ets/utils/index.ts +73 -13
  93. package/dist/runtime-ets/utils/info.ts +2 -2
  94. package/dist/runtime-framework/react/app.ts +9 -4
  95. package/dist/runtime-framework/react/hooks.ts +0 -1
  96. package/dist/runtime-framework/react/index.ts +0 -2
  97. package/dist/runtime-framework/react/native-page.ts +154 -77
  98. package/dist/runtime-framework/react/page.ts +3 -8
  99. package/dist/runtime-framework/solid/app.ts +25 -45
  100. package/dist/runtime-framework/solid/connect.ts +21 -3
  101. package/dist/runtime-framework/solid/hooks.ts +16 -11
  102. package/dist/runtime-framework/solid/index.ts +6 -2
  103. package/dist/runtime-framework/solid/page.ts +84 -30
  104. package/dist/runtime-framework/solid/reconciler/props.ts +70 -25
  105. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  106. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  107. package/dist/runtime-framework/solid/utils/index.ts +0 -2
  108. package/dist/runtime-utils.d.ts +827 -0
  109. package/dist/runtime-utils.js +435 -218
  110. package/dist/runtime-utils.js.map +1 -1
  111. package/dist/runtime.d.ts +1 -0
  112. package/dist/runtime.js +435 -218
  113. package/dist/runtime.js.map +1 -1
  114. package/index.js +3 -1
  115. package/package.json +14 -15
  116. package/static/media/cancel.svg +1 -1
  117. package/static/media/circle.svg +1 -1
  118. package/static/media/clear.svg +1 -1
  119. package/static/media/download.svg +1 -1
  120. package/static/media/info.svg +1 -1
  121. package/static/media/info_circle.svg +1 -1
  122. package/static/media/search.svg +1 -1
  123. package/static/media/success.svg +1 -1
  124. package/static/media/success_no_circle.svg +1 -1
  125. package/static/media/warn.svg +1 -1
  126. package/types/harmony.d.ts +4 -0
  127. package/types/index.d.ts +4 -0
  128. package/types/runtime.d.ts +1 -1
  129. /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\([^)]*\))/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
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: {
@@ -468,35 +469,102 @@ export default function convertWebStyle2HmStyle(webStyle: CSSProperties) {
468
469
  }
469
470
 
470
471
  function setBackgroundImage(hmStyle, value) {
471
- if (typeof value === 'string' && value.indexOf('url(') !== -1 && value.indexOf(')') !== -1) {
472
- // 如果包含 url(),则说明是 background-image 属性
473
- const match = value.match(new RegExp('url\\([\'"]?(.*?)[\'"]?\\)'))
474
- if (match) {
475
- hmStyle._backgroundImage = [{
476
- src: match[1]
477
- }]
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(' ')
478
537
  }
479
538
  }
539
+
540
+ return result
480
541
  }
481
542
 
482
543
  function setBackgroundRepeat(hmStyle, value) {
483
544
  if (typeof value === 'string') {
484
545
  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
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
489
550
  }
490
551
  }
491
552
  }
492
553
 
493
554
  function setBackgroundSize(hmStyle, value) {
494
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
+ }
495
563
  const sizes = value.split(' ')
496
564
  if (sizes.length === 1) {
497
- hmStyle._backgroundSize = [{ width: getUnit(sizes[0]) }]
565
+ hmStyle.backgroundSize = { width: getUnit(sizes[0]) }
498
566
  } else if (sizes.length === 2) {
499
- hmStyle._backgroundSize = [{ width: getUnit(sizes[0]), height: getUnit(sizes[1]) }]
567
+ hmStyle.backgroundSize = { width: getUnit(sizes[0]), height: getUnit(sizes[1]) }
500
568
  }
501
569
  }
502
570
  }
@@ -505,31 +573,31 @@ function setBackgroundPosistion (hmStyle, value) {
505
573
  if (typeof value === 'string') {
506
574
  const positions = value.split(' ')
507
575
  const horizontal = positions[0].toLowerCase()
508
- const vertical = positions[1].toLowerCase() || 'top'
576
+ const vertical = positions[1]?.toLowerCase() || 'top'
509
577
 
510
578
  if (horizontal === 'left' && vertical === 'top') {
511
- hmStyle._backgroundPosition = [Alignment.TopStart]
579
+ hmStyle.backgroundPosition = Alignment.TopStart
512
580
  } else if (horizontal === 'center' && vertical === 'top') {
513
- hmStyle._backgroundPosition = [Alignment.Top]
581
+ hmStyle.backgroundPosition = Alignment.Top
514
582
  } else if (horizontal === 'right' && vertical === 'top') {
515
- hmStyle._backgroundPosition = [Alignment.TopEnd]
583
+ hmStyle.backgroundPosition = Alignment.TopEnd
516
584
  } else if (horizontal === 'left' && vertical === 'center') {
517
- hmStyle._backgroundPosition = [Alignment.Start]
585
+ hmStyle.backgroundPosition = Alignment.Start
518
586
  } else if (horizontal === 'center' && vertical === 'center') {
519
- hmStyle._backgroundPosition = [Alignment.Center]
587
+ hmStyle.backgroundPosition = Alignment.Center
520
588
  } else if (horizontal === 'right' && vertical === 'center') {
521
- hmStyle._backgroundPosition = [Alignment.End]
589
+ hmStyle.backgroundPosition = Alignment.End
522
590
  } else if (horizontal === 'left' && vertical === 'bottom') {
523
- hmStyle._backgroundPosition = [Alignment.BottomStart]
591
+ hmStyle.backgroundPosition = Alignment.BottomStart
524
592
  } else if (horizontal === 'center' && vertical === 'bottom') {
525
- hmStyle._backgroundPosition = [Alignment.Bottom]
593
+ hmStyle.backgroundPosition = Alignment.Bottom
526
594
  } else if (horizontal === 'right' && vertical === 'bottom') {
527
- hmStyle._backgroundPosition = [Alignment.BottomEnd]
595
+ hmStyle.backgroundPosition = Alignment.BottomEnd
528
596
  } else {
529
597
  if (/^\d+(\.\d+)?(px|%|vw|vh)$/.test(horizontal)) {
530
- hmStyle._backgroundPosition = [{ x: getUnit(horizontal) }]
598
+ hmStyle.backgroundPosition = { x: getUnit(horizontal) }
531
599
  if (/^\d+(\.\d+)?(px|%|vw|vh)$/.test(vertical)) {
532
- hmStyle._backgroundPosition = [{ x: getUnit(horizontal), y: getUnit(vertical) }]
600
+ hmStyle.backgroundPosition = { x: getUnit(horizontal), y: getUnit(vertical) }
533
601
  }
534
602
  }
535
603
  }
@@ -538,22 +606,23 @@ function setBackgroundPosistion (hmStyle, value) {
538
606
 
539
607
  function setFontWeight (hmStyle, value) {
540
608
  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
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
546
614
  }
547
615
  }
548
616
 
617
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
549
618
  function parseTransform(transformString) {
550
619
  const transformRegex = /(\w+)\(([^)]+)\)/g
551
- const transforms = []
620
+ const transform = {}
552
621
 
553
622
  let matchs
554
623
  while ((matchs = transformRegex.exec(transformString)) !== null) {
555
624
  const [, type, valueString] = matchs
556
- const values = valueString.split(/\s*,\s*/).map(parseFloat)
625
+ const values = valueString.split(/\s*,\s*/)
557
626
 
558
627
  const transformObj = {
559
628
  type: capitalizeFirstLetter(type),
@@ -563,62 +632,174 @@ function parseTransform(transformString) {
563
632
  switch (type) {
564
633
  case 'translate':
565
634
  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
635
+ transformObj.value.x = (getUnit(values[0])) || 0
636
+ transformObj.value.y = (getUnit(values[1])) || 0
637
+ transformObj.value.z = (getUnit(values[2])) || 0
569
638
  break
570
639
  case 'translateX':
571
- transformObj.value.x = parseFloat(getUnit(values[0])) || 0
640
+ transformObj.value.x = (getUnit(values[0])) || 0
572
641
  break
573
642
  case 'translateY':
574
- transformObj.value.y = parseFloat(getUnit(values[0])) || 0
643
+ transformObj.value.y = (getUnit(values[0])) || 0
575
644
  break
576
645
  case 'translateZ':
577
- transformObj.value.z = parseFloat(getUnit(values[0])) || 0
646
+ transformObj.value.z = (getUnit(values[0])) || 0
578
647
  break
579
648
  case 'rotate':
580
- transformObj.value.angle = parseFloat(getUnit(values[0])) || 0
649
+ case 'rotateZ':
650
+ transformObj.value.angle = (getUnit(values[0])) || 0
581
651
  transformObj.value.x = 0
582
652
  transformObj.value.y = 0
583
653
  transformObj.value.z = 1
584
654
  break
585
655
  case 'rotate3d':
586
- transformObj.value.angle = parseFloat(getUnit(values[0])) || 0
656
+ transformObj.value.angle = getUnit(values[0]) || 0
587
657
  transformObj.value.x = values[1] || 0
588
658
  transformObj.value.y = values[2] || 0
589
659
  transformObj.value.z = values[3] || 0
590
660
  break
591
661
  case 'rotateX':
592
- transformObj.value.angle = parseFloat(getUnit(values[0])) || 0
662
+ transformObj.value.angle = getUnit(values[0]) || 0
593
663
  transformObj.value.x = 1
594
664
  transformObj.value.y = 0
595
665
  transformObj.value.z = 0
596
666
  break
597
667
  case 'rotateY':
598
- transformObj.value.angle = parseFloat(getUnit(values[0])) || 0
668
+ transformObj.value.angle = getUnit(values[0]) || 0
599
669
  transformObj.value.x = 0
600
670
  transformObj.value.y = 1
601
671
  transformObj.value.z = 0
602
672
  break
603
673
  case 'scale':
604
674
  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
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
608
678
  break
609
679
  case 'scaleX':
610
- transformObj.value.x = values[0] || 1
680
+ transformObj.value.x = parseFloat(values[0]) || 1
611
681
  break
612
682
  case 'scaleY':
613
- transformObj.value.y = values[0] || 1
683
+ transformObj.value.y = parseFloat(values[0]) || 1
614
684
  break
615
685
  default:
616
686
  // Handle unrecognized transform types or ignore them
617
687
  break
618
688
  }
619
689
 
620
- transforms.push(transformObj)
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
621
709
  }
710
+ }
622
711
 
623
- return transforms
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
+ })
624
805
  }