@tarojs/plugin-platform-harmony-ets 4.0.0-beta.12 → 4.0.0-beta.121

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 (143) hide show
  1. package/dist/apis/base/system.ts +60 -25
  2. package/dist/apis/base/weapp/life-cycle.ts +1 -1
  3. package/dist/apis/canvas/index.ts +10 -1
  4. package/dist/apis/device/clipboard.ts +23 -8
  5. package/dist/apis/framework/index.ts +2 -6
  6. package/dist/apis/index.ts +25 -17
  7. package/dist/apis/media/image/index.ts +169 -17
  8. package/dist/apis/route/index.ts +1 -2
  9. package/dist/apis/storage/index.ts +135 -131
  10. package/dist/apis/ui/animation/animation.ts +71 -29
  11. package/dist/apis/ui/background.ts +3 -2
  12. package/dist/apis/ui/interaction/index.ts +58 -59
  13. package/dist/apis/ui/navigation-bar/index.ts +2 -2
  14. package/dist/apis/ui/pull-down-refresh.ts +9 -3
  15. package/dist/apis/ui/scroll/index.ts +6 -6
  16. package/dist/apis/ui/tab-bar.ts +4 -5
  17. package/dist/apis/utils/index.ts +20 -2
  18. package/dist/apis/utils/permissions.ts +6 -0
  19. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  20. package/dist/apis/wxml/selectorQuery.ts +26 -13
  21. package/dist/components-harmony-ets/button.ets +36 -9
  22. package/dist/components-harmony-ets/canvas.ets +51 -0
  23. package/dist/components-harmony-ets/checkbox.ets +69 -60
  24. package/dist/components-harmony-ets/form.ets +33 -15
  25. package/dist/components-harmony-ets/icon.ets +16 -8
  26. package/dist/components-harmony-ets/image.ets +22 -6
  27. package/dist/components-harmony-ets/index.ets +39 -0
  28. package/dist/components-harmony-ets/innerHtml.ets +6 -5
  29. package/dist/components-harmony-ets/input.ets +63 -37
  30. package/dist/components-harmony-ets/label.ets +43 -21
  31. package/dist/components-harmony-ets/listView.ets +32 -0
  32. package/dist/components-harmony-ets/movableArea.ets +110 -51
  33. package/dist/components-harmony-ets/movableView.ets +74 -47
  34. package/dist/components-harmony-ets/navigationBar.ets +65 -0
  35. package/dist/components-harmony-ets/pageMeta.ets +94 -0
  36. package/dist/components-harmony-ets/picker.ets +36 -33
  37. package/dist/components-harmony-ets/progress.ets +31 -24
  38. package/dist/components-harmony-ets/pseudo.ets +80 -0
  39. package/dist/components-harmony-ets/radio.ets +75 -66
  40. package/dist/components-harmony-ets/richText.ets +4 -25
  41. package/dist/components-harmony-ets/scrollList.ets +108 -0
  42. package/dist/components-harmony-ets/scrollView.ets +46 -42
  43. package/dist/components-harmony-ets/slider.ets +19 -15
  44. package/dist/components-harmony-ets/stickySection.ets +42 -0
  45. package/dist/components-harmony-ets/style.ets +386 -129
  46. package/dist/components-harmony-ets/swiper.ets +42 -5
  47. package/dist/components-harmony-ets/switch.ets +36 -32
  48. package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
  49. package/dist/components-harmony-ets/text.ets +102 -46
  50. package/dist/components-harmony-ets/textArea.ets +49 -34
  51. package/dist/components-harmony-ets/utils/AttributeManager.ets +2 -2
  52. package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -2
  53. package/dist/components-harmony-ets/utils/flexManager.ets +49 -19
  54. package/dist/components-harmony-ets/utils/helper.ets +20 -8
  55. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  56. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  57. package/dist/components-harmony-ets/utils/index.ts +54 -50
  58. package/dist/components-harmony-ets/utils/styles.ets +169 -91
  59. package/dist/components-harmony-ets/video.ets +28 -20
  60. package/dist/components-harmony-ets/view.ets +45 -39
  61. package/dist/components-harmony-ets/webView.ets +6 -5
  62. package/dist/index.d.ts +152 -0
  63. package/dist/index.js +73 -44
  64. package/dist/index.js.map +1 -1
  65. package/dist/runtime-ets/bom/URL.ts +2 -0
  66. package/dist/runtime-ets/bom/document.ts +5 -4
  67. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -3
  68. package/dist/runtime-ets/bom/history.ts +1 -0
  69. package/dist/runtime-ets/bom/location.ts +1 -0
  70. package/dist/runtime-ets/bom/navigator.ts +1 -21
  71. package/dist/runtime-ets/bom/raf.ts +1 -37
  72. package/dist/runtime-ets/bom/window.ts +10 -4
  73. package/dist/runtime-ets/constant.ts +17 -10
  74. package/dist/runtime-ets/current.ts +5 -2
  75. package/dist/runtime-ets/dom/bind.ts +28 -12
  76. package/dist/runtime-ets/dom/class-list.ts +2 -2
  77. package/dist/runtime-ets/dom/cssNesting.ts +419 -0
  78. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +28 -42
  79. package/dist/runtime-ets/dom/document.ts +9 -12
  80. package/dist/runtime-ets/dom/element/canvas.ts +137 -0
  81. package/dist/runtime-ets/dom/element/element.ts +379 -55
  82. package/dist/runtime-ets/dom/element/form.ts +26 -22
  83. package/dist/runtime-ets/dom/element/index.ts +22 -2
  84. package/dist/runtime-ets/dom/element/movableArea.ts +0 -1
  85. package/dist/runtime-ets/dom/element/movableView.ts +238 -2
  86. package/dist/runtime-ets/dom/element/normal.ts +27 -6
  87. package/dist/runtime-ets/dom/element/progress.ts +0 -2
  88. package/dist/runtime-ets/dom/element/text.ts +0 -8
  89. package/dist/runtime-ets/dom/element/video.ts +4 -4
  90. package/dist/runtime-ets/dom/element/webView.ts +4 -5
  91. package/dist/runtime-ets/dom/event-source.ts +1 -0
  92. package/dist/runtime-ets/dom/event.ts +3 -5
  93. package/dist/runtime-ets/dom/eventTarget.ts +3 -4
  94. package/dist/runtime-ets/dom/node.ts +53 -22
  95. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +418 -237
  96. package/dist/runtime-ets/dom/stylesheet/index.ts +29 -311
  97. package/dist/runtime-ets/dom/stylesheet/type.ts +53 -11
  98. package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
  99. package/dist/runtime-ets/emitter/emitter.ts +1 -0
  100. package/dist/runtime-ets/env.ts +1 -0
  101. package/dist/runtime-ets/index.ts +23 -7
  102. package/dist/runtime-ets/interface/event.ts +1 -1
  103. package/dist/runtime-ets/interface/index.ts +6 -0
  104. package/dist/runtime-ets/utils/index.ts +78 -19
  105. package/dist/runtime-ets/utils/info.ts +2 -2
  106. package/dist/runtime-ets/utils/router.ts +9 -0
  107. package/dist/runtime-framework/react/app.ts +15 -11
  108. package/dist/runtime-framework/react/hooks.ts +1 -2
  109. package/dist/runtime-framework/react/index.ts +0 -2
  110. package/dist/runtime-framework/react/native-page.ts +217 -81
  111. package/dist/runtime-framework/react/page.ts +4 -10
  112. package/dist/runtime-framework/react/utils/index.ts +3 -3
  113. package/dist/runtime-framework/solid/app.ts +29 -46
  114. package/dist/runtime-framework/solid/connect.ts +21 -3
  115. package/dist/runtime-framework/solid/hooks.ts +16 -11
  116. package/dist/runtime-framework/solid/index.ts +6 -2
  117. package/dist/runtime-framework/solid/page.ts +84 -31
  118. package/dist/runtime-framework/solid/reconciler/props.ts +73 -29
  119. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  120. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  121. package/dist/runtime-framework/solid/utils/index.ts +3 -5
  122. package/dist/runtime-utils.d.ts +827 -0
  123. package/dist/runtime-utils.js +574 -285
  124. package/dist/runtime-utils.js.map +1 -1
  125. package/dist/runtime.d.ts +1 -0
  126. package/dist/runtime.js +574 -285
  127. package/dist/runtime.js.map +1 -1
  128. package/index.js +3 -1
  129. package/package.json +14 -15
  130. package/static/media/cancel.svg +1 -1
  131. package/static/media/circle.svg +1 -1
  132. package/static/media/clear.svg +1 -1
  133. package/static/media/download.svg +1 -1
  134. package/static/media/info.svg +1 -1
  135. package/static/media/info_circle.svg +1 -1
  136. package/static/media/search.svg +1 -1
  137. package/static/media/success.svg +1 -1
  138. package/static/media/success_no_circle.svg +1 -1
  139. package/static/media/warn.svg +1 -1
  140. package/types/harmony.d.ts +5 -0
  141. package/types/index.d.ts +4 -0
  142. package/types/runtime.d.ts +1 -1
  143. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
