@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.
- package/dist/apis/base/system.ts +73 -20
- package/dist/apis/canvas/index.ts +10 -1
- package/dist/apis/device/clipboard.ts +16 -8
- package/dist/apis/framework/index.ts +1 -5
- package/dist/apis/index.ts +25 -17
- package/dist/apis/media/image/index.ts +1 -1
- package/dist/apis/storage/index.ts +146 -78
- package/dist/apis/ui/animation/animation.ts +71 -29
- package/dist/apis/ui/background.ts +2 -1
- package/dist/apis/ui/interaction/index.ts +42 -59
- package/dist/apis/ui/navigation-bar/index.ts +1 -1
- package/dist/apis/ui/pull-down-refresh.ts +9 -3
- package/dist/apis/ui/scroll/index.ts +5 -5
- package/dist/apis/ui/tab-bar.ts +3 -3
- package/dist/apis/utils/index.ts +2 -1
- package/dist/apis/wxml/IntersectionObserver.ts +18 -10
- package/dist/apis/wxml/selectorQuery.ts +26 -13
- package/dist/components-harmony-ets/button.ets +64 -34
- package/dist/components-harmony-ets/canvas.ets +51 -0
- package/dist/components-harmony-ets/checkbox.ets +72 -61
- package/dist/components-harmony-ets/form.ets +51 -29
- package/dist/components-harmony-ets/icon.ets +31 -19
- package/dist/components-harmony-ets/image.ets +34 -14
- package/dist/components-harmony-ets/index.ets +92 -0
- package/dist/components-harmony-ets/innerHtml.ets +11 -6
- package/dist/components-harmony-ets/input.ets +49 -41
- package/dist/components-harmony-ets/label.ets +71 -44
- package/dist/components-harmony-ets/listView.ets +26 -0
- package/dist/components-harmony-ets/movableArea.ets +126 -0
- package/dist/components-harmony-ets/movableView.ets +93 -0
- package/dist/components-harmony-ets/navigationBar.ets +65 -0
- package/dist/components-harmony-ets/pageMeta.ets +94 -0
- package/dist/components-harmony-ets/picker.ets +42 -38
- package/dist/components-harmony-ets/progress.ets +52 -0
- package/dist/components-harmony-ets/pseudo.ets +80 -0
- package/dist/components-harmony-ets/radio.ets +74 -64
- package/dist/components-harmony-ets/richText.ets +14 -30
- package/dist/components-harmony-ets/scrollList.ets +94 -0
- package/dist/components-harmony-ets/scrollView.ets +61 -57
- package/dist/components-harmony-ets/slider.ets +18 -14
- package/dist/components-harmony-ets/stickySection.ets +42 -0
- package/dist/components-harmony-ets/style.ets +381 -130
- package/dist/components-harmony-ets/swiper.ets +61 -20
- package/dist/components-harmony-ets/switch.ets +36 -32
- package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
- package/dist/components-harmony-ets/text.ets +135 -49
- package/dist/components-harmony-ets/textArea.ets +50 -35
- package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
- package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -2
- package/dist/components-harmony-ets/utils/flexManager.ets +49 -19
- package/dist/components-harmony-ets/utils/helper.ets +18 -5
- package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
- package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
- package/dist/components-harmony-ets/utils/index.ts +54 -50
- package/dist/components-harmony-ets/utils/styles.ets +170 -93
- package/dist/components-harmony-ets/video.ets +34 -21
- package/dist/components-harmony-ets/view.ets +63 -52
- package/dist/components-harmony-ets/webView.ets +40 -34
- package/dist/index.d.ts +152 -0
- package/dist/index.js +99 -55
- package/dist/index.js.map +1 -1
- package/dist/runtime-ets/bom/document.ts +6 -4
- package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
- package/dist/runtime-ets/bom/window.ts +7 -0
- package/dist/runtime-ets/current.ts +3 -0
- package/dist/runtime-ets/dom/bind.ts +28 -12
- package/dist/runtime-ets/dom/class-list.ts +2 -2
- package/dist/runtime-ets/dom/cssNesting.ts +419 -0
- package/dist/runtime-ets/dom/cssStyleDeclaration.ts +28 -42
- package/dist/runtime-ets/dom/document.ts +8 -11
- package/dist/runtime-ets/dom/element/canvas.ts +136 -0
- package/dist/runtime-ets/dom/element/element.ts +348 -57
- package/dist/runtime-ets/dom/element/form.ts +31 -26
- package/dist/runtime-ets/dom/element/index.ts +30 -2
- package/dist/runtime-ets/dom/element/movableArea.ts +11 -0
- package/dist/runtime-ets/dom/element/movableView.ts +244 -0
- package/dist/runtime-ets/dom/element/normal.ts +35 -8
- package/dist/runtime-ets/dom/element/progress.ts +11 -0
- package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
- package/dist/runtime-ets/dom/element/text.ts +1 -8
- package/dist/runtime-ets/dom/element/video.ts +5 -4
- package/dist/runtime-ets/dom/element/webView.ts +12 -5
- package/dist/runtime-ets/dom/event.ts +2 -4
- package/dist/runtime-ets/dom/eventTarget.ts +2 -3
- package/dist/runtime-ets/dom/node.ts +54 -29
- package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +416 -235
- package/dist/runtime-ets/dom/stylesheet/index.ts +29 -311
- package/dist/runtime-ets/dom/stylesheet/type.ts +51 -9
- package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
- package/dist/runtime-ets/index.ts +2 -1
- package/dist/runtime-ets/interface/event.ts +1 -1
- package/dist/runtime-ets/utils/index.ts +73 -13
- package/dist/runtime-ets/utils/info.ts +2 -2
- package/dist/runtime-framework/react/app.ts +9 -4
- package/dist/runtime-framework/react/hooks.ts +0 -1
- package/dist/runtime-framework/react/index.ts +0 -2
- package/dist/runtime-framework/react/native-page.ts +154 -77
- package/dist/runtime-framework/react/page.ts +3 -8
- package/dist/runtime-framework/solid/app.ts +25 -45
- package/dist/runtime-framework/solid/connect.ts +21 -3
- package/dist/runtime-framework/solid/hooks.ts +16 -11
- package/dist/runtime-framework/solid/index.ts +6 -2
- package/dist/runtime-framework/solid/page.ts +84 -30
- package/dist/runtime-framework/solid/reconciler/props.ts +70 -25
- package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
- package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
- package/dist/runtime-framework/solid/utils/index.ts +0 -2
- package/dist/runtime-utils.d.ts +827 -0
- package/dist/runtime-utils.js +435 -218
- package/dist/runtime-utils.js.map +1 -1
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.js +435 -218
- package/dist/runtime.js.map +1 -1
- package/index.js +3 -1
- package/package.json +14 -15
- package/static/media/cancel.svg +1 -1
- package/static/media/circle.svg +1 -1
- package/static/media/clear.svg +1 -1
- package/static/media/download.svg +1 -1
- package/static/media/info.svg +1 -1
- package/static/media/info_circle.svg +1 -1
- package/static/media/search.svg +1 -1
- package/static/media/success.svg +1 -1
- package/static/media/success_no_circle.svg +1 -1
- package/static/media/warn.svg +1 -1
- package/types/harmony.d.ts +4 -0
- package/types/index.d.ts +4 -0
- package/types/runtime.d.ts +1 -1
- /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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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.
|
|
89
|
-
hmStyle.
|
|
90
|
-
hmStyle.
|
|
91
|
-
hmStyle.
|
|
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.
|
|
32
|
+
hmStyle.paddingTop = getUnit(value)
|
|
96
33
|
break
|
|
97
34
|
}
|
|
98
35
|
case 'paddingBottom': {
|
|
99
|
-
hmStyle.
|
|
36
|
+
hmStyle.paddingBottom = getUnit(value)
|
|
100
37
|
break
|
|
101
38
|
}
|
|
102
39
|
case 'paddingLeft': {
|
|
103
|
-
hmStyle.
|
|
40
|
+
hmStyle.paddingLeft = getUnit(value)
|
|
104
41
|
break
|
|
105
42
|
}
|
|
106
43
|
case 'paddingRight': {
|
|
107
|
-
hmStyle.
|
|
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.
|
|
113
|
-
hmStyle.
|
|
114
|
-
hmStyle.
|
|
115
|
-
hmStyle.
|
|
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.
|
|
56
|
+
hmStyle.marginTop = getUnit(value)
|
|
120
57
|
break
|
|
121
58
|
}
|
|
122
59
|
case 'marginBottom': {
|
|
123
|
-
hmStyle.
|
|
60
|
+
hmStyle.marginBottom = getUnit(value)
|
|
124
61
|
break
|
|
125
62
|
}
|
|
126
63
|
case 'marginLeft': {
|
|
127
|
-
hmStyle.
|
|
64
|
+
hmStyle.marginLeft = getUnit(value)
|
|
128
65
|
break
|
|
129
66
|
}
|
|
130
67
|
case 'marginRight': {
|
|
131
|
-
hmStyle.
|
|
68
|
+
hmStyle.marginRight = getUnit(value)
|
|
132
69
|
break
|
|
133
70
|
}
|
|
134
71
|
case 'top': {
|
|
135
|
-
hmStyle.
|
|
72
|
+
hmStyle.top = getUnit(value)
|
|
136
73
|
break
|
|
137
74
|
}
|
|
138
75
|
case 'left': {
|
|
139
|
-
hmStyle.
|
|
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.
|
|
157
|
-
hmStyle.
|
|
158
|
-
hmStyle.
|
|
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.
|
|
107
|
+
hmStyle.flexGrow = getUnit(value)
|
|
163
108
|
break
|
|
164
109
|
}
|
|
165
110
|
case 'flexShrink': {
|
|
166
|
-
hmStyle.
|
|
111
|
+
hmStyle.flexShrink = Number(value)
|
|
167
112
|
break
|
|
168
113
|
}
|
|
169
114
|
case 'flexBasis': {
|
|
170
|
-
hmStyle.
|
|
115
|
+
hmStyle.flexBasis = Number(value)
|
|
171
116
|
break
|
|
172
117
|
}
|
|
173
118
|
case 'alignSelf': {
|
|
174
|
-
hmStyle.
|
|
119
|
+
hmStyle.alignSelf = FlexManager.itemAlign(value)
|
|
175
120
|
break
|
|
176
121
|
}
|
|
177
122
|
case 'flexDirection': {
|
|
178
|
-
hmStyle.
|
|
123
|
+
hmStyle.flexDirection = FlexManager.direction(value)
|
|
179
124
|
break
|
|
180
125
|
}
|
|
181
126
|
case 'justifyContent': {
|
|
182
|
-
hmStyle.
|
|
127
|
+
hmStyle.justifyContent = FlexManager.flexAlign(value)
|
|
183
128
|
break
|
|
184
129
|
}
|
|
185
130
|
case 'alignItems': {
|
|
186
|
-
hmStyle.
|
|
131
|
+
hmStyle.alignItems = FlexManager.itemAlign(value)
|
|
187
132
|
break
|
|
188
133
|
}
|
|
189
134
|
case 'alignContent': {
|
|
190
|
-
hmStyle.
|
|
135
|
+
hmStyle.alignContent = FlexManager.flexAlign(value)
|
|
191
136
|
break
|
|
192
137
|
}
|
|
193
138
|
case 'flexWrap': {
|
|
194
|
-
hmStyle.
|
|
139
|
+
hmStyle.flexWrap = FlexManager.flexWrap(value)
|
|
195
140
|
break
|
|
196
141
|
}
|
|
197
142
|
case 'width': {
|
|
198
|
-
hmStyle.
|
|
143
|
+
hmStyle.width = getUnit(value)
|
|
199
144
|
break
|
|
200
145
|
}
|
|
201
146
|
case 'height': {
|
|
202
|
-
hmStyle.
|
|
147
|
+
hmStyle.height = getUnit(value)
|
|
203
148
|
break
|
|
204
149
|
}
|
|
205
150
|
case 'minWidth': {
|
|
206
|
-
hmStyle.
|
|
151
|
+
hmStyle.minWidth = getUnit(value)
|
|
207
152
|
break
|
|
208
153
|
}
|
|
209
154
|
case 'minHeight': {
|
|
210
|
-
hmStyle.
|
|
155
|
+
hmStyle.minHeight = getUnit(value)
|
|
211
156
|
break
|
|
212
157
|
}
|
|
213
158
|
case 'maxWidth': {
|
|
214
|
-
hmStyle.
|
|
159
|
+
hmStyle.maxWidth = getUnit(value)
|
|
215
160
|
break
|
|
216
161
|
}
|
|
217
162
|
case 'maxHeight': {
|
|
218
|
-
hmStyle.
|
|
163
|
+
hmStyle.maxHeight = getUnit(value)
|
|
219
164
|
break
|
|
220
165
|
}
|
|
221
166
|
case 'background': {
|
|
222
|
-
|
|
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.
|
|
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.
|
|
248
|
-
hmStyle.
|
|
249
|
-
hmStyle.
|
|
250
|
-
hmStyle.
|
|
251
|
-
hmStyle.
|
|
252
|
-
hmStyle.
|
|
253
|
-
hmStyle.
|
|
254
|
-
hmStyle.
|
|
255
|
-
hmStyle.
|
|
256
|
-
hmStyle.
|
|
257
|
-
hmStyle.
|
|
258
|
-
hmStyle.
|
|
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.
|
|
264
|
-
hmStyle.
|
|
265
|
-
hmStyle.
|
|
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.
|
|
271
|
-
hmStyle.
|
|
272
|
-
hmStyle.
|
|
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.
|
|
278
|
-
hmStyle.
|
|
279
|
-
hmStyle.
|
|
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.
|
|
285
|
-
hmStyle.
|
|
286
|
-
hmStyle.
|
|
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.
|
|
291
|
-
hmStyle.
|
|
292
|
-
hmStyle.
|
|
293
|
-
hmStyle.
|
|
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.
|
|
247
|
+
hmStyle.borderLeftWidth = getUnit(value)
|
|
298
248
|
break
|
|
299
249
|
}
|
|
300
250
|
case 'borderRightWidth': {
|
|
301
|
-
hmStyle.
|
|
251
|
+
hmStyle.borderRightWidth = getUnit(value)
|
|
302
252
|
break
|
|
303
253
|
}
|
|
304
254
|
case 'borderTopWidth': {
|
|
305
|
-
hmStyle.
|
|
255
|
+
hmStyle.borderTopWidth = getUnit(value)
|
|
306
256
|
break
|
|
307
257
|
}
|
|
308
258
|
case 'borderBottomWidth': {
|
|
309
|
-
hmStyle.
|
|
259
|
+
hmStyle.borderBottomWidth = getUnit(value)
|
|
310
260
|
break
|
|
311
261
|
}
|
|
312
262
|
case 'borderStyle': {
|
|
313
|
-
hmStyle.
|
|
314
|
-
hmStyle.
|
|
315
|
-
hmStyle.
|
|
316
|
-
hmStyle.
|
|
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.
|
|
270
|
+
hmStyle.borderLeftStyle = BORDER_STYLE_MAP.get(value)
|
|
321
271
|
break
|
|
322
272
|
}
|
|
323
273
|
case 'borderRightStyle': {
|
|
324
|
-
hmStyle.
|
|
274
|
+
hmStyle.borderRightStyle = BORDER_STYLE_MAP.get(value)
|
|
325
275
|
break
|
|
326
276
|
}
|
|
327
277
|
case 'borderTopStyle': {
|
|
328
|
-
hmStyle.
|
|
278
|
+
hmStyle.borderTopStyle = BORDER_STYLE_MAP.get(value)
|
|
329
279
|
break
|
|
330
280
|
}
|
|
331
281
|
case 'borderBottomStyle': {
|
|
332
|
-
hmStyle.
|
|
282
|
+
hmStyle.borderBottomStyle = BORDER_STYLE_MAP.get(value)
|
|
333
283
|
break
|
|
334
284
|
}
|
|
335
285
|
case 'borderColor': {
|
|
336
|
-
hmStyle.
|
|
337
|
-
hmStyle.
|
|
338
|
-
hmStyle.
|
|
339
|
-
hmStyle.
|
|
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.
|
|
293
|
+
hmStyle.borderLeftColor = value
|
|
344
294
|
break
|
|
345
295
|
}
|
|
346
296
|
case 'borderRightColor': {
|
|
347
|
-
hmStyle.
|
|
297
|
+
hmStyle.borderRightColor = value
|
|
348
298
|
break
|
|
349
299
|
}
|
|
350
300
|
case 'borderTopColor': {
|
|
351
|
-
hmStyle.
|
|
301
|
+
hmStyle.borderTopColor = value
|
|
352
302
|
break
|
|
353
303
|
}
|
|
354
304
|
case 'borderBottomColor': {
|
|
355
|
-
hmStyle.
|
|
305
|
+
hmStyle.borderBottomColor = value
|
|
356
306
|
break
|
|
357
307
|
}
|
|
358
308
|
case 'borderRadius': {
|
|
359
|
-
hmStyle.
|
|
360
|
-
hmStyle.
|
|
361
|
-
hmStyle.
|
|
362
|
-
hmStyle.
|
|
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.
|
|
316
|
+
hmStyle.borderTopLeftRadius = getUnit(value)
|
|
367
317
|
break
|
|
368
318
|
}
|
|
369
319
|
case 'borderTopRightRadius': {
|
|
370
|
-
hmStyle.
|
|
320
|
+
hmStyle.borderTopRightRadius = getUnit(value)
|
|
371
321
|
break
|
|
372
322
|
}
|
|
373
323
|
case 'borderBottomLeftRadius': {
|
|
374
|
-
hmStyle.
|
|
324
|
+
hmStyle.borderBottomLeftRadius = getUnit(value)
|
|
375
325
|
break
|
|
376
326
|
}
|
|
377
327
|
case 'borderBottomRightRadius': {
|
|
378
|
-
hmStyle.
|
|
328
|
+
hmStyle.borderBottomRightRadius = getUnit(value)
|
|
379
329
|
break
|
|
380
330
|
}
|
|
381
331
|
case 'color': {
|
|
382
|
-
hmStyle.
|
|
332
|
+
hmStyle.color = value
|
|
383
333
|
break
|
|
384
334
|
}
|
|
385
335
|
case 'fontSize': {
|
|
386
|
-
hmStyle.
|
|
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.
|
|
346
|
+
hmStyle.fontStyle = FontStyle.Italic
|
|
397
347
|
break
|
|
398
348
|
default:
|
|
399
|
-
hmStyle.
|
|
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.
|
|
356
|
+
hmStyle.textAlign = TextAlign.Start
|
|
407
357
|
break
|
|
408
358
|
case 'center':
|
|
409
|
-
hmStyle.
|
|
359
|
+
hmStyle.textAlign = TextAlign.Center
|
|
410
360
|
break
|
|
411
361
|
case 'right':
|
|
412
|
-
hmStyle.
|
|
362
|
+
hmStyle.textAlign = TextAlign.End
|
|
413
363
|
break
|
|
414
364
|
default:
|
|
415
|
-
hmStyle.
|
|
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.
|
|
389
|
+
hmStyle.lineHeight = getUnit(value)
|
|
422
390
|
break
|
|
423
391
|
}
|
|
424
392
|
case 'letterSpacing': {
|
|
425
|
-
hmStyle.
|
|
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.
|
|
432
|
-
case 'overline': hmStyle.
|
|
433
|
-
case 'line-through': hmStyle.
|
|
434
|
-
default: hmStyle.
|
|
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.
|
|
415
|
+
hmStyle.textOverflow = {
|
|
448
416
|
overflow
|
|
449
417
|
}
|
|
450
418
|
}
|
|
451
419
|
break
|
|
452
420
|
}
|
|
453
421
|
case 'WebkitLineClamp': {
|
|
454
|
-
hmStyle.
|
|
455
|
-
break
|
|
422
|
+
hmStyle.WebkitLineClamp = Number(value)
|
|
423
|
+
break
|
|
456
424
|
}
|
|
457
425
|
case 'transform': {
|
|
458
|
-
hmStyle.
|
|
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'
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
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.
|
|
486
|
-
case 'repeat-y': hmStyle.
|
|
487
|
-
case 'no-repeat': hmStyle.
|
|
488
|
-
default: hmStyle.
|
|
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.
|
|
565
|
+
hmStyle.backgroundSize = { width: getUnit(sizes[0]) }
|
|
498
566
|
} else if (sizes.length === 2) {
|
|
499
|
-
hmStyle.
|
|
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]
|
|
576
|
+
const vertical = positions[1]?.toLowerCase() || 'top'
|
|
509
577
|
|
|
510
578
|
if (horizontal === 'left' && vertical === 'top') {
|
|
511
|
-
hmStyle.
|
|
579
|
+
hmStyle.backgroundPosition = Alignment.TopStart
|
|
512
580
|
} else if (horizontal === 'center' && vertical === 'top') {
|
|
513
|
-
hmStyle.
|
|
581
|
+
hmStyle.backgroundPosition = Alignment.Top
|
|
514
582
|
} else if (horizontal === 'right' && vertical === 'top') {
|
|
515
|
-
hmStyle.
|
|
583
|
+
hmStyle.backgroundPosition = Alignment.TopEnd
|
|
516
584
|
} else if (horizontal === 'left' && vertical === 'center') {
|
|
517
|
-
hmStyle.
|
|
585
|
+
hmStyle.backgroundPosition = Alignment.Start
|
|
518
586
|
} else if (horizontal === 'center' && vertical === 'center') {
|
|
519
|
-
hmStyle.
|
|
587
|
+
hmStyle.backgroundPosition = Alignment.Center
|
|
520
588
|
} else if (horizontal === 'right' && vertical === 'center') {
|
|
521
|
-
hmStyle.
|
|
589
|
+
hmStyle.backgroundPosition = Alignment.End
|
|
522
590
|
} else if (horizontal === 'left' && vertical === 'bottom') {
|
|
523
|
-
hmStyle.
|
|
591
|
+
hmStyle.backgroundPosition = Alignment.BottomStart
|
|
524
592
|
} else if (horizontal === 'center' && vertical === 'bottom') {
|
|
525
|
-
hmStyle.
|
|
593
|
+
hmStyle.backgroundPosition = Alignment.Bottom
|
|
526
594
|
} else if (horizontal === 'right' && vertical === 'bottom') {
|
|
527
|
-
hmStyle.
|
|
595
|
+
hmStyle.backgroundPosition = Alignment.BottomEnd
|
|
528
596
|
} else {
|
|
529
597
|
if (/^\d+(\.\d+)?(px|%|vw|vh)$/.test(horizontal)) {
|
|
530
|
-
hmStyle.
|
|
598
|
+
hmStyle.backgroundPosition = { x: getUnit(horizontal) }
|
|
531
599
|
if (/^\d+(\.\d+)?(px|%|vw|vh)$/.test(vertical)) {
|
|
532
|
-
hmStyle.
|
|
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.
|
|
542
|
-
case 'bold': hmStyle.
|
|
543
|
-
case 'bolder': hmStyle.
|
|
544
|
-
case 'lighter': hmStyle.
|
|
545
|
-
default: hmStyle.
|
|
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
|
|
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*/)
|
|
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 =
|
|
567
|
-
transformObj.value.y =
|
|
568
|
-
transformObj.value.z =
|
|
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 =
|
|
640
|
+
transformObj.value.x = (getUnit(values[0])) || 0
|
|
572
641
|
break
|
|
573
642
|
case 'translateY':
|
|
574
|
-
transformObj.value.y =
|
|
643
|
+
transformObj.value.y = (getUnit(values[0])) || 0
|
|
575
644
|
break
|
|
576
645
|
case 'translateZ':
|
|
577
|
-
transformObj.value.z =
|
|
646
|
+
transformObj.value.z = (getUnit(values[0])) || 0
|
|
578
647
|
break
|
|
579
648
|
case 'rotate':
|
|
580
|
-
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|