@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.
- package/dist/apis/base/system.ts +53 -20
- package/dist/apis/canvas/index.ts +10 -1
- package/dist/apis/device/clipboard.ts +4 -0
- package/dist/apis/framework/index.ts +1 -5
- package/dist/apis/index.ts +27 -17
- package/dist/apis/network/request.ts +5 -5
- package/dist/apis/route/index.ts +15 -0
- package/dist/apis/storage/index.ts +148 -80
- package/dist/apis/ui/animation/animation.ts +71 -28
- package/dist/apis/ui/background.ts +2 -1
- package/dist/apis/ui/interaction/index.ts +40 -49
- package/dist/apis/ui/navigation-bar/index.ts +1 -1
- package/dist/apis/utils/index.ts +1 -1
- package/dist/apis/wxml/IntersectionObserver.ts +18 -10
- package/dist/apis/wxml/index.ts +2 -0
- package/dist/apis/wxml/selectorQuery.ts +18 -9
- package/dist/components-harmony-ets/button.ets +48 -34
- package/dist/components-harmony-ets/canvas.ets +51 -0
- package/dist/components-harmony-ets/checkbox.ets +69 -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 +27 -14
- package/dist/components-harmony-ets/index.ets +85 -0
- package/dist/components-harmony-ets/innerHtml.ets +11 -6
- package/dist/components-harmony-ets/input.ets +41 -40
- package/dist/components-harmony-ets/label.ets +69 -42
- package/dist/components-harmony-ets/movableArea.ets +126 -0
- package/dist/components-harmony-ets/movableView.ets +73 -0
- package/dist/components-harmony-ets/navigationBar.ets +25 -0
- package/dist/components-harmony-ets/pageMeta.ets +28 -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 +71 -64
- package/dist/components-harmony-ets/richText.ets +14 -30
- package/dist/components-harmony-ets/scrollView.ets +61 -57
- package/dist/components-harmony-ets/slider.ets +15 -14
- package/dist/components-harmony-ets/style.ets +390 -130
- package/dist/components-harmony-ets/swiper.ets +38 -20
- package/dist/components-harmony-ets/switch.ets +30 -28
- package/dist/components-harmony-ets/{index.ts → tag.ts} +2 -0
- package/dist/components-harmony-ets/text.ets +121 -51
- package/dist/components-harmony-ets/textArea.ets +35 -34
- package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
- package/dist/components-harmony-ets/utils/DynamicCenter.ts +1 -1
- package/dist/components-harmony-ets/utils/flexManager.ets +47 -19
- package/dist/components-harmony-ets/utils/helper.ets +17 -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 +50 -51
- package/dist/components-harmony-ets/utils/styles.ets +170 -93
- package/dist/components-harmony-ets/video.ets +34 -20
- 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 +82 -39
- 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 +31 -13
- package/dist/runtime-ets/dom/cssNesting.ts +393 -0
- package/dist/runtime-ets/dom/cssStyleDeclaration.ts +25 -39
- package/dist/runtime-ets/dom/document.ts +22 -8
- package/dist/runtime-ets/dom/element/canvas.ts +136 -0
- package/dist/runtime-ets/dom/element/element.ts +317 -51
- package/dist/runtime-ets/dom/element/form.ts +23 -26
- package/dist/runtime-ets/dom/element/index.ts +24 -2
- package/dist/runtime-ets/dom/element/movableArea.ts +12 -0
- package/dist/runtime-ets/dom/element/movableView.ts +193 -0
- package/dist/runtime-ets/dom/element/normal.ts +35 -8
- package/dist/runtime-ets/dom/element/progress.ts +12 -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 -3
- package/dist/runtime-ets/dom/element/webView.ts +11 -3
- package/dist/runtime-ets/dom/event.ts +0 -1
- package/dist/runtime-ets/dom/eventTarget.ts +0 -3
- package/dist/runtime-ets/dom/node.ts +46 -28
- package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +334 -230
- package/dist/runtime-ets/dom/stylesheet/index.ts +28 -308
- package/dist/runtime-ets/dom/stylesheet/type.ts +40 -9
- package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
- package/dist/runtime-ets/index.ts +2 -2
- package/dist/runtime-ets/interface/event.ts +1 -1
- package/dist/runtime-ets/utils/index.ts +66 -11
- package/dist/runtime-ets/utils/info.ts +1 -1
- package/dist/runtime-framework/react/app.ts +7 -2
- package/dist/runtime-framework/react/index.ts +0 -2
- package/dist/runtime-framework/react/native-page.ts +32 -14
- 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 +65 -20
- 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 +399 -188
- package/dist/runtime-utils.js.map +1 -1
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.js +399 -188
- package/dist/runtime.js.map +1 -1
- package/index.js +3 -1
- package/package.json +13 -13
- 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/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\([^)]*\)/,
|
|
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.
|
|
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: {
|
|
@@ -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.
|
|
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.
|
|
486
|
-
case 'repeat-y': hmStyle.
|
|
487
|
-
case 'no-repeat': hmStyle.
|
|
488
|
-
default: hmStyle.
|
|
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.
|
|
561
|
+
hmStyle.backgroundSize = { width: getUnit(sizes[0]) }
|
|
498
562
|
} else if (sizes.length === 2) {
|
|
499
|
-
hmStyle.
|
|
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]
|
|
572
|
+
const vertical = positions[1]?.toLowerCase() || 'top'
|
|
509
573
|
|
|
510
574
|
if (horizontal === 'left' && vertical === 'top') {
|
|
511
|
-
hmStyle.
|
|
575
|
+
hmStyle.backgroundPosition = Alignment.TopStart
|
|
512
576
|
} else if (horizontal === 'center' && vertical === 'top') {
|
|
513
|
-
hmStyle.
|
|
577
|
+
hmStyle.backgroundPosition = Alignment.Top
|
|
514
578
|
} else if (horizontal === 'right' && vertical === 'top') {
|
|
515
|
-
hmStyle.
|
|
579
|
+
hmStyle.backgroundPosition = Alignment.TopEnd
|
|
516
580
|
} else if (horizontal === 'left' && vertical === 'center') {
|
|
517
|
-
hmStyle.
|
|
581
|
+
hmStyle.backgroundPosition = Alignment.Start
|
|
518
582
|
} else if (horizontal === 'center' && vertical === 'center') {
|
|
519
|
-
hmStyle.
|
|
583
|
+
hmStyle.backgroundPosition = Alignment.Center
|
|
520
584
|
} else if (horizontal === 'right' && vertical === 'center') {
|
|
521
|
-
hmStyle.
|
|
585
|
+
hmStyle.backgroundPosition = Alignment.End
|
|
522
586
|
} else if (horizontal === 'left' && vertical === 'bottom') {
|
|
523
|
-
hmStyle.
|
|
587
|
+
hmStyle.backgroundPosition = Alignment.BottomStart
|
|
524
588
|
} else if (horizontal === 'center' && vertical === 'bottom') {
|
|
525
|
-
hmStyle.
|
|
589
|
+
hmStyle.backgroundPosition = Alignment.Bottom
|
|
526
590
|
} else if (horizontal === 'right' && vertical === 'bottom') {
|
|
527
|
-
hmStyle.
|
|
591
|
+
hmStyle.backgroundPosition = Alignment.BottomEnd
|
|
528
592
|
} else {
|
|
529
593
|
if (/^\d+(\.\d+)?(px|%|vw|vh)$/.test(horizontal)) {
|
|
530
|
-
hmStyle.
|
|
594
|
+
hmStyle.backgroundPosition = { x: getUnit(horizontal) }
|
|
531
595
|
if (/^\d+(\.\d+)?(px|%|vw|vh)$/.test(vertical)) {
|
|
532
|
-
hmStyle.
|
|
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.
|
|
542
|
-
case 'bold': hmStyle.
|
|
543
|
-
case 'bolder': hmStyle.
|
|
544
|
-
case 'lighter': hmStyle.
|
|
545
|
-
default: hmStyle.
|
|
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
|
|
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*/)
|
|
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 =
|
|
567
|
-
transformObj.value.y =
|
|
568
|
-
transformObj.value.z =
|
|
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 =
|
|
636
|
+
transformObj.value.x = (getUnit(values[0])) || 0
|
|
572
637
|
break
|
|
573
638
|
case 'translateY':
|
|
574
|
-
transformObj.value.y =
|
|
639
|
+
transformObj.value.y = (getUnit(values[0])) || 0
|
|
575
640
|
break
|
|
576
641
|
case 'translateZ':
|
|
577
|
-
transformObj.value.z =
|
|
642
|
+
transformObj.value.z = (getUnit(values[0])) || 0
|
|
578
643
|
break
|
|
579
644
|
case 'rotate':
|
|
580
|
-
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|