@@ -1,5 +1,8 @@
1
1
  import { convertNumber2VP } from '@tarojs/runtime'
2
- import { isNumber } from '@tarojs/shared'
2
+ import { isNumber, isUndefined } from '@tarojs/shared'
3
+
4
+ import type { RichTextProps } from '@tarojs/components/types/RichText'
5
+ import type { TaroRichTextElement } from '@tarojs/runtime'
3
6
 
4
7
  export function getSingleSelector(range, rangeKey): any[] {
5
8
  return range.map((data) => data[rangeKey])
@@ -18,66 +21,67 @@ export function getMultiSelector(ctx, range, rangeKey, value) {
18
21
  }))
19
22
  }
20
23
 
21
- export function getUnit (val) {
22
- if (/\d+(vp)$/.test(val)) {
24
+ export function getUnit (val: string | number): string {
25
+ if (isNumber(val) || /\d+px$/.test(val)) {
26
+ return convertNumber2VP(parseFloat(val as string))
27
+ } else if (/\d+(vp)$/.test(val)) {
23
28
  return val
24
- } else if (isNumber(val) || /\d+px$/.test(val)) {
25
- return convertNumber2VP(parseFloat(val))
26
29
  }
27
30
  return val
28
31
  }
29
32
 
30
- function handleNodeStyleData (dataValue: string, handler: (values: string[]) => { [key: string]: string } | void) {
31
- let res: any = {}
32
- if (dataValue) {
33
- const values = dataValue.trim().split(/\s+/)
34
- const data = handler(values)
35
-
36
- if (!data) return res
37
-
38
- res = data
33
+ export function generateText (node: TaroRichTextElement): string {
34
+ return parseHtmlNode(node._attrs.nodes || '')
35
+ }
39
36
 
40
- Object.keys(res).forEach(key => {
41
- const exec = `${res[key]}`.match(/(\d+)(px)$/)
42
- if (exec && values.length > 1) {
43
- res[key] = getUnit(+exec[1])
44
- }
45
- })
37
+ // 将nodeTree转换成harmony需要的string结构
38
+ function nodeToHtml(node: RichTextProps.Text | RichTextProps.HTMLElement): string {
39
+ if (node.type === 'text') {
40
+ return node.text
41
+ }
42
+ if (node.attrs) {
43
+ const attributes = Object.entries(node.attrs)
44
+ .map((item: [string, string]) => `${item[0]}="${item[1]}"`)
45
+ .join(' ')
46
+ const childrenHtml: string = typeof node.children === 'string' ? node.children : (node.children || []).map((child: RichTextProps.Text | RichTextProps.HTMLElement) => nodeToHtml(child)).join('')
47
+ return `<${node.name}${attributes ? ' ' + attributes : ''}>${childrenHtml}</${node.name}>`
46
48
  }
49
+ return ''
50
+ }
47
51
 
48
- return res
52
+ function parseHtmlNode (nodes: Array<RichTextProps.Text | RichTextProps.HTMLElement> | string) {
53
+ return typeof nodes === 'string' ? nodes : `<div>${nodes.map(node => nodeToHtml(node)).join('')}</div>`
49
54
  }
50
55
 
51
- export function getNodeBorderRadiusData (dataValue: string) {
52
- return handleNodeStyleData(dataValue, values => {
53
- switch (values.length) {
54
- case 1:
55
- return { topLeft: values[0], topRight: values[0], bottomRight: values[0], bottomLeft: values[0] }
56
- case 2:
57
- return { topLeft: values[0], topRight: values[1], bottomRight: values[0], bottomLeft: values[1] }
58
- case 3:
59
- return { topLeft: values[0], topRight: values[1], bottomRight: values[2], bottomLeft: values[1] }
60
- case 4:
61
- return { topLeft: values[0], topRight: values[1], bottomRight: values[2], bottomLeft: values[3] }
62
- default:
63
- break
56
+ // 背景偏移算法:https://developer.mozilla.org/zh-CN/docs/Web/CSS/background-position
57
+ export function computeBackgroundPosition(style) {
58
+ let offsetX = style.backgroundPosition?.x || 0
59
+ let offsetY = style.backgroundPosition?.y || 0
60
+ if (style.backgroundSize && typeof style.backgroundSize !== 'number') {
61
+ if (!isUndefined(style.backgroundSize.width) && style.width) {
62
+ if (typeof style.backgroundPosition.x === 'string' && style.backgroundPosition.x.indexOf('%') > 0) {
63
+ // (container width - image width) * (position x%) = (x offset value)
64
+ const width = parseFloat(style.width)
65
+ const bgWidth = parseFloat(style.backgroundSize.width)
66
+ const bgOffsetX = parseFloat(style.backgroundPosition.x)
67
+ offsetX = Number((width - bgWidth) * (bgOffsetX) / 100) || 0
68
+ }
69
+ }
70
+ if (!isUndefined(style.backgroundSize.height) && style.height) {
71
+ if (typeof style.backgroundPosition.y === 'string' && style.backgroundPosition.y.indexOf('%') > 0) {
72
+ // (container height - image height) * (position y%) = (y offset value)
73
+ const height = parseFloat(style.height)
74
+ const bgHeight = parseFloat(style.backgroundSize.height)
75
+ const bgOffsetY = parseFloat(style.backgroundPosition.y)
76
+ offsetY = Number((height - bgHeight) * (bgOffsetY) / 100) || 0
77
+ }
64
78
  }
65
- })
79
+ }
80
+
81
+ return { offsetX, offsetY }
66
82
  }
67
83
 
68
- export function getNodeMarginOrPaddingData (dataValue: string) {
69
- return handleNodeStyleData(dataValue, values => {
70
- switch (values.length) {
71
- case 1:
72
- return { top: values[0], right: values[0], bottom: values[0], left: values[0] }
73
- case 2:
74
- return { top: values[0], right: values[1], bottom: values[0], left: values[1] }
75
- case 3:
76
- return { top: values[0], right: values[1], bottom: values[2], left: values[1] }
77
- case 4:
78
- return { top: values[0], right: values[1], bottom: values[2], left: values[3] }
79
- default:
80
- break
81
- }
82
- })
84
+ export function convertVp2Px(val: string | number) {
85
+ const vp = parseFloat(`${val}`)
86
+ return vp2px(vp)
83
87
  }
@@ -2,125 +2,203 @@ import { isUndefined } from '@tarojs/shared'
2
2
  import { ObjectAssign } from '@tarojs/runtime'
3
3
 
4
4
  import { FlexManager } from './flexManager'
5
- import { TEXT_DEFAULT_STYLE } from './constant/style'
6
5
 
7
6
  import type { StandardProps, TextProps } from '@tarojs/components/types'
8
- import type { TaroAny, TaroElement, TaroStyleType, TaroTextStyleType, HarmonyType, HarmonyStyle } from '@tarojs/runtime'
7
+ import type { TaroAny, TaroElement, TaroTextStyleType, HarmonyStyle } from '@tarojs/runtime'
9
8
 
10
9
  export function getFontAttributes (node: TaroElement): TaroTextStyleType {
11
- const hmStyle = node.hmStyle
10
+ let hmStyle = getNormalAttributes(node)
12
11
  const attrs: TextProps = node._attrs || {}
13
12
 
13
+ if (!hmStyle) return {}
14
+
15
+ let lineHeight = hmStyle.lineHeight
16
+ if (!isUndefined(hmStyle.verticalAlign)) {
17
+ lineHeight = 0
18
+ }
19
+
20
+ let WebkitLineClamp = attrs.maxLines || hmStyle.WebkitLineClamp || Infinity
21
+ if (hmStyle.textOverflow && !isUndefined(hmStyle.textOverflow.overflow)) {
22
+ switch (hmStyle.textOverflow.overflow) {
23
+ case TextOverflow.Clip:
24
+ case TextOverflow.Ellipsis:
25
+ case TextOverflow.None: WebkitLineClamp = WebkitLineClamp || 1; break
26
+ default: break
27
+ }
28
+ }
29
+
30
+ const isFlexText = hmStyle.display === 'flex'
31
+ let textAlign = hmStyle.textAlign
32
+ let verticalAlign = hmStyle.verticalAlign
33
+
34
+ // 按照 w3c 规范,一旦设置了 display: flex,textAlign 和 verticalAlign 都会直接失效
35
+ // 需要使用 justifyContent 和 alignItems
36
+ if (isFlexText) {
37
+ switch (hmStyle.justifyContent) {
38
+ case FlexAlign.Start:
39
+ textAlign = TextAlign.Start
40
+ break
41
+ case FlexAlign.Center:
42
+ textAlign = TextAlign.Center
43
+ break
44
+ case FlexAlign.End:
45
+ textAlign = TextAlign.End
46
+ break
47
+ case FlexAlign.SpaceBetween:
48
+ case FlexAlign.SpaceAround:
49
+ textAlign = TextAlign.JUSTIFY
50
+ break
51
+ default:
52
+ textAlign = TextAlign.Start
53
+ break
54
+ }
55
+ switch (hmStyle.alignItems) {
56
+ case ItemAlign.Start:
57
+ verticalAlign = Alignment.Top
58
+ break
59
+ case ItemAlign.Center:
60
+ verticalAlign = Alignment.Center
61
+ break
62
+ case ItemAlign.End:
63
+ verticalAlign = Alignment.End
64
+ break
65
+ default:
66
+ verticalAlign = Alignment.Top
67
+ break
68
+ }
69
+ }
70
+
14
71
  const attributes: TaroAny = {
15
- WebkitLineClamp: attrs.maxLines || hmStyle.WebkitLineClamp || Infinity,
72
+ textAlign,
73
+ verticalAlign,
74
+ WebkitLineClamp: WebkitLineClamp,
16
75
  // 已做处理的属性
17
76
  letterSpacing: hmStyle.letterSpacing,
18
- textAlign: hmStyle.textAlign,
19
- textOverflow: hmStyle.textOverflow
77
+ textOverflow: hmStyle.textOverflow,
78
+ lineHeight: lineHeight
20
79
  }
21
80
 
22
81
  return attributes
23
82
  }
24
83
 
25
84
  // 模拟 div 自动撑满父元素的情况
26
- function isMaxWidthView (node: TaroElement) {
85
+ export function isMaxWidthView (node: TaroElement) {
27
86
  const parentNode: TaroElement = node.parentNode as TaroElement
28
87
 
29
- return node.tagName === 'VIEW' && parentNode && parentNode.tagName === 'VIEW' &&
30
- !(FlexManager.isFlexNode(parentNode) && FlexManager.flexOptions(parentNode).direction !== FlexDirection.Column)
88
+ return node.tagName === 'VIEW' && parentNode && parentNode.tagName === 'VIEW' && !FlexManager.isFlexNode(parentNode)
31
89
  }
32
90
 
33
- export function getNormalAttributes (node: TaroElement): TaroStyleType {
91
+ export function getNormalAttributes (node: TaroElement, initStyle?: HarmonyStyle): HarmonyStyle {
92
+ if (!node) return {}
93
+
34
94
  const hmStyle = node.hmStyle
95
+ if (!hmStyle) return {}
35
96
 
36
97
  const _nid = node._nid
37
98
  const _attrs: StandardProps = node._attrs || {}
38
99
 
39
- let linearGradient: HarmonyType.LinearGradient | undefined = undefined
40
- // 渐变
41
- if (hmStyle.backgroundImage?.colors) {
42
- linearGradient = hmStyle.backgroundImage
43
- }
100
+ let normalAttributes = hmStyle
44
101
 
45
- let normalAttributes: HarmonyStyle = {
46
- // Flex相关
47
- flexBasis: hmStyle.flexBasis,
48
- flexGrow: hmStyle.flexGrow,
49
- flexShrink: hmStyle.flexShrink,
50
- alignSelf: hmStyle.alignSelf,
51
- // 尺寸相关
52
- width: isMaxWidthView(node) && isUndefined(hmStyle.width) ? '100%' : hmStyle.width,
53
- height: hmStyle.height,
54
- minHeight: hmStyle.minHeight,
55
- maxHeight: hmStyle.maxHeight,
56
- minWidth: hmStyle.minWidth,
57
- maxWidth: hmStyle.maxWidth,
58
- marginTop: hmStyle.marginTop,
59
- marginRight: hmStyle.marginRight,
60
- marginBottom: hmStyle.marginBottom,
61
- marginLeft: hmStyle.marginLeft,
62
- paddingTop: hmStyle.paddingTop,
63
- paddingRight: hmStyle.paddingRight,
64
- paddingBottom: hmStyle.paddingBottom,
65
- paddingLeft: hmStyle.paddingLeft,
66
- // 边框相关
67
- borderStyle: hmStyle.borderStyle,
68
- borderTopStyle: hmStyle.borderTopStyle,
69
- borderRightStyle: hmStyle.borderRightStyle,
70
- borderBottomStyle: hmStyle.borderBottomStyle,
71
- borderLeftStyle: hmStyle.borderLeftStyle,
72
- borderWidth: hmStyle.borderWidth,
73
- borderTopWidth: hmStyle.borderTopWidth,
74
- borderRightWidth: hmStyle.borderRightWidth,
75
- borderBottomWidth: hmStyle.borderBottomWidth,
76
- borderLeftWidth: hmStyle.borderLeftWidth,
77
- borderColor: hmStyle.borderColor,
78
- borderTopColor: hmStyle.borderTopColor,
79
- borderRightColor: hmStyle.borderRightColor,
80
- borderBottomColor: hmStyle.borderBottomColor,
81
- borderLeftColor: hmStyle.borderLeftColor,
82
- borderRadius: hmStyle.borderRadius,
83
- borderTopLeftRadius: hmStyle.borderTopLeftRadius,
84
- borderTopRightRadius: hmStyle.borderTopRightRadius,
85
- borderBottomRightRadius: hmStyle.borderBottomRightRadius,
86
- borderBottomLeftRadius: hmStyle.borderBottomLeftRadius,
87
- // 背景相关
88
- backgroundColor: hmStyle.backgroundColor,
89
- backgroundImage: hmStyle.backgroundImage,
90
- backgroundSize: hmStyle.backgroundSize,
91
- backgroundRepeat: hmStyle.backgroundRepeat,
92
- backgroundPosition: hmStyle.backgroundPosition,
93
- linearGradient,
94
- // 变换相关
95
- transform: hmStyle.transform,
96
- transformOrigin: {
97
- x: hmStyle.transformOrigin?.x || 0,
98
- y: hmStyle.transformOrigin?.y || 0
99
- },
100
- // 通用文本相关
101
- color: hmStyle.color,
102
- fontSize: hmStyle.fontSize,
103
- fontStyle: hmStyle.fontStyle,
104
- fontWeight: hmStyle.fontWeight,
105
- fontFamily: hmStyle.fontFamily || TEXT_DEFAULT_STYLE.FONT_FAMILY,
106
- lineHeight: hmStyle.lineHeight,
107
- textDecoration: hmStyle.textDecoration,
108
- // 其他
109
- overflow: hmStyle.overflow,
110
- id: _attrs.id || _nid,
111
- opacity: hmStyle.opacity,
112
- zIndex: hmStyle.zIndex
113
- // focus: _attrs.focus || false,
102
+ // 覆盖属性
103
+ normalAttributes.id = _attrs.id || _nid.toString()
104
+
105
+ let pseudoStylesheet = getPseudoClass(node)
106
+ if (pseudoStylesheet) {
107
+ normalAttributes = ObjectAssign({}, normalAttributes, pseudoStylesheet)
114
108
  }
115
109
 
116
- // taro_page 等写死在运行时里的节点,没有 _nodeInfo
117
- if (node._nodeInfo) {
118
- const overwriteStyle: TaroStyleType = node._nodeInfo?.overwriteStyle
110
+ // 初始化默认的值
111
+ if (initStyle) {
112
+ normalAttributes = ObjectAssign({}, initStyle, normalAttributes)
113
+ }
114
+ return normalAttributes
115
+ }
119
116
 
120
- // 处理覆盖属性:如动画的覆盖
121
- if (overwriteStyle) {
122
- normalAttributes = ObjectAssign(normalAttributes, overwriteStyle)
117
+ // 应用伪类样式
118
+ function getPseudoClass (node: TaroElement): HarmonyStyle | null {
119
+ // 伪类
120
+ const _pseudo_class = Object.keys(node._pseudo_class)
121
+ if (_pseudo_class.length) {
122
+ for (let i = 0; i < _pseudo_class.length; i++) {
123
+ const pseudoKey = _pseudo_class[i]
124
+ const pseudoStylesheet = node._pseudo_class[pseudoKey]
125
+ if (!pseudoStylesheet) continue
126
+ switch(pseudoKey) {
127
+ case "::first-child": {
128
+ if (node.parentNode?.firstChild?._nid === node._nid) {
129
+ return pseudoStylesheet.hmStyle
130
+ }
131
+ break
132
+ }
133
+ case "::last-child": {
134
+ if (node.parentNode?.lastChild?._nid === node._nid) {
135
+ return pseudoStylesheet.hmStyle
136
+ }
137
+ break
138
+ }
139
+ case "::empty": {
140
+ if (node.children?.length === 0) {
141
+ return pseudoStylesheet.hmStyle
142
+ }
143
+ break
144
+ }
145
+ default: {
146
+ // 解析nth-child()
147
+ // 找出当前节点在父节点中的位置
148
+ // 公式
149
+ let matchs: [number, number] | null = null
150
+ if (pseudoKey === '::nth-child(odd)') {
151
+ matchs = [2, 1]
152
+ } else if (pseudoKey === '::nth-child(even)') {
153
+ matchs = [2, 0]
154
+ } else {
155
+ matchs = parseNthChild(pseudoKey)
156
+ }
157
+ if (matchs) {
158
+ let index = node.parentNode?.childNodes.findIndex((child) => child._nid === node._nid)
159
+ if (isUndefined(index)) return null
160
+ else {
161
+ index = index + 1
162
+ if (matchs[0] === 0) {
163
+ if (index === matchs[1]) {
164
+ return pseudoStylesheet.hmStyle
165
+ }
166
+ } else {
167
+ if ((index - matchs[1]) % matchs[0] === 0) {
168
+ return pseudoStylesheet.hmStyle
169
+ }
170
+ }
171
+ }
172
+ }
173
+ }
174
+ }
123
175
  }
124
176
  }
125
- return normalAttributes
177
+ return null
178
+ }
179
+
180
+ // 正则匹配nth-child
181
+ function parseNthChild(selector: string): [number, number] | null {
182
+ const regex = /nth-child\((?:(-?\d*)n\s*)?([+-]?\s*\d+)?\)/;
183
+ const match = selector.match(regex);
184
+
185
+ if (match) {
186
+ const a = match[1] ? parseInt(match[1]) : 0;
187
+ const b = match[2] ? parseInt(match[2]) : 0;
188
+ return [a, b];
189
+ } else {
190
+ return null;
191
+ }
192
+ }
193
+
194
+
195
+ export function getStyleAttr(node: TaroElement | null, key: string): TaroAny {
196
+ if (!node) return null
197
+ const hmStyle = node.hmStyle
198
+ if (!hmStyle) return null
199
+ // 覆盖属性
200
+ if (key === 'width') {
201
+ return isMaxWidthView(node) && isUndefined(hmStyle.width) ? '100%' : hmStyle.width
202
+ }
203
+ return hmStyle[key]
126
204
  }
@@ -4,7 +4,7 @@ import commonStyleModify from './style'
4
4
  import { TOUCH_EVENT_MAP } from './utils/constant/event'
5
5
  import { shouldBindEvent, getNodeThresholds } from './utils/helper'
6
6
 
7
- import type { TaroAny, TaroVideoElement, TaroEvent } from '@tarojs/runtime'
7
+ import type { TaroAny, TaroEvent, TaroVideoElement } from '@tarojs/runtime'
8
8
 
9
9
  export interface VideoOptions {
10
10
  src?: string | Resource
@@ -73,35 +73,43 @@ function getVideoProps (node: TaroVideoElement): VideoAttrs {
73
73
  }
74
74
 
75
75
  function handleUpdate (node: TaroVideoElement, e: VideoUpdateEvent) {
76
- node._currentTime = e.time
76
+ node._nodeInfo._currentTime = e.time
77
77
 
78
78
  emitEvent(node, 'timeUpdate', { currentTime: e.time})
79
79
  }
80
80
 
81
81
  @Component
82
82
  export default struct TaroVideo {
83
+ @Builder customBuilder() {}
84
+ @BuilderParam createLazyChildren: (node: TaroVideoElement, layer?: number) => void = this.customBuilder
83
85
  @ObjectLink node: TaroVideoElement
86
+ @State overwriteStyle: Record<string, TaroAny> = {}
87
+
88
+ aboutToAppear(): void {
89
+ if (this.node) {
90
+ this.node._instance = this
91
+ }
92
+ }
84
93
 
85
94
  build () {
86
95
  Video(getVideoData(this.node))
87
- .attributeModifier(commonStyleModify.setNode(this.node))
88
- .props(getVideoProps(this.node))
89
- .aspectRatio(4 / 3)
90
- .onStart(shouldBindEvent(() => { emitEvent(this.node, 'play') }, this.node, ['play']))
91
- .onPause(shouldBindEvent(() => { emitEvent(this.node, 'pause') }, this.node, ['pause']))
92
- .onFinish(shouldBindEvent(() => { emitEvent(this.node, 'ended') }, this.node, ['ended']))
93
- .onError(shouldBindEvent(() => { emitEvent(this.node, 'error') }, this.node, ['error']))
94
- .onUpdate((e) => { handleUpdate(this.node, e) })
95
- .onPrepared(shouldBindEvent((e: TaroAny) => { emitEvent(this.node, 'loadedMetaData', { duration: e.duration }) }, this.node, ['loadedmetadata']))
96
- .onSeeking(shouldBindEvent((e: TaroAny) => { emitEvent(this.node, 'seeking', { duration: e.time }) }, this.node, ['seeking']))
97
- .onSeeked(shouldBindEvent(() => { emitEvent(this.node, 'seeked') }, this.node, ['seeked']))
98
- .onFullscreenChange(shouldBindEvent((e: TaroAny) => { emitEvent(this.node, 'fullScreenChange', { fullScreen: e.fullscreen}) }, this.node, ['fullscreenchange']))
99
- .onClick((e: ClickEvent) => { eventHandler(e, 'click', this.node) })
100
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
101
- .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
102
- this.node._nodeInfo.areaInfo = res[1]
103
- }))
104
- .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
96
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
97
+ .props(getVideoProps(this.node))
98
+ .onStart(shouldBindEvent(() => { emitEvent(this.node, 'play') }, this.node, ['play']))
99
+ .onPause(shouldBindEvent(() => { emitEvent(this.node, 'pause') }, this.node, ['pause']))
100
+ .onFinish(shouldBindEvent(() => { emitEvent(this.node, 'ended') }, this.node, ['ended']))
101
+ .onError(shouldBindEvent(() => { emitEvent(this.node, 'error') }, this.node, ['error']))
102
+ .onUpdate((e) => { handleUpdate(this.node, e) })
103
+ .onPrepared(shouldBindEvent((e: TaroAny) => { emitEvent(this.node, 'loadedMetaData', { duration: e.duration }) }, this.node, ['loadedmetadata']))
104
+ .onSeeking(shouldBindEvent((e: TaroAny) => { emitEvent(this.node, 'seeking', { duration: e.time }) }, this.node, ['seeking']))
105
+ .onSeeked(shouldBindEvent(() => { emitEvent(this.node, 'seeked') }, this.node, ['seeked']))
106
+ .onFullscreenChange(shouldBindEvent((e: TaroAny) => { emitEvent(this.node, 'fullScreenChange', { fullScreen: e.fullscreen}) }, this.node, ['fullscreenchange']))
107
+ .onClick((e: ClickEvent) => { eventHandler(e, 'click', this.node) })
108
+ .onTouch(shouldBindEvent((e: TouchEvent) => { eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node) }, this.node, TOUCH_EVENT_MAP.values()))
109
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
110
+ this.node._nodeInfo.areaInfo = res[1]
111
+ }))
112
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
105
113
  }
106
114
 
107
115
  }
@@ -1,66 +1,72 @@
1
1
  import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME } from '@tarojs/runtime'
2
2
 
3
- import commonStyleModify from './style'
4
- import { createLazyChildren } from './render'
3
+ import commonStyleModify, { rowModify, columnModify } from './style'
4
+ import PseduoChildren from './pseudo'
5
5
  import { TOUCH_EVENT_MAP } from './utils/constant/event'
6
6
  import { FlexManager } from './utils/flexManager'
7
- import { getNodeThresholds, getNormalAttributes, shouldBindEvent } from './utils/helper'
7
+ import { getNodeThresholds, shouldBindEvent } from './utils/helper'
8
8
 
9
- import type { TaroViewElement, TaroStyleType, TaroAny } from '@tarojs/runtime'
10
-
11
- @Extend(Row)
12
- function rowAttrs (style: TaroStyleType) {
13
- .constraintSize({
14
- minWidth: style.minWidth || style.width,
15
- maxWidth: style.maxWidth,
16
- minHeight: style.minHeight,
17
- maxHeight: style.maxHeight
18
- })
19
- }
20
-
21
- @Extend(Column)
22
- function columnAttrs (style: TaroStyleType) {
23
- .constraintSize({
24
- minWidth: style.minWidth,
25
- maxWidth: style.maxWidth,
26
- minHeight: style.minHeight || style.height,
27
- maxHeight: style.maxHeight
28
- })
29
- }
9
+ import type { TaroAny, TaroViewElement } from '@tarojs/runtime'
30
10
 
31
11
  @Component
32
12
  export default struct TaroView {
13
+ @Builder customBuilder() {}
14
+ @BuilderParam createLazyChildren: (node: TaroViewElement, layer?: number) => void = this.customBuilder
33
15
  @ObjectLink node: TaroViewElement
16
+ @State overwriteStyle: Record<string, TaroAny> = {}
17
+
18
+ aboutToAppear(): void {
19
+ if (this.node) {
20
+ this.node._instance = this
21
+ }
22
+ }
34
23
 
35
24
  build () {
36
- if (FlexManager.isFlexNode(this.node) && FlexManager.flexOptions(this.node).direction !== FlexDirection.Column) {
25
+ if (FlexManager.useFlexLayout(this.node)) {
26
+ Flex(FlexManager.flexOptions(this.node)) {
27
+ if (this.node._pseudo_before || this.node._pseudo_after) {
28
+ PseduoChildren({ node: this.node, createLazyChildren: this.createLazyChildren })
29
+ } else {
30
+ this.createLazyChildren(this.node, 0)
31
+ }
32
+ }
33
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
34
+ .onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', this.node) }, this.node, ['click']))
35
+ .onTouch(shouldBindEvent((e: TouchEvent) => { eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node) }, this.node, TOUCH_EVENT_MAP.values()))
36
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
37
+ this.node._nodeInfo.areaInfo = res[1]
38
+ }))
39
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
40
+ } else if (FlexManager.isFlexNode(this.node) && FlexManager.direction(this.node) !== FlexDirection.Column) {
37
41
  Row() {
38
- createLazyChildren(this.node)
42
+ if (this.node._pseudo_before || this.node._pseudo_after) {
43
+ PseduoChildren({ node: this.node, createLazyChildren: this.createLazyChildren })
44
+ } else {
45
+ this.createLazyChildren(this.node, 0)
46
+ }
39
47
  }
40
- .attributeModifier(commonStyleModify.setNode(this.node))
41
- .rowAttrs(getNormalAttributes(this.node))
42
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
43
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
48
+ .attributeModifier(rowModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
49
+ .onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', this.node) }, this.node, ['click']))
50
+ .onTouch(shouldBindEvent((e: TouchEvent) => { eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node) }, this.node, TOUCH_EVENT_MAP.values()))
44
51
  .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
45
52
  this.node._nodeInfo.areaInfo = res[1]
46
53
  }))
47
54
  .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
48
- .alignItems(FlexManager.flexOptions(this.node).alignItems as VerticalAlign)
49
- .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
50
55
  } else {
51
56
  Column() {
52
- createLazyChildren(this.node)
57
+ if (this.node._pseudo_before || this.node._pseudo_after) {
58
+ PseduoChildren({ node: this.node, createLazyChildren: this.createLazyChildren })
59
+ } else {
60
+ this.createLazyChildren(this.node, 0)
61
+ }
53
62
  }
54
- .attributeModifier(commonStyleModify.setNode(this.node))
55
- .columnAttrs(getNormalAttributes(this.node))
56
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
57
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
63
+ .attributeModifier(columnModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
64
+ .onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', this.node) }, this.node, ['click']))
65
+ .onTouch(shouldBindEvent((e: TouchEvent) => { eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node) }, this.node, TOUCH_EVENT_MAP.values()))
58
66
  .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
59
67
  this.node._nodeInfo.areaInfo = res[1]
60
68
  }))
