@tarojs/plugin-platform-harmony-ets 4.0.0-beta.11 → 4.0.0-beta.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/apis/base/system.ts +40 -22
  2. package/dist/apis/framework/index.ts +1 -5
  3. package/dist/apis/index.ts +1 -1
  4. package/dist/components-harmony-ets/checkbox.ets +2 -2
  5. package/dist/components-harmony-ets/form.ets +1 -1
  6. package/dist/components-harmony-ets/label.ets +1 -1
  7. package/dist/components-harmony-ets/movableArea.ets +1 -1
  8. package/dist/components-harmony-ets/movableView.ets +1 -1
  9. package/dist/components-harmony-ets/picker.ets +5 -5
  10. package/dist/components-harmony-ets/pseudo.ets +72 -0
  11. package/dist/components-harmony-ets/radio.ets +3 -3
  12. package/dist/components-harmony-ets/scrollView.ets +8 -7
  13. package/dist/components-harmony-ets/style.ets +144 -123
  14. package/dist/components-harmony-ets/utils/flexManager.ets +6 -6
  15. package/dist/components-harmony-ets/utils/helper.ets +2 -2
  16. package/dist/components-harmony-ets/utils/styles.ets +33 -16
  17. package/dist/components-harmony-ets/view.ets +4 -4
  18. package/dist/index.js +1 -1
  19. package/dist/index.js.map +1 -1
  20. package/dist/runtime-ets/bom/window.ts +2 -0
  21. package/dist/runtime-ets/current.ts +2 -0
  22. package/dist/runtime-ets/dom/element/element.ts +41 -4
  23. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +43 -20
  24. package/dist/runtime-ets/dom/stylesheet/index.ts +21 -14
  25. package/dist/runtime-ets/dom/stylesheet/type.ts +1 -0
  26. package/dist/runtime-framework/react/app.ts +5 -1
  27. package/dist/runtime-framework/react/native-page.ts +5 -1
  28. package/dist/runtime-framework/react/page.ts +1 -0
  29. package/dist/runtime-utils.js +45 -24
  30. package/dist/runtime-utils.js.map +1 -1
  31. package/dist/runtime.js +45 -24
  32. package/dist/runtime.js.map +1 -1
  33. package/package.json +8 -8
@@ -1,25 +1,42 @@
1
+ import ConfigurationConstant from '@ohos.app.ability.ConfigurationConstant'
1
2
  // 设备信息,从 API Version 6 开始支持
2
3
  import deviceInfo from '@ohos.deviceInfo'
3
4
  // 显示设备属性,从 API Version 7 开始支持
4
5
  import _display from '@ohos.display'
5
6
  // 从 API Version 7 开始支持
6
7
  import i18n from '@ohos.i18n'
7
- // 设备信息 从API Version 6开始,该接口不再维护,推荐使用新接口'@ohos.deviceInfo'进行设备信息查询
8
- import deviceMethod from '@system.device'
9
8
 
10
9
  import { callAsyncFail, callAsyncSuccess } from '../utils'
11
10
 
12
11
  import type Taro from '@tarojs/taro/types'
13
12
 
14
- const display = _display.getDefaultDisplaySync()
15
-
16
- let device
13
+ let display
14
+ let safeArea: TaroGeneral.SafeAreaResult | null = null
15
+ try {
16
+ display = _display.getDefaultDisplaySync()
17
+ // @ts-ignore
18
+ display.getCutoutInfo((err, { boundingRects = [], waterfallDisplayAreaRects = {} }: _display.CutoutInfo = {}) => {
19
+ if (err?.code) {
20
+ console.error('Failed to get cutout info', JSON.stringify(err))
21
+ return
22
+ }
17
23
 
18
- deviceMethod.getInfo({
19
- success: data => {
20
- device = data
21
- }
22
- })
24
+ const top = Math.max(...boundingRects.map(rect => rect.top * 2 + rect.height), waterfallDisplayAreaRects.top?.top + waterfallDisplayAreaRects.top?.height)
25
+ const bottom = (waterfallDisplayAreaRects.bottom?.top + waterfallDisplayAreaRects.bottom?.height) || display.height
26
+ const left = waterfallDisplayAreaRects.left?.left + waterfallDisplayAreaRects.left?.width
27
+ const right = (waterfallDisplayAreaRects.right?.left + waterfallDisplayAreaRects.right?.width) || display.width
28
+ safeArea = {
29
+ top,
30
+ bottom,
31
+ left,
32
+ right,
33
+ height: bottom - top,
34
+ width: right - left,
35
+ }
36
+ })
37
+ } catch (e) {
38
+ console.error('Failed to get display', e)
39
+ }
23
40
 
