@tarojs/plugin-platform-harmony-ets 4.0.0-beta.30 → 4.0.0-beta.32
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/index.ts +4 -5
- package/dist/apis/storage/index.ts +93 -15
- package/dist/components-harmony-ets/style.ets +51 -48
- package/dist/components-harmony-ets/utils/styles.ets +0 -8
- package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +141 -23
- package/dist/runtime-ets/dom/stylesheet/util.ts +3 -3
- package/dist/runtime-utils.d.ts +7 -7
- package/dist/runtime-utils.js +123 -22
- package/dist/runtime-utils.js.map +1 -1
- package/dist/runtime.js +123 -22
- package/dist/runtime.js.map +1 -1
- package/package.json +9 -9
package/dist/apis/index.ts
CHANGED
|
@@ -105,19 +105,18 @@ export function pxTransformHelper (size: number, unit?: string, isNumber = false
|
|
|
105
105
|
return isNumber ? val : val + targetUnit
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
export function pxTransform (size: number): number {
|
|
108
|
+
export function pxTransform (size: number): number | string {
|
|
109
109
|
const config = (Current as any).taro?.config || {}
|
|
110
110
|
const targetUnit = config.targetUnit || defaultTargetUnit
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
const val = size
|
|
113
113
|
switch (targetUnit) {
|
|
114
114
|
case 'vp':
|
|
115
|
-
|
|
116
|
-
break
|
|
115
|
+
return pxTransformHelper(size, 'px')
|
|
117
116
|
default:
|
|
118
117
|
// NOTE: 鸿蒙环境下 style 会自动完成设计稿转换,无需在方法内二次调整
|
|
119
118
|
}
|
|
120
|
-
return val +
|
|
119
|
+
return val + targetUnit
|
|
121
120
|
}
|
|
122
121
|
|
|
123
122
|
export function canIUseWebp () {
|
|
@@ -22,7 +22,7 @@ let preferences: any
|
|
|
22
22
|
|
|
23
23
|
function getPreferences () {
|
|
24
24
|
try {
|
|
25
|
-
if (!preferences) {
|
|
25
|
+
if (!preferences && context) {
|
|
26
26
|
const data = bundleManager.getBundleInfoForSelfSync(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION)
|
|
27
27
|
preferences = dataPreferences.getPreferencesSync(context, { name: `${data.appInfo.uid}Store` })
|
|
28
28
|
}
|
|
@@ -37,13 +37,42 @@ const storageSchema = {
|
|
|
37
37
|
key: 'String'
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
function checkContextExist (api: string, isAsync = false) {
|
|
41
|
+
if (!context) {
|
|
42
|
+
const message = `${api} 调用失败,Taro 不支持过早地调用 ${api},请确保页面已经渲染完成再调用此 API`
|
|
43
|
+
if (isAsync) {
|
|
44
|
+
return {
|
|
45
|
+
isExist: false,
|
|
46
|
+
error: Promise.reject(new Error(message))
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
console.warn(message)
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
isExist: false,
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
isExist: true,
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
40
62
|
export function getStorage<T = any> (options: Taro.getStorage.Option<T>) {
|
|
63
|
+
const name = 'getStorage'
|
|
64
|
+
const { isExist, error } = checkContextExist(name, true)
|
|
65
|
+
|
|
66
|
+
if (!isExist) {
|
|
67
|
+
return error
|
|
68
|
+
}
|
|
69
|
+
|
|
41
70
|
const { key, success, fail, complete } = options || {}
|
|
42
|
-
const handle = new MethodHandler<{data: any}>({ name
|
|
71
|
+
const handle = new MethodHandler<{data: any}>({ name, success, fail, complete })
|
|
43
72
|
|
|
44
73
|
return new Promise((resolve, reject) => {
|
|
45
74
|
try {
|
|
46
|
-
validateParams(
|
|
75
|
+
validateParams(name, options, storageSchema)
|
|
47
76
|
} catch (error) {
|
|
48
77
|
const res = { errMsg: error.message }
|
|
49
78
|
return handle.fail(res, { resolve, reject })
|
|
@@ -63,14 +92,21 @@ export function getStorage<T = any> (options: Taro.getStorage.Option<T>) {
|
|
|
63
92
|
}
|
|
64
93
|
|
|
65
94
|
export function getStorageSync (key: string) {
|
|
95
|
+
const name = 'getStorageSync'
|
|
96
|
+
const { isExist, error } = checkContextExist(name, false)
|
|
97
|
+
|
|
98
|
+
if (!isExist) {
|
|
99
|
+
return error
|
|
100
|
+
}
|
|
101
|
+
|
|
66
102
|
if (!key) {
|
|
67
|
-
throw new Error(
|
|
103
|
+
throw new Error(`${name}:fail parameter error: parameter should be String`)
|
|
68
104
|
}
|
|
69
105
|
|
|
70
106
|
const preferences = getPreferences()
|
|
71
107
|
|
|
72
108
|
if (!preferences) {
|
|
73
|
-
throw new Error(
|
|
109
|
+
throw new Error(`${name}:fail:preferences is null`)
|
|
74
110
|
}
|
|
75
111
|
|
|
76
112
|
const data = preferences.getSync(key, null)
|
|
@@ -82,12 +118,19 @@ export function getStorageSync (key: string) {
|
|
|
82
118
|
}
|
|
83
119
|
|
|
84
120
|
export function setStorage (options: Taro.setStorage.Option) {
|
|
121
|
+
const name = 'setStorage'
|
|
122
|
+
const { isExist, error } = checkContextExist(name, true)
|
|
123
|
+
|
|
124
|
+
if (!isExist) {
|
|
125
|
+
return error
|
|
126
|
+
}
|
|
127
|
+
|
|
85
128
|
const { key, data, success, fail, complete } = options || {}
|
|
86
|
-
const handle = new MethodHandler({ name
|
|
129
|
+
const handle = new MethodHandler({ name, success, fail, complete })
|
|
87
130
|
|
|
88
131
|
return new Promise((resolve, reject) => {
|
|
89
132
|
try {
|
|
90
|
-
validateParams(
|
|
133
|
+
validateParams(name, options, storageSchema)
|
|
91
134
|
} catch (error) {
|
|
92
135
|
const res = { errMsg: error.message }
|
|
93
136
|
return handle.fail(res, { resolve, reject })
|
|
@@ -105,14 +148,21 @@ export function setStorage (options: Taro.setStorage.Option) {
|
|
|
105
148
|
}
|
|
106
149
|
|
|
107
150
|
export function setStorageSync (key: string, data: any) {
|
|
151
|
+
const name = 'setStorageSync'
|
|
152
|
+
const { isExist, error } = checkContextExist(name, false)
|
|
153
|
+
|
|
154
|
+
if (!isExist) {
|
|
155
|
+
return error
|
|
156
|
+
}
|
|
157
|
+
|
|
108
158
|
if (!key) {
|
|
109
|
-
throw new Error(
|
|
159
|
+
throw new Error(`${name}:fail key error: key should be String`)
|
|
110
160
|
}
|
|
111
161
|
|
|
112
162
|
const preferences = getPreferences()
|
|
113
163
|
|
|
114
164
|
if (!preferences) {
|
|
115
|
-
throw new Error(
|
|
165
|
+
throw new Error(`${name}:fail:preferences is null`)
|
|
116
166
|
}
|
|
117
167
|
|
|
118
168
|
preferences.putSync(key, data)
|
|
@@ -120,12 +170,19 @@ export function setStorageSync (key: string, data: any) {
|
|
|
120
170
|
}
|
|
121
171
|
|
|
122
172
|
export function removeStorage (options: Taro.removeStorage.Option) {
|
|
173
|
+
const name = 'removeStorage'
|
|
174
|
+
const { isExist, error } = checkContextExist(name, true)
|
|
175
|
+
|
|
176
|
+
if (!isExist) {
|
|
177
|
+
return error
|
|
178
|
+
}
|
|
179
|
+
|
|
123
180
|
const { key, success, fail, complete } = options || {}
|
|
124
|
-
const handle = new MethodHandler({ name
|
|
181
|
+
const handle = new MethodHandler({ name, success, fail, complete })
|
|
125
182
|
|
|
126
183
|
return new Promise((resolve, reject) => {
|
|
127
184
|
try {
|
|
128
|
-
validateParams(
|
|
185
|
+
validateParams(name, options, storageSchema)
|
|
129
186
|
} catch (error) {
|
|
130
187
|
const res = { errMsg: error.message }
|
|
131
188
|
return handle.fail(res, { resolve, reject })
|
|
@@ -143,14 +200,21 @@ export function removeStorage (options: Taro.removeStorage.Option) {
|
|
|
143
200
|
}
|
|
144
201
|
|
|
145
202
|
export function removeStorageSync (key: string) {
|
|
203
|
+
const name = 'removeStorageSync'
|
|
204
|
+
const { isExist, error } = checkContextExist(name, false)
|
|
205
|
+
|
|
206
|
+
if (!isExist) {
|
|
207
|
+
return error
|
|
208
|
+
}
|
|
209
|
+
|
|
146
210
|
if (!key) {
|
|
147
|
-
throw new Error(
|
|
211
|
+
throw new Error(`${name}:fail key error: key should be String`)
|
|
148
212
|
}
|
|
149
213
|
|
|
150
214
|
const preferences = getPreferences()
|
|
151
215
|
|
|
152
216
|
if (!preferences) {
|
|
153
|
-
throw new Error(
|
|
217
|
+
throw new Error(`${name}:fail:preferences is null`)
|
|
154
218
|
}
|
|
155
219
|
|
|
156
220
|
preferences.deleteSync(key)
|
|
@@ -158,8 +222,15 @@ export function removeStorageSync (key: string) {
|
|
|
158
222
|
}
|
|
159
223
|
|
|
160
224
|
export function clearStorage (options: Taro.clearStorage.Option) {
|
|
225
|
+
const name = 'clearStorage'
|
|
226
|
+
const { isExist, error } = checkContextExist(name, true)
|
|
227
|
+
|
|
228
|
+
if (!isExist) {
|
|
229
|
+
return error
|
|
230
|
+
}
|
|
231
|
+
|
|
161
232
|
const { success, fail, complete } = options || {}
|
|
162
|
-
const handle = new MethodHandler({ name
|
|
233
|
+
const handle = new MethodHandler({ name, success, fail, complete })
|
|
163
234
|
|
|
164
235
|
return new Promise((resolve, reject) => {
|
|
165
236
|
const preferences = getPreferences()
|
|
@@ -174,10 +245,17 @@ export function clearStorage (options: Taro.clearStorage.Option) {
|
|
|
174
245
|
}
|
|
175
246
|
|
|
176
247
|
export function clearStorageSync () {
|
|
248
|
+
const name = 'clearStorageSync'
|
|
249
|
+
const { isExist, error } = checkContextExist(name, false)
|
|
250
|
+
|
|
251
|
+
if (!isExist) {
|
|
252
|
+
return error
|
|
253
|
+
}
|
|
254
|
+
|
|
177
255
|
const preferences = getPreferences()
|
|
178
256
|
|
|
179
257
|
if (!preferences) {
|
|
180
|
-
throw new Error(
|
|
258
|
+
throw new Error(`${name}:fail:preferences is null`)
|
|
181
259
|
}
|
|
182
260
|
|
|
183
261
|
preferences.clearSync()
|
|
@@ -36,7 +36,7 @@ class CommonStyleModify implements AttributeModifier<CommonAttribute> {
|
|
|
36
36
|
setNormalAttributeIntoInstance(instance, this.style, this.node)
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
setAnimationAttributeIntoInstance(instance, this.overwriteStyle)
|
|
39
|
+
setAnimationAttributeIntoInstance(instance, this.overwriteStyle, this.style || {})
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -69,7 +69,7 @@ class RowStyleModify extends CommonStyleModify {
|
|
|
69
69
|
})
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
setAnimationAttributeIntoInstance(instance, this.overwriteStyle)
|
|
72
|
+
setAnimationAttributeIntoInstance(instance, this.overwriteStyle, this.style || {})
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
@@ -85,29 +85,31 @@ class ColumnStyleModify extends CommonStyleModify {
|
|
|
85
85
|
})
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
setAnimationAttributeIntoInstance(instance, this.overwriteStyle)
|
|
88
|
+
setAnimationAttributeIntoInstance(instance, this.overwriteStyle, this.style || {})
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
function setAnimationAttributeIntoInstance(instance: CommonAttribute, overwriteStyle: Record<string, TaroAny
|
|
92
|
+
function setAnimationAttributeIntoInstance(instance: CommonAttribute, overwriteStyle: Record<string, TaroAny>, style: TaroStyleType) {
|
|
93
93
|
// Animation 需要提前和 @State 变量绑定才能产生动画效果,因此不能做 if else 判断
|
|
94
94
|
instance.translate({
|
|
95
|
-
x: overwriteStyle.translate?.x,
|
|
96
|
-
y: overwriteStyle.translate?.y,
|
|
97
|
-
z: overwriteStyle.translate?.z,
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
95
|
+
x: overwriteStyle.translate?.x || style.transform?.Translate?.x,
|
|
96
|
+
y: overwriteStyle.translate?.y || style.transform?.Translate?.y,
|
|
97
|
+
z: overwriteStyle.translate?.z || style.transform?.Translate?.z,
|
|
98
|
+
})
|
|
99
|
+
instance.scale({
|
|
100
|
+
x: overwriteStyle.scale?.x || style.transform?.Scale?.x,
|
|
101
|
+
y: overwriteStyle.scale?.y || style.transform?.Scale?.y,
|
|
102
|
+
z: overwriteStyle.scale?.z || style.transform?.Scale?.z,
|
|
103
|
+
centerX: overwriteStyle.transformOrigin?.x || style.transformOrigin?.x || 0,
|
|
104
|
+
centerY: overwriteStyle.transformOrigin?.y || style.transformOrigin?.y || 0,
|
|
105
|
+
})
|
|
106
|
+
instance.rotate({
|
|
107
|
+
x: overwriteStyle.rotate?.x || style.transform?.Rotate?.x,
|
|
108
|
+
y: overwriteStyle.rotate?.y || style.transform?.Rotate?.y,
|
|
109
|
+
z: overwriteStyle.rotate?.z || style.transform?.Rotate?.z,
|
|
110
|
+
centerX: overwriteStyle.transformOrigin?.x || style.transformOrigin?.x || 0,
|
|
111
|
+
centerY: overwriteStyle.transformOrigin?.y || style.transformOrigin?.y || 0,
|
|
112
|
+
angle: overwriteStyle.rotate?.angle || style.transform?.Rotate?.angle || 0,
|
|
111
113
|
})
|
|
112
114
|
}
|
|
113
115
|
|
|
@@ -231,34 +233,35 @@ function setNormalAttributeIntoInstance(instance: CommonAttribute, style: TaroSt
|
|
|
231
233
|
// instance.rotate({ centerX: style.transformOrigin.x, centerY: style.transformOrigin.y, angle: 0 })
|
|
232
234
|
// instance.scale({ centerX: style.transformOrigin.x, centerY: style.transformOrigin.y })
|
|
233
235
|
// }
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
}
|
|
236
|
+
// // Note: 移植到setAnimationAttributeIntoInstance设置
|
|
237
|
+
// if (!isUndefined(style.transform)) {
|
|
238
|
+
// if (style.transform.Translate) {
|
|
239
|
+
// instance.translate({
|
|
240
|
+
// x: style.transform.Translate.x || 0,
|
|
241
|
+
// y: style.transform.Translate.y || 0,
|
|
242
|
+
// z: style.transform.Translate.z || 0,
|
|
243
|
+
// })
|
|
244
|
+
// }
|
|
245
|
+
// if (style.transform.Scale) {
|
|
246
|
+
// instance.scale({
|
|
247
|
+
// x: style.transform.Scale.x || 0,
|
|
248
|
+
// y: style.transform.Scale.y || 0,
|
|
249
|
+
// z: style.transform.Scale.z || 0,
|
|
250
|
+
// centerX: style.transformOrigin?.x || 0,
|
|
251
|
+
// centerY: style.transformOrigin?.y || 0,
|
|
252
|
+
// })
|
|
253
|
+
// }
|
|
254
|
+
// if (style.transform.Rotate) {
|
|
255
|
+
// instance.rotate({
|
|
256
|
+
// x: style.transform.Rotate.x || 0,
|
|
257
|
+
// y: style.transform.Rotate.y || 0,
|
|
258
|
+
// z: style.transform.Rotate.z || 0,
|
|
259
|
+
// centerX: style.transformOrigin?.x || 0,
|
|
260
|
+
// centerY: style.transformOrigin?.y || 0,
|
|
261
|
+
// angle: 0
|
|
262
|
+
// })
|
|
263
|
+
// }
|
|
264
|
+
// }
|
|
262
265
|
if (style.position === 'absolute' || style.position === 'fixed') {
|
|
263
266
|
instance.position({
|
|
264
267
|
x: style.left || 0,
|
|
@@ -106,14 +106,6 @@ export function getNormalAttributes (node: TaroElement, initStyle?: HarmonyStyle
|
|
|
106
106
|
normalAttributes = ObjectAssign({}, normalAttributes, pseudoStylesheet)
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
// taro_page 等写死在运行时里的节点,没有 _nodeInfo
|
|
110
|
-
if (node._nodeInfo) {
|
|
111
|
-
const overwriteStyle: TaroStyleType = node._nodeInfo?.overwriteStyle
|
|
112
|
-
// 处理覆盖属性:如动画的覆盖
|
|
113
|
-
if (overwriteStyle) {
|
|
114
|
-
normalAttributes = ObjectAssign({}, normalAttributes, overwriteStyle)
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
109
|
// 初始化默认的值
|
|
118
110
|
if (initStyle) {
|
|
119
111
|
normalAttributes = ObjectAssign({}, initStyle, normalAttributes)
|
|
@@ -5,6 +5,15 @@ import { CSSProperties } from 'react'
|
|
|
5
5
|
import { TaroElement } from '../element/element'
|
|
6
6
|
import { BORDER_STYLE_MAP, capitalizeFirstLetter, FlexManager, getNodeMarginOrPaddingData, getUnit } from './util'
|
|
7
7
|
|
|
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
|
|
15
|
+
}
|
|
16
|
+
|
|
8
17
|
// Note: 将 web 端的 style 转换为 hm 端的 style
|
|
9
18
|
export default function convertWebStyle2HmStyle(webStyle: CSSProperties, node?: TaroElement) {
|
|
10
19
|
const hmStyle: Record<string, any> = node?._st?.hmStyle || {}
|
|
@@ -155,7 +164,12 @@ export default function convertWebStyle2HmStyle(webStyle: CSSProperties, node?:
|
|
|
155
164
|
break
|
|
156
165
|
}
|
|
157
166
|
case 'background': {
|
|
158
|
-
|
|
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'])
|
|
159
173
|
break
|
|
160
174
|
}
|
|
161
175
|
case 'backgroundColor': {
|
|
@@ -409,8 +423,11 @@ export default function convertWebStyle2HmStyle(webStyle: CSSProperties, node?:
|
|
|
409
423
|
break
|
|
410
424
|
}
|
|
411
425
|
case 'transform': {
|
|
412
|
-
|
|
413
|
-
|
|
426
|
+
hmStyle.transform = parseTransform(value)
|
|
427
|
+
break
|
|
428
|
+
}
|
|
429
|
+
case 'transformOrigin': {
|
|
430
|
+
hmStyle.transformOrigin = parseTransformOrigin(value)
|
|
414
431
|
break
|
|
415
432
|
}
|
|
416
433
|
case 'position': {
|
|
@@ -456,6 +473,61 @@ function setBackgroundImage(hmStyle, value) {
|
|
|
456
473
|
// todo 渐变需要处理
|
|
457
474
|
}
|
|
458
475
|
|
|
476
|
+
// 解析background属性
|
|
477
|
+
function setBackground (backgroundValue: string) {
|
|
478
|
+
const result = {
|
|
479
|
+
'background-color': '',
|
|
480
|
+
'background-image': '',
|
|
481
|
+
'background-repeat': '',
|
|
482
|
+
'background-position': '',
|
|
483
|
+
'background-size': ''
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
if (!backgroundValue) return result
|
|
487
|
+
|
|
488
|
+
// 匹配background-image
|
|
489
|
+
const imageMatch = backgroundValue.match(BACKGROUND_REGEX.IMAGE)
|
|
490
|
+
if (imageMatch) {
|
|
491
|
+
result['background-image'] = imageMatch[0]
|
|
492
|
+
backgroundValue = backgroundValue.replace(imageMatch[0], '').trim()
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
// 匹配background-color
|
|
496
|
+
const colorMatch = backgroundValue.match(BACKGROUND_REGEX.COLOR)
|
|
497
|
+
if (colorMatch) {
|
|
498
|
+
result['background-color'] = colorMatch[0]
|
|
499
|
+
backgroundValue = backgroundValue.replace(colorMatch[0], '').trim()
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// 匹配background-repeat
|
|
503
|
+
const repeatMatch = backgroundValue.match(BACKGROUND_REGEX.REPEAT)
|
|
504
|
+
if (repeatMatch) {
|
|
505
|
+
result['background-repeat'] = repeatMatch[0]
|
|
506
|
+
backgroundValue = backgroundValue.replace(repeatMatch[0], '').trim()
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
// 匹配background-position,background-size
|
|
510
|
+
// 先分割 / 分割出background-position\background-size
|
|
511
|
+
const positionSize = backgroundValue.split('/')
|
|
512
|
+
const [position, size] = positionSize
|
|
513
|
+
// 匹配background-position
|
|
514
|
+
if (position) {
|
|
515
|
+
const positionMatch = position.match(BACKGROUND_REGEX.POSITION)
|
|
516
|
+
if (positionMatch) {
|
|
517
|
+
result['background-position'] = positionMatch.join(' ')
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
if (size) {
|
|
521
|
+
// 匹配background-size
|
|
522
|
+
const sizeMatch = size.match(BACKGROUND_REGEX.SIZE)
|
|
523
|
+
if (sizeMatch) {
|
|
524
|
+
result['background-size'] = sizeMatch.join(' ')
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
return result
|
|
529
|
+
}
|
|
530
|
+
|
|
459
531
|
function setBackgroundRepeat(hmStyle, value) {
|
|
460
532
|
if (typeof value === 'string') {
|
|
461
533
|
switch (value) {
|
|
@@ -469,6 +541,13 @@ function setBackgroundRepeat(hmStyle, value) {
|
|
|
469
541
|
|
|
470
542
|
function setBackgroundSize(hmStyle, value) {
|
|
471
543
|
if (typeof value === 'string') {
|
|
544
|
+
if (value === 'cover') {
|
|
545
|
+
hmStyle.backgroundSize = ImageSize.Cover
|
|
546
|
+
return
|
|
547
|
+
} else if (value === 'contain') {
|
|
548
|
+
hmStyle.backgroundSize = ImageSize.Contain
|
|
549
|
+
return
|
|
550
|
+
}
|
|
472
551
|
const sizes = value.split(' ')
|
|
473
552
|
if (sizes.length === 1) {
|
|
474
553
|
hmStyle.backgroundSize = { width: getUnit(sizes[0]) }
|
|
@@ -482,7 +561,7 @@ function setBackgroundPosistion (hmStyle, value) {
|
|
|
482
561
|
if (typeof value === 'string') {
|
|
483
562
|
const positions = value.split(' ')
|
|
484
563
|
const horizontal = positions[0].toLowerCase()
|
|
485
|
-
const vertical = positions[1]
|
|
564
|
+
const vertical = positions[1]?.toLowerCase() || 'top'
|
|
486
565
|
|
|
487
566
|
if (horizontal === 'left' && vertical === 'top') {
|
|
488
567
|
hmStyle.backgroundPosition = Alignment.TopStart
|
|
@@ -526,12 +605,12 @@ function setFontWeight (hmStyle, value) {
|
|
|
526
605
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
527
606
|
function parseTransform(transformString) {
|
|
528
607
|
const transformRegex = /(\w+)\(([^)]+)\)/g
|
|
529
|
-
const
|
|
608
|
+
const transform = {}
|
|
530
609
|
|
|
531
610
|
let matchs
|
|
532
611
|
while ((matchs = transformRegex.exec(transformString)) !== null) {
|
|
533
612
|
const [, type, valueString] = matchs
|
|
534
|
-
const values = valueString.split(/\s*,\s*/)
|
|
613
|
+
const values = valueString.split(/\s*,\s*/)
|
|
535
614
|
|
|
536
615
|
const transformObj = {
|
|
537
616
|
type: capitalizeFirstLetter(type),
|
|
@@ -541,62 +620,101 @@ function parseTransform(transformString) {
|
|
|
541
620
|
switch (type) {
|
|
542
621
|
case 'translate':
|
|
543
622
|
case 'translate3d':
|
|
544
|
-
transformObj.value.x =
|
|
545
|
-
transformObj.value.y =
|
|
546
|
-
transformObj.value.z =
|
|
623
|
+
transformObj.value.x = (getUnit(values[0])) || 0
|
|
624
|
+
transformObj.value.y = (getUnit(values[1])) || 0
|
|
625
|
+
transformObj.value.z = (getUnit(values[2])) || 0
|
|
547
626
|
break
|
|
548
627
|
case 'translateX':
|
|
549
|
-
transformObj.value.x =
|
|
628
|
+
transformObj.value.x = (getUnit(values[0])) || 0
|
|
550
629
|
break
|
|
551
630
|
case 'translateY':
|
|
552
|
-
transformObj.value.y =
|
|
631
|
+
transformObj.value.y = (getUnit(values[0])) || 0
|
|
553
632
|
break
|
|
554
633
|
case 'translateZ':
|
|
555
|
-
transformObj.value.z =
|
|
634
|
+
transformObj.value.z = (getUnit(values[0])) || 0
|
|
556
635
|
break
|
|
557
636
|
case 'rotate':
|
|
558
|
-
|
|
637
|
+
case 'rotateZ':
|
|
638
|
+
transformObj.value.angle = (getUnit(values[0])) || 0
|
|
559
639
|
transformObj.value.x = 0
|
|
560
640
|
transformObj.value.y = 0
|
|
561
641
|
transformObj.value.z = 1
|
|
562
642
|
break
|
|
563
643
|
case 'rotate3d':
|
|
564
|
-
transformObj.value.angle =
|
|
644
|
+
transformObj.value.angle = getUnit(values[0]) || 0
|
|
565
645
|
transformObj.value.x = values[1] || 0
|
|
566
646
|
transformObj.value.y = values[2] || 0
|
|
567
647
|
transformObj.value.z = values[3] || 0
|
|
568
648
|
break
|
|
569
649
|
case 'rotateX':
|
|
570
|
-
transformObj.value.angle =
|
|
650
|
+
transformObj.value.angle = getUnit(values[0]) || 0
|
|
571
651
|
transformObj.value.x = 1
|
|
572
652
|
transformObj.value.y = 0
|
|
573
653
|
transformObj.value.z = 0
|
|
574
654
|
break
|
|
575
655
|
case 'rotateY':
|
|
576
|
-
transformObj.value.angle =
|
|
656
|
+
transformObj.value.angle = getUnit(values[0]) || 0
|
|
577
657
|
transformObj.value.x = 0
|
|
578
658
|
transformObj.value.y = 1
|
|
579
659
|
transformObj.value.z = 0
|
|
580
660
|
break
|
|
581
661
|
case 'scale':
|
|
582
662
|
case 'scale3d':
|
|
583
|
-
transformObj.value.x = values[0] || 1
|
|
584
|
-
transformObj.value.y = values[1] || values[0] || 1
|
|
585
|
-
transformObj.value.z = values[2] || 1
|
|
663
|
+
transformObj.value.x = parseFloat(values[0]) || 1
|
|
664
|
+
transformObj.value.y = parseFloat(values[1] || values[0]) || 1
|
|
665
|
+
transformObj.value.z = parseFloat(values[2]) || 1
|
|
586
666
|
break
|
|
587
667
|
case 'scaleX':
|
|
588
|
-
transformObj.value.x = values[0] || 1
|
|
668
|
+
transformObj.value.x = parseFloat(values[0]) || 1
|
|
589
669
|
break
|
|
590
670
|
case 'scaleY':
|
|
591
|
-
transformObj.value.y = values[0] || 1
|
|
671
|
+
transformObj.value.y = parseFloat(values[0]) || 1
|
|
592
672
|
break
|
|
593
673
|
default:
|
|
594
674
|
// Handle unrecognized transform types or ignore them
|
|
595
675
|
break
|
|
596
676
|
}
|
|
597
677
|
|
|
598
|
-
|
|
678
|
+
transform[transformObj.type] = transformObj.value
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
return transform
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
// 方向转百分比
|
|
685
|
+
function directionToPercent(direction: string) {
|
|
686
|
+
switch (direction) {
|
|
687
|
+
case 'top':
|
|
688
|
+
case 'left':
|
|
689
|
+
return '0%'
|
|
690
|
+
case 'center':
|
|
691
|
+
return '50%'
|
|
692
|
+
case 'bottom':
|
|
693
|
+
case 'right':
|
|
694
|
+
return '100%'
|
|
695
|
+
default:
|
|
696
|
+
return direction
|
|
599
697
|
}
|
|
698
|
+
}
|
|
600
699
|
|
|
601
|
-
|
|
700
|
+
// 解析transform-orgin
|
|
701
|
+
function parseTransformOrigin (value: string) {
|
|
702
|
+
if (typeof value === 'string') {
|
|
703
|
+
const values = value.split(' ')
|
|
704
|
+
if (values.length === 1) {
|
|
705
|
+
return {
|
|
706
|
+
x: getUnit(directionToPercent(values[0])),
|
|
707
|
+
y: getUnit(directionToPercent(values[0]))
|
|
708
|
+
}
|
|
709
|
+
} else if (values.length === 2) {
|
|
710
|
+
return {
|
|
711
|
+
x: getUnit(directionToPercent(values[0])),
|
|
712
|
+
y: getUnit(directionToPercent(values[1]))
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
return {
|
|
717
|
+
x: 0,
|
|
718
|
+
y: 0
|
|
719
|
+
}
|
|
602
720
|
}
|
|
@@ -220,14 +220,14 @@ export function getUnit (val) {
|
|
|
220
220
|
// 空的字符串代表 Reconciler remove 了这个 prop,不进行后面的逻辑了
|
|
221
221
|
if (val === '') return val
|
|
222
222
|
|
|
223
|
-
if (/\d+(vp)$/.test(val)) {
|
|
223
|
+
if (/\d+(vp|px)$/.test(val)) {
|
|
224
224
|
return val
|
|
225
225
|
} else if (isNumber(val)) {
|
|
226
|
-
return
|
|
226
|
+
return parseFloat(val) + 'px'
|
|
227
227
|
}
|
|
228
228
|
if (val) {
|
|
229
229
|
// 匹配vw\vh
|
|
230
|
-
const exec = val.match(/(-?\d*(\.\d+)?)(vw|vh
|
|
230
|
+
const exec = val.match(/(-?\d*(\.\d+)?)(vw|vh)$/)
|
|
231
231
|
if (exec) {
|
|
232
232
|
const [, num, , unit] = exec
|
|
233
233
|
return convertNumber2VP(parseFloat(num), unit)
|
package/dist/runtime-utils.d.ts
CHANGED
|
@@ -501,14 +501,14 @@ declare namespace apis {
|
|
|
501
501
|
const getShareInfo: (option?: {}, ...args: any[]) => Promise<Partial<ICallbackResult> & Record<string, unknown> & ICallbackResult>;
|
|
502
502
|
/** 验证私密消息。 */
|
|
503
503
|
const authPrivateMessage: (option?: {}, ...args: any[]) => Promise<ICallbackResult & Record<string, unknown>>;
|
|
504
|
-
function getStorage<T = any>(options: Taro.getStorage.Option<T>): Promise<unknown
|
|
504
|
+
function getStorage<T = any>(options: Taro.getStorage.Option<T>): Promise<unknown> | undefined;
|
|
505
505
|
function getStorageSync(key: string): any;
|
|
506
|
-
function setStorage(options: Taro.setStorage.Option): Promise<unknown
|
|
507
|
-
function setStorageSync(key: string, data: any):
|
|
508
|
-
function removeStorage(options: Taro.removeStorage.Option): Promise<unknown
|
|
509
|
-
function removeStorageSync(key: string):
|
|
510
|
-
function clearStorage(options: Taro.clearStorage.Option): Promise<unknown
|
|
511
|
-
function clearStorageSync():
|
|
506
|
+
function setStorage(options: Taro.setStorage.Option): Promise<unknown> | undefined;
|
|
507
|
+
function setStorageSync(key: string, data: any): Promise<never> | undefined;
|
|
508
|
+
function removeStorage(options: Taro.removeStorage.Option): Promise<unknown> | undefined;
|
|
509
|
+
function removeStorageSync(key: string): Promise<never> | undefined;
|
|
510
|
+
function clearStorage(options: Taro.clearStorage.Option): Promise<unknown> | undefined;
|
|
511
|
+
function clearStorageSync(): Promise<never> | undefined;
|
|
512
512
|
const getStorageInfoSync: (option?: {}, ...args: any[]) => Promise<Partial<ICallbackResult> & Record<string, unknown> & ICallbackResult>;
|
|
513
513
|
const getStorageInfo: (option?: {}, ...args: any[]) => Promise<Partial<ICallbackResult> & Record<string, unknown> & ICallbackResult>;
|
|
514
514
|
const createBufferURL: (option?: {}, ...args: any[]) => Promise<Partial<ICallbackResult> & Record<string, unknown> & ICallbackResult>;
|