61
69
  .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
62
- .alignItems(FlexManager.flexOptions(this.node).alignItems as HorizontalAlign)
63
- .justifyContent(FlexManager.flexOptions(this.node).justifyContent)
64
70
  }
65
71
  }
66
72
  }
@@ -1,9 +1,9 @@
1
1
  import { AREA_CHANGE_EVENT_NAME, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
2
2
 
3
3
  import commonStyleModify from './style'
4
- import { getNormalAttributes, shouldBindEvent, getNodeThresholds } from './utils/helper'
4
+ import { shouldBindEvent, getNodeThresholds } from './utils/helper'
5
5
 
6
- import type { TaroAny, TaroWebViewElement, TaroStyleType, TaroEvent } from '@tarojs/runtime'
6
+ import type { TaroAny, TaroEvent, TaroWebViewElement } from '@tarojs/runtime'
7
7
 
8
8
  interface IPageLoad {
9
9
  url: string
@@ -16,6 +16,8 @@ interface IError {
16
16
 
17
17
  @Component
18
18
  export default struct TaroWebView {
19
+ @Builder customBuilder() {}
20
+ @BuilderParam createLazyChildren: (node: TaroWebViewElement, layer?: number) => void = this.customBuilder
19
21
  @ObjectLink node: TaroWebViewElement
20
22
 
21
23
  build () {
@@ -42,14 +44,13 @@ export default struct TaroWebView {
42
44
  })
43
45
  .onErrorReceive(shouldBindEvent((e: IError) => {
44
46
  const event: TaroEvent = createTaroEvent('error', { detail: { url: this.node._attrs.src, fullUrl: e.request.getRequestUrl() } }, this.node)
45
-
47
+
46
48
  eventHandler(event, 'error', this.node)
47
49
  }, this.node, ['error']))
48
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
50
+ .onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', this.node) }, this.node, ['click']))
49
51
  .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
50
52
  this.node._nodeInfo.areaInfo = res[1]
51
53
  }))
52
54
  .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
53
-
54
55
  }
55
56
  }