24
41
  /* 同步版本 */
25
42
  export const getSystemInfoSync: typeof Taro.getSystemInfoSync = function () {
@@ -32,7 +49,7 @@ export const getSystemInfoSync: typeof Taro.getSystemInfoSync = function () {
32
49
  res.cameraAuthorized = null // 允许使用摄像头的开关 boolean
33
50
  res.enableDebug = null // 是否已打开调试 boolean
34
51
  res.fontSizeSetting = null // 用户字体大小(单位px) number
35
- res.language = i18n && i18n.getSystemLanguage && i18n.getSystemLanguage() // string
52
+ res.language = i18n?.getSystemLanguage?.() // string
36
53
  res.locationAuthorized = null // 定位的开关 boolean
37
54
  res.locationEnabled = null // 地理位置的系统开关 boolean
38
55
  res.microphoneAuthorized = null // 麦克风的开关 boolean
@@ -43,17 +60,18 @@ export const getSystemInfoSync: typeof Taro.getSystemInfoSync = function () {
43
60
  res.notificationSoundAuthorized = false // 通知带有声音的开关(仅 iOS 有效)boolean
44
61
  res.phoneCalendarAuthorized = null // 使用日历的开关 boolean
45
62
  res.wifiEnabled = false // Wi-Fi 的系统开关 boolean
46
- res.pixelRatio = null // 设备像素比,number
47
- res.platform = 'android' // 客户端平台 string
48
- res.safeArea = null // 在竖屏正方向下的安全区域 General.SafeAreaResult
49
- res.screenHeight = display && display.height // 屏幕高度,单位px number
50
- res.screenWidth = display && display.width // 屏幕宽度,单位px number
51
- res.statusBarHeight = null // 状态栏的高度,单位px number
52
- res.system = deviceInfo && deviceInfo.osFullName // 操作系统及版本 string
53
- res.theme = null // 系统当前主题,取值为light或dark 'light' | 'dark'
54
- res.windowWidth = device && device.windowWidth // 可使用窗口宽度,单位px number
55
- res.windowHeight = device && device.windowHeight // 可使用窗口高度,单位px number
56
- res.version = deviceInfo && deviceInfo.displayVersion // 版本号 string
63
+ res.pixelRatio = display && (Math.round(display.xDPI / display.width * 100) / 100) // 设备像素比,number
64
+ res.platform = 'harmony' // 客户端平台 string
65
+ res.safeArea = safeArea // 在竖屏正方向下的安全区域 General.SafeAreaResult
66
+ res.screenHeight = display?.height // 屏幕高度,单位px number
67
+ res.screenWidth = display?.width // 屏幕宽度,单位px number
68
+ res.statusBarHeight = safeArea?.top // 状态栏的高度,单位px number
69
+ res.system = deviceInfo?.osFullName // 操作系统及版本 string
70
+ // Note: 更新配置时才能记录
71
+ res.theme = AppStorage.get('__TARO_APP_CONFIG')?.colorMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK ? 'dark' : 'light' // 系统当前主题,取值为light或dark 'light' | 'dark'
72
+ res.windowHeight = display?.height // 可使用窗口高度,单位px number
73
+ res.windowWidth = display?.width // 可使用窗口宽度,单位px number
74
+ res.version = deviceInfo?.displayVersion // 版本号 string
57
75
 
58
76
  return res
59
77
  }
@@ -1,5 +1,3 @@
1
- import { Current } from '@tarojs/runtime'
2
-
3
1
  import { temporarilyNotSupport } from '../utils'
4
2
 
5
3
  export const ENV_TYPE = {
@@ -19,12 +17,10 @@ export function getEnv () {
19
17
  return ENV_TYPE.HARMONY
20
18
  }
21
19
 
22
- export { Current }
23
-
24
20
  // TODO
25
21
  export const getCurrentPages = () => []
26
22
 
27
- export const getCurrentInstance = () => Current
23
+ export { Current, getCurrentInstance } from '@tarojs/runtime'
28
24
 
29
25
  export const requirePlugin = temporarilyNotSupport('requirePlugin')
30
26
 
@@ -33,7 +33,7 @@ const defaultUnitPrecision = 5
33
33
  const defaultTargetUnit = 'vp'
34
34
 
35
35
  export function getApp () {
36
- return Current.app
36
+ return Current.app || {}
37
37
  }
38
38
 
39
39
  export function initPxTransform ({
@@ -2,7 +2,7 @@ import { createTaroEvent, eventHandler, getComponentEventCallback, AREA_CHANGE_E
2
2
 
3
3
  import commonStyleModify from './style'
4
4
  import { createLazyChildren } from './render'
5
- import { FlexManager } from './utils/FlexManager'
5
+ import { FlexManager } from './utils/flexManager'
6
6
  import { shouldBindEvent, getNodeThresholds } from './utils/helper'
7
7
 
8
8
  import type { TaroAny, TaroEvent, TaroCheckboxElement, TaroCheckboxGroupElement } from '@tarojs/runtime'
@@ -60,7 +60,7 @@ export struct TaroCheckbox {
60
60
  this.node.updateComponent()
61
61
  } else {
62
62
  this.node.updateCheckedValue(value)
63
-
63
+
64
64
  if (value) {
65
65
  const event: TaroEvent = createTaroEvent('change', { detail: { value: this.node?._attrs.value } }, this.node)
66
66
  eventHandler(event, 'change', this.node)
@@ -3,7 +3,7 @@ import { AREA_CHANGE_EVENT_NAME, eventHandler, getComponentEventCallback, VISIBL
3
3
  import commonStyleModify from './style'
4
4
  import { createLazyChildren } from './render'
5
5
  import { TOUCH_EVENT_MAP } from './utils/constant/event'
6
- import { FlexManager } from './utils/FlexManager'
6
+ import { FlexManager } from './utils/flexManager'
7
7
  import { shouldBindEvent, getNodeThresholds } from './utils/helper'
8
8
 
9
9
  import type { TaroAny, TaroFormElement } from '@tarojs/runtime'
@@ -3,7 +3,7 @@ import { Current, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_
3
3
  import commonStyleModify from './style'
4
4
  import { createLazyChildren } from './render'
5
5
  import { TOUCH_EVENT_MAP } from './utils/constant/event'
6
- import { FlexManager } from './utils/FlexManager'
6
+ import { FlexManager } from './utils/flexManager'
7
7
  import { getNormalAttributes, shouldBindEvent, getNodeThresholds } from './utils/helper'
8
8
 
9
9
  import type { TaroLabelElement, TaroElement, TaroAny, TaroRadioElement, TaroCheckboxElement } from '@tarojs/runtime'
@@ -2,7 +2,7 @@ import type { TaroMovableAreaElement, TaroStyleType } from '@tarojs/runtime'
2
2
  import commonStyleModify from './style'
3
3
  import { createLazyChildren } from './render'
4
4
 
5
- import { FlexManager } from './utils/FlexManager'
5
+ import { FlexManager } from './utils/flexManager'
6
6
  import { getNormalAttributes } from './utils/helper'
7
7
 
8
8
 
@@ -3,7 +3,7 @@ import type { TaroMovableViewElement, TaroStyleType } from '@tarojs/runtime'
3
3
  import commonStyleModify from './style'
4
4
  import { createLazyChildren } from './render'
5
5
 
6
- import { FlexManager } from './utils/FlexManager'
6
+ import { FlexManager } from './utils/flexManager'
7
7
  import { getNormalAttributes, } from './utils/helper'
8
8
  @Extend(Row)
9
9
  function rowAttrs(style: TaroStyleType) {
@@ -3,7 +3,7 @@ import { createLazyChildren } from './render'
3
3
  import commonStyleModify from './style'
4
4
  import { getSingleSelector, getMultiSelector } from './utils'
5
5
  import { TOUCH_EVENT_MAP } from './utils/constant/event'
6
- import { FlexManager } from './utils/FlexManager'
6
+ import { FlexManager } from './utils/flexManager'
7
7
  import { getNormalAttributes, shouldBindEvent, getNodeThresholds } from './utils/helper'
8
8
 
9
9
  import type { TaroAny, TaroEvent } from '@tarojs/runtime'
@@ -238,8 +238,8 @@ export default struct TaroPicker {
238
238
  break
239
239
  case 'time': {
240
240
  const hour = new Date().getHours()
241
- const minute = new Date().getMinutes()
242
-
241
+ const minute = new Date().getMinutes()
242
+
243
243
  defaultResetValue = `${('00'+hour).slice(-2)}:${('00'+minute).slice(-2)}`
244
244
  break
245
245
  }
@@ -248,7 +248,7 @@ export default struct TaroPicker {
248
248
  const day = data[1]
249
249
  const month = data[0]
250
250
  const year = data[2]
251
-
251
+
252
252
  defaultResetValue = `${year}-${month}-${day}`
253
253
  break
254
254
  }
@@ -256,7 +256,7 @@ export default struct TaroPicker {
256
256
  defaultResetValue = ''
257
257
  break
258
258
  }
259
-
259
+
260
260
  this.node._isInit = true
261
261
  this.node._reset = this.node.value || defaultResetValue
262
262
  }
@@ -0,0 +1,72 @@
1
+ import { getFontAttributes, getStyle } from './utils/helper'
2
+ import { pseudoModify } from './style'
3
+ import { createLazyChildren } from './render'
4
+
5
+ import type { TaroViewElement, TaroStyleType, TaroTextStyleType } from '@tarojs/runtime'
6
+
7
+ @Extend(Stack)
8
+ function stackAttrs (style: TaroStyleType) {
9
+ .constraintSize({
10
+ minWidth: style.minWidth,
11
+ maxWidth: style.maxWidth,
12
+ minHeight: style.minHeight || style.height,
13
+ maxHeight: style.maxHeight
14
+ })
15
+ }
16
+
17
+
18
+ @Extend(Text)
19
+ function textNormalFontStyle (style: TaroStyleType) {
20
+ .id(style.id)
21
+ .key(style.id)
22
+ .opacity(style.opacity)
23
+ .fontColor(style.color)
24
+ .fontSize(style.fontSize)
25
+ .fontWeight(style.fontWeight)
26
+ .fontStyle(style.fontStyle)
27
+ .fontFamily(style.fontFamily)
28
+ .lineHeight(style.lineHeight)
29
+ .decoration({
30
+ type: style.textDecoration,
31
+ color: style.color
32
+ })
33
+ }
34
+
35
+ @Extend(Text)
36
+ function textSpecialFontStyle(attr: TaroTextStyleType) {
37
+ .textAlign(attr.textAlign)
38
+ .textOverflow(attr.textOverflow)
39
+ .maxLines(attr.WebkitLineClamp)
40
+ .letterSpacing(attr.letterSpacing)
41
+ }
42
+
43
+ @Builder
44
+ export default function PseduoChildren (node: TaroViewElement) {
45
+ // 伪类::Before
46
+ if (node.pseudo_before) {
47
+ if (node.pseudo_before.content) {
48
+ Text(node.pseudo_before.content)
49
+ .attributeModifier(pseudoModify.setStyle(node.pseudo_before))
50
+ .textNormalFontStyle(getStyle(node.pseudo_before || {}))
51
+ .textSpecialFontStyle(getFontAttributes(node))
52
+ } else {
53
+ Stack() {}
54
+ .attributeModifier(pseudoModify.setStyle(node.pseudo_before || {}))
55
+ .stackAttrs(getStyle(node.pseudo_before || {}))
56
+ }
57
+ }
58
+ createLazyChildren(node)
59
+ // 伪类::After
60
+ if (node.pseudo_after) {
61
+ if (node.pseudo_after.content) {
62
+ Text(node.pseudo_after.content)
63
+ .attributeModifier(pseudoModify.setStyle(node.pseudo_after))
64
+ .textNormalFontStyle(getStyle(node.pseudo_after || {}))
65
+ .textSpecialFontStyle(getFontAttributes(node))
66
+ } else {
67
+ Stack() {}
68
+ .attributeModifier(pseudoModify.setStyle(node.pseudo_after || {}))
69
+ .stackAttrs(getStyle(node.pseudo_after || {}))
70
+ }
71
+ }
72
+ }
@@ -3,7 +3,7 @@ import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBL
3
3
  import commonStyleModify from './style'
4
4
  import { createLazyChildren } from './render'
5
5
  import { TOUCH_EVENT_MAP } from './utils/constant/event'
6
- import { FlexManager } from './utils/FlexManager'
6
+ import { FlexManager } from './utils/flexManager'
7
7
  import { shouldBindEvent, getNodeThresholds } from './utils/helper'
8
8
 
9
9
  import { TaroEvent, TaroAny, HarmonyType, TaroRadioGroupElement, TaroRadioElement } from '@tarojs/runtime'
@@ -36,7 +36,7 @@ function themeStyles(isDisabled: boolean) {
36
36
  @Component
37
37
  export struct TaroRadio {
38
38
  @ObjectLink node: TaroRadioElement
39
-
39
+
40
40
  aboutToAppear () {
41
41
  if (this.node && !this.node._isInit) {
42
42
  this.node._isInit = true
@@ -61,7 +61,7 @@ export struct TaroRadio {
61
61
  this.node.updateComponent()
62
62
  } else {
63
63
  this.node.updateCheckedValue(value)
64
-
64
+
65
65
  if (value) {
66
66
  const event: TaroEvent = createTaroEvent('change', { detail: { value: this.node?._attrs.value } }, this.node)
67
67
  eventHandler(event, 'change', this.node)
@@ -1,7 +1,7 @@
1
1
  import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
2
2
 
3
3
  import commonStyleModify from './style'
4
- import { createLazyChildren } from './render'
4
+ import PseduoChildren from './pseudo'
5
5
  import { FlexManager } from './utils/FlexManager'
6
6
  import { TOUCH_EVENT_MAP } from './utils/constant/event'
7
7
  import { getNodeThresholds, getNormalAttributes, shouldBindEvent } from './utils/helper'
@@ -49,8 +49,8 @@ function handleScrollEvent (node: TaroScrollViewElement, eventName = 'scroll', x
49
49
  deltaY: vp2px(yOffset),
50
50
  scrollLeft: vp2px(currentXOffset),
51
51
  scrollTop: vp2px(currentYOffset),
52
- scrollWidth: vp2px(Number(node._scroll?.width)),
53
- scrollHeight: vp2px(Number(node._scroll?.height)),
52
+ scrollWidth: vp2px(Number(node._nodeInfo?._scroll?.width)),
53
+ scrollHeight: vp2px(Number(node._nodeInfo?._scroll?.height)),
54
54
  }
55
55
  const event: TaroEvent = createTaroEvent(eventName, { detail: value }, node)
56
56
 
@@ -85,27 +85,27 @@ export default struct TaroScrollView {
85
85
  Scroll(this.node.scroller) {
86
86
  if (this.node._attrs.scrollX) {
87
87
  Row() {
88
- createLazyChildren(this.node)
88
+ PseduoChildren(this.node)
89
89
  }
90
90
  .attributeModifier(commonStyleModify.setNode(this.node))
91
91
  .rowAttrs(getNormalAttributes(this.node))
92
92
  .width(null)
93
93
  .onAreaChange(shouldBindEvent((_: Area, areaResult: Area) => {
94
- this.node._scroll = areaResult
94
+ this.node._nodeInfo._scroll = areaResult
95
95
  }, this.node, ['scroll', 'scrollstart', 'scrollend']))
96
96
  .alignItems(FlexManager.flexOptions(this.node).alignItems as VerticalAlign)
97
97
  .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
98
98
  .flexGrow(0).flexShrink(0)
99
99
  } else {
100
100
  Column() {
101
- createLazyChildren(this.node)
101
+ PseduoChildren(this.node)
102
102
  }
103
103
  .attributeModifier(commonStyleModify.setNode(this.node))
104
104
  .columnAttrs(getNormalAttributes(this.node))
105
105
  .height(null)
106
106
  .alignItems(HorizontalAlign.Start)
107
107
  .onAreaChange(shouldBindEvent((_: Area, areaResult: Area) => {
108
- this.node._scroll = areaResult
108
+ this.node._nodeInfo._scroll = areaResult
109
109
  }, this.node, ['scroll', 'scrollstart', 'scrollend']))
110
110
  .alignItems(FlexManager.flexOptions(this.node).alignItems as HorizontalAlign)
111
111
  .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
@@ -127,5 +127,6 @@ export default struct TaroScrollView {
127
127
  .onScrollStart(shouldBindEvent(() => { handleScrollEvent(this.node, 'scrollstart') }, this.node, ['scrollstart']))
128
128
  .onScrollStop(shouldBindEvent(() => { handleScrollEvent(this.node, 'scrollend') }, this.node, ['scrollend']))
129
129
  .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
130
+ .onReachEnd(shouldBindEvent(() => { handleScrollEvent(this.node, 'scrolltolower') }, this.node, ['scrolltolower']))
130
131
  }
131
132
  }
@@ -1,6 +1,6 @@
1
- import type { TaroElement, TaroStyleType } from '@tarojs/runtime'
1
+ import type { HarmonyStyle, TaroElement, TaroStyleType } from '@tarojs/runtime'
2
2
  import { isUndefined } from '../shared'
3
- import { getNormalAttributes } from './utils/helper'
3
+ import { getNormalAttributes, getStyle } from './utils/helper'
4
4
 
5
5
  function getTop (node: TaroElement): Length | number {
6
6
  return node?.hmStyle?.top || 0
@@ -23,132 +23,153 @@ class CommonStyleModify implements AttributeModifier<CommonAttribute> {
23
23
 
24
24
  applyNormalAttribute(instance: CommonAttribute): void {
25
25
  if (this.node && this.style) {
26
+ setNormalAttributeIntoInstance(instance, this.style)
27
+ }
28
+ }
29
+ }
30
+
31
+ class PseudoStyleModify implements AttributeModifier<CommonAttribute> {
32
+ style: TaroStyleType | null = null
26
33
 
27
- if (!isUndefined(this.style.id)) {
28
- instance.id(this.style.id)
29
- instance.key(this.style.id)
30
- }
31
- if (!isUndefined(this.style.flexGrow)) {
32
- instance.flexGrow(this.style.flexGrow)
33
- }
34
- if (!isUndefined(this.style.flexShrink)) {
35
- instance.flexShrink(this.style.flexShrink)
36
- }
37
- if (!isUndefined(this.style.flexBasis)) {
38
- instance.flexBasis(this.style.flexBasis)
39
- }
40
- if (!isUndefined(this.style.alignSelf)) {
41
- instance.alignSelf(this.style.alignSelf)
42
- }
43
- if (!isUndefined(this.style.paddingTop) || !isUndefined(this.style.paddingRight) || !isUndefined(this.style.paddingBottom) || !isUndefined(this.style.paddingLeft)) {
44
- instance.padding({
45
- top: this.style.paddingTop,
46
- right: this.style.paddingRight,
47
- bottom: this.style.paddingBottom,
48
- left: this.style.paddingLeft
49
- })
50
- }
51
- if (!isUndefined(this.style.marginTop) || !isUndefined(this.style.marginRight) || !isUndefined(this.style.marginBottom) || !isUndefined(this.style.marginLeft)) {
52
- instance.margin({
53
- top: this.style.marginTop,
54
- right: this.style.marginRight,
55
- bottom: this.style.marginBottom,
56
- left: this.style.marginLeft
57
- })
58
- }
59
- if (!isUndefined(this.style.width)) {
60
- instance.width(this.style.width)
61
- }
62
- if (!isUndefined(this.style.height)) {
63
- instance.height(this.style.height)
64
- }
65
- if (!isUndefined(this.style.minWidth) || !isUndefined(this.style.maxWidth) || !isUndefined(this.style.minHeight) || !isUndefined(this.style.maxHeight)) {
66
- instance.constraintSize({
67
- minWidth: this.style.minWidth,
68
- maxWidth: this.style.maxWidth,
69
- minHeight: this.style.minHeight,
70
- maxHeight: this.style.maxHeight
71
- })
72
- }
73
- if (!isUndefined(this.style.backgroundColor)) {
74
- instance.backgroundColor(this.style.backgroundColor)
75
- }
76
- if (!isUndefined(this.style.backgroundImage)) {
77
- instance.backgroundImage(this.style.backgroundImage?.src, this.style.backgroundRepeat)
78
- }
79
- if (!isUndefined(this.style.backgroundSize)) {
80
- instance.backgroundImageSize(this.style.backgroundSize)
81
- }
82
- if (!isUndefined(this.style.backgroundPosition)) {
83
- instance.backgroundImagePosition(this.style.backgroundPosition)
84
- }
85
- if (!isUndefined(this.style.borderTopStyle) || !isUndefined(this.style.borderRightStyle) || !isUndefined(this.style.borderBottomStyle) || !isUndefined(this.style.borderLeftStyle)) {
86
- instance.borderStyle({
87
- top: this.style.borderTopStyle,
88
- right: this.style.borderRightStyle,
89
- bottom: this.style.borderBottomStyle,
90
- left: this.style.borderLeftStyle
91
- })
92
- }
93
- if (!isUndefined(this.style.borderTopWidth) || !isUndefined(this.style.borderRightWidth) || !isUndefined(this.style.borderBottomWidth) || !isUndefined(this.style.borderLeftWidth)) {
94
- instance.borderWidth({
95
- top: this.style.borderTopWidth,
96
- right: this.style.borderRightWidth,
97
- bottom: this.style.borderBottomWidth,
98
- left: this.style.borderLeftWidth
99
- })
100
- }
101
- if (!isUndefined(this.style.borderTopColor) || !isUndefined(this.style.borderRightColor) || !isUndefined(this.style.borderBottomColor) || !isUndefined(this.style.borderLeftColor)) {
102
- instance.borderColor({
103
- top: this.style.borderTopColor,
104
- right: this.style.borderRightColor,
105
- bottom: this.style.borderBottomColor,
106
- left: this.style.borderLeftColor
107
- })
108
- }
109
- if (!isUndefined(this.style.borderTopLeftRadius) || !isUndefined(this.style.borderTopRightRadius) || !isUndefined(this.style.borderBottomLeftRadius) || !isUndefined(this.style.borderBottomRightRadius)) {
110
- instance.borderRadius({
111
- topLeft: this.style.borderTopLeftRadius,
112
- topRight: this.style.borderTopRightRadius,
113
- bottomLeft: this.style.borderBottomLeftRadius,
114
- bottomRight: this.style.borderBottomRightRadius
115
- })
116
- }
117
- if (!isUndefined(this.style.zIndex)) {
118
- instance.zIndex(this.style.zIndex)
119
- }
120
- if (!isUndefined(this.style.opacity)) {
121
- instance.opacity(this.style.opacity)
122
- }
123
- if (!isUndefined(this.style.linearGradient)) {
124
- instance.linearGradient(this.style.linearGradient)
125
- }
126
- if (!isUndefined(this.style.overflow)) {
127
- instance.clip(this.style.overflow)
128
- }
129
- if (!isUndefined(this.style.transformOrigin)) {
130
- instance.rotate({ centerX: this.style.transformOrigin.x, centerY: this.style.transformOrigin.y, angle: 0 })
131
- instance.scale({ centerX: this.style.transformOrigin.x, centerY: this.style.transformOrigin.y })
132
- }
133
- if (!isUndefined(this.style.transform)) {
134
- instance.transform(this.style.transform)
135
- }
136
- if (this.node.hmStyle?.position === 'absolute' || this.node.hmStyle?.position === 'fixed') {
137
- instance.position({
138
- x: getLeft(this.node),
139
- y: getTop(this.node)
140
- })
141
- }
142
- if (this.node.hmStyle?.position === 'relative') {
143
- instance.offset({
144
- x: getLeft(this.node),
145
- y: getTop(this.node)
146
- })
147
- }
34
+ setStyle (style: HarmonyStyle) {
35
+ this.style = getStyle(style)
36
+ return this
37
+ }
38
+
39
+ applyNormalAttribute(instance: CommonAttribute): void {
40
+ if (this.style) {
41
+ setNormalAttributeIntoInstance(instance, this.style)
148
42
  }
149
43
  }
150
44
  }
151
45
 
46
+
47
+ function setNormalAttributeIntoInstance(instance: CommonAttribute, style: TaroStyleType) {
48
+ if (!isUndefined(style.id)) {
49
+ instance.id(style.id)
50
+ instance.key(style.id)
51
+ }
52
+ if (!isUndefined(style.flexGrow)) {
53
+ instance.flexGrow(style.flexGrow)
54
+ }
55
+ if (!isUndefined(style.flexShrink)) {
56
+ instance.flexShrink(style.flexShrink)
57
+ }
58
+ if (!isUndefined(style.flexBasis)) {
59
+ instance.flexBasis(style.flexBasis)
60
+ }
61
+ if (!isUndefined(style.alignSelf)) {
62
+ instance.alignSelf(style.alignSelf)
63
+ }
64
+ if (!isUndefined(style.paddingTop) || !isUndefined(style.paddingRight) || !isUndefined(style.paddingBottom) || !isUndefined(style.paddingLeft)) {
65
+ instance.padding({
66
+ top: style.paddingTop,
67
+ right: style.paddingRight,
68
+ bottom: style.paddingBottom,
69
+ left: style.paddingLeft
70
+ })
71
+ }
72
+ if (!isUndefined(style.marginTop) || !isUndefined(style.marginRight) || !isUndefined(style.marginBottom) || !isUndefined(style.marginLeft)) {
73
+ instance.margin({
74
+ top: style.marginTop,
75
+ right: style.marginRight,
76
+ bottom: style.marginBottom,
77
+ left: style.marginLeft
78
+ })
79
+ }
80
+ if (!isUndefined(style.width)) {
81
+ instance.width(style.width)
82
+ }
83
+ if (!isUndefined(style.height)) {
84
+ instance.height(style.height)
85
+ }
86
+ if (!isUndefined(style.minWidth) || !isUndefined(style.maxWidth) || !isUndefined(style.minHeight) || !isUndefined(style.maxHeight)) {
87
+ instance.constraintSize({
88
+ minWidth: style.minWidth,
89
+ maxWidth: style.maxWidth,
90
+ minHeight: style.minHeight,
91
+ maxHeight: style.maxHeight
92
+ })
93
+ }
94
+ if (!isUndefined(style.backgroundColor)) {
95
+ instance.backgroundColor(style.backgroundColor)
96
+ }
97
+ if (!isUndefined(style.backgroundImage)) {
98
+ instance.backgroundImage(style.backgroundImage?.src, style.backgroundRepeat)
99
+ }
100
+ if (!isUndefined(style.backgroundSize)) {
101
+ instance.backgroundImageSize(style.backgroundSize)
102
+ }
103
+ if (!isUndefined(style.backgroundPosition)) {
104
+ instance.backgroundImagePosition(style.backgroundPosition)
105
+ }
106
+ if (!isUndefined(style.borderTopStyle) || !isUndefined(style.borderRightStyle) || !isUndefined(style.borderBottomStyle) || !isUndefined(style.borderLeftStyle)) {
107
+ instance.borderStyle({
108
+ top: style.borderTopStyle,
109
+ right: style.borderRightStyle,
110
+ bottom: style.borderBottomStyle,
111
+ left: style.borderLeftStyle
112
+ })
113
+ }
114
+ if (!isUndefined(style.borderTopWidth) || !isUndefined(style.borderRightWidth) || !isUndefined(style.borderBottomWidth) || !isUndefined(style.borderLeftWidth)) {
115
+ instance.borderWidth({
116
+ top: style.borderTopWidth,
117
+ right: style.borderRightWidth,
118
+ bottom: style.borderBottomWidth,
119
+ left: style.borderLeftWidth
120
+ })
121
+ }
122
+ if (!isUndefined(style.borderTopColor) || !isUndefined(style.borderRightColor) || !isUndefined(style.borderBottomColor) || !isUndefined(style.borderLeftColor)) {
123
+ instance.borderColor({
124
+ top: style.borderTopColor,
125
+ right: style.borderRightColor,
126
+ bottom: style.borderBottomColor,
127
+ left: style.borderLeftColor
128
+ })
129
+ }
130
+ if (!isUndefined(style.borderTopLeftRadius) || !isUndefined(style.borderTopRightRadius) || !isUndefined(style.borderBottomLeftRadius) || !isUndefined(style.borderBottomRightRadius)) {
131
+ instance.borderRadius({
132
+ topLeft: style.borderTopLeftRadius,
133
+ topRight: style.borderTopRightRadius,
134
+ bottomLeft: style.borderBottomLeftRadius,
135
+ bottomRight: style.borderBottomRightRadius
136
+ })
137
+ }
138
+ if (!isUndefined(style.zIndex)) {
139
+ instance.zIndex(style.zIndex)
140
+ }
141
+ if (!isUndefined(style.opacity)) {
142
+ instance.opacity(style.opacity)
143
+ }
144
+ if (!isUndefined(style.linearGradient)) {
145
+ instance.linearGradient(style.linearGradient)
146
+ }
147
+ if (!isUndefined(style.overflow)) {
148
+ instance.clip(style.overflow)
149
+ }
150
+ if (!isUndefined(style.transformOrigin)) {
151
+ instance.rotate({ centerX: style.transformOrigin.x, centerY: style.transformOrigin.y, angle: 0 })
152
+ instance.scale({ centerX: style.transformOrigin.x, centerY: style.transformOrigin.y })
153
+ }
154
+ if (!isUndefined(style.transform)) {
155
+ instance.transform(style.transform)
156
+ }
157
+ if (style.position === 'absolute' || style.position === 'fixed') {
158
+ instance.position({
159
+ x: style.left || 0,
160
+ y: style.top || 0,
161
+ })
162
+ }
163
+ if (style.position === 'relative') {
164
+ instance.offset({
165
+ x: style.left || 0,
166
+ y: style.top || 0,
167
+ })
168
+ }
169
+ }
170
+
152
171
  const modify = new CommonStyleModify()
153
172
 
173
+ export const pseudoModify = new PseudoStyleModify()
174
+
154
175
  export default modify