@tarojs/plugin-platform-harmony-ets 4.0.0-beta.2 → 4.0.0-beta.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/apis/base/system.ts +53 -20
  2. package/dist/apis/framework/index.ts +1 -5
  3. package/dist/apis/index.ts +3 -1
  4. package/dist/apis/network/request.ts +5 -5
  5. package/dist/apis/route/index.ts +15 -0
  6. package/dist/apis/storage/index.ts +124 -60
  7. package/dist/apis/wxml/IntersectionObserver.ts +5 -3
  8. package/dist/apis/wxml/index.ts +2 -0
  9. package/dist/components-harmony-ets/button.ets +41 -78
  10. package/dist/components-harmony-ets/checkbox.ets +19 -209
  11. package/dist/components-harmony-ets/form.ets +38 -160
  12. package/dist/components-harmony-ets/icon.ets +31 -83
  13. package/dist/components-harmony-ets/image.ets +22 -78
  14. package/dist/components-harmony-ets/innerHtml.ets +11 -6
  15. package/dist/components-harmony-ets/input.ets +10 -67
  16. package/dist/components-harmony-ets/label.ets +52 -173
  17. package/dist/components-harmony-ets/movableArea.ets +89 -0
  18. package/dist/components-harmony-ets/movableView.ets +67 -0
  19. package/dist/components-harmony-ets/picker.ets +32 -147
  20. package/dist/components-harmony-ets/progress.ets +47 -0
  21. package/dist/components-harmony-ets/pseudo.ets +80 -0
  22. package/dist/components-harmony-ets/radio.ets +19 -210
  23. package/dist/components-harmony-ets/richText.ets +22 -102
  24. package/dist/components-harmony-ets/scrollView.ets +66 -169
  25. package/dist/components-harmony-ets/slider.ets +10 -72
  26. package/dist/components-harmony-ets/style.ets +244 -0
  27. package/dist/components-harmony-ets/swiper.ets +30 -87
  28. package/dist/components-harmony-ets/switch.ets +9 -71
  29. package/dist/components-harmony-ets/text.ets +38 -89
  30. package/dist/components-harmony-ets/textArea.ets +10 -67
  31. package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
  32. package/dist/components-harmony-ets/utils/DynamicCenter.ts +1 -1
  33. package/dist/components-harmony-ets/utils/flexManager.ets +8 -7
  34. package/dist/components-harmony-ets/utils/helper.ets +5 -4
  35. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  36. package/dist/components-harmony-ets/utils/index.ts +55 -2
  37. package/dist/components-harmony-ets/utils/styles.ets +45 -85
  38. package/dist/components-harmony-ets/video.ets +33 -88
  39. package/dist/components-harmony-ets/view.ets +47 -160
  40. package/dist/components-harmony-ets/webView.ets +44 -99
  41. package/dist/index.d.ts +151 -0
  42. package/dist/index.js +58 -29
  43. package/dist/index.js.map +1 -1
  44. package/dist/runtime-ets/bom/window.ts +4 -2
  45. package/dist/runtime-ets/current.ts +2 -0
  46. package/dist/runtime-ets/dom/bind.ts +0 -1
  47. package/dist/runtime-ets/dom/cssNesting.ts +311 -0
  48. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +15 -40
  49. package/dist/runtime-ets/dom/document.ts +21 -8
  50. package/dist/runtime-ets/dom/element/element.ts +53 -9
  51. package/dist/runtime-ets/dom/element/form.ts +11 -4
  52. package/dist/runtime-ets/dom/element/index.ts +12 -1
  53. package/dist/runtime-ets/dom/element/movableArea.ts +12 -0
  54. package/dist/runtime-ets/dom/element/movableView.ts +193 -0
  55. package/dist/runtime-ets/dom/element/normal.ts +8 -3
  56. package/dist/runtime-ets/dom/element/progress.ts +13 -0
  57. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  58. package/dist/runtime-ets/dom/element/text.ts +1 -0
  59. package/dist/runtime-ets/dom/element/video.ts +1 -0
  60. package/dist/runtime-ets/dom/element/webView.ts +8 -0
  61. package/dist/runtime-ets/dom/event.ts +0 -1
  62. package/dist/runtime-ets/dom/eventTarget.ts +0 -3
  63. package/dist/runtime-ets/dom/node.ts +18 -17
  64. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +184 -207
  65. package/dist/runtime-ets/dom/stylesheet/index.ts +28 -308
  66. package/dist/runtime-ets/dom/stylesheet/type.ts +18 -6
  67. package/dist/runtime-ets/dom/stylesheet/util.ts +19 -15
  68. package/dist/runtime-ets/index.ts +2 -2
  69. package/dist/runtime-ets/interface/event.ts +1 -1
  70. package/dist/runtime-ets/utils/index.ts +24 -9
  71. package/dist/runtime-framework/react/app.ts +5 -1
  72. package/dist/runtime-framework/react/hooks.ts +3 -3
  73. package/dist/runtime-framework/react/native-page.ts +14 -9
  74. package/dist/runtime-framework/react/page.ts +1 -0
  75. package/dist/runtime-framework/solid/hooks.ts +3 -3
  76. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  77. package/dist/runtime-framework/solid/utils/index.ts +0 -2
  78. package/dist/runtime-utils.d.ts +825 -0
  79. package/dist/runtime-utils.js +185 -91
  80. package/dist/runtime-utils.js.map +1 -1
  81. package/dist/runtime.d.ts +1 -0
  82. package/dist/runtime.js +185 -91
  83. package/dist/runtime.js.map +1 -1
  84. package/index.js +3 -1
  85. package/package.json +10 -10
  86. package/types/index.d.ts +4 -0
  87. package/dist/runtime-ets/utils/bind.ts +0 -24
@@ -1,72 +1,12 @@
1
1
  import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
2
2
 
3
- import { getNodeThresholds, getNormalAttributes, getFontAttributes, shouldBindEvent, parseStyles } from './utils/helper'
3
+ import commonStyleModify from './style'
4
+ import { getNodeThresholds, getFontAttributes, shouldBindEvent, parseStyles } from './utils/helper'
4
5
 
5
6
  import type { TaroAny, TaroStyleType, TaroTextStyleType, TaroTextAreaElement, TaroEvent } from '@tarojs/runtime'
6
7
 
7
8
  @Extend(TextArea)
8
9
  function textStyle (style: TaroStyleType) {
9
- .id(style.id)
10
- .key(style.id)
11
- .flexGrow(style.flexGrow)
12
- .flexShrink(style.flexShrink)
13
- .flexBasis(style.flexBasis)
14
- .alignSelf(style.alignSelf)
15
- .padding({
16
- top: style.paddingTop,
17
- right: style.paddingRight,
18
- bottom: style.paddingBottom,
19
- left: style.paddingLeft
20
- })
21
- .margin({
22
- top: style.marginTop,
23
- right: style.marginRight,
24
- bottom: style.marginBottom,
25
- left: style.marginLeft
26
- })
27
- .width(style.width)
28
- .height(style.height)
29
- .constraintSize({
30
- minWidth: style.minWidth,
31
- maxWidth: style.maxWidth,
32
- minHeight: style.minHeight,
33
- maxHeight: style.maxHeight
34
- })
35
- .backgroundColor(style.backgroundColor)
36
- .backgroundImage(style.backgroundImage?.src, style.backgroundRepeat)
37
- .backgroundImageSize(style.backgroundSize)
38
- .backgroundImagePosition(style.backgroundPosition)
39
- .borderStyle({
40
- top: style.borderTopStyle,
41
- right: style.borderRightStyle,
42
- bottom: style.borderBottomStyle,
43
- left: style.borderLeftStyle
44
- })
45
- .borderWidth({
46
- top: style.borderTopWidth,
47
- right: style.borderRightWidth,
48
- bottom: style.borderBottomWidth,
49
- left: style.borderLeftWidth
50
- })
51
- .borderColor({
52
- top: style.borderTopColor,
53
- right: style.borderRightColor,
54
- bottom: style.borderBottomColor,
55
- left: style.borderLeftColor
56
- })
57
- .borderRadius({
58
- topLeft: style.borderTopLeftRadius,
59
- topRight: style.borderTopRightRadius,
60
- bottomLeft: style.borderBottomLeftRadius,
61
- bottomRight: style.borderBottomRightRadius
62
- })
63
- .zIndex(style.zIndex)
64
- .opacity(style.opacity)
65
- .linearGradient(style.linearGradient)
66
- .clip(style.overflow)
67
- .rotate({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y, angle: 0 })
68
- .scale({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y })
69
- .transform(style.transform)
70
10
  .fontColor(style.color)
71
11
  .fontSize(style.fontSize)
72
12
  .fontWeight(style.fontWeight)
@@ -90,7 +30,9 @@ function getPlaceholderColor (node: TaroTextAreaElement): string {
90
30
  export default struct TaroTextArea {
91
31
  @State value: string = ''
92
32
 
93
- node: TaroTextAreaElement | null = null
33
+ @Builder customBuilder() {}
34
+ @BuilderParam createLazyChildren: (node: TaroTextAreaElement) => void = this.customBuilder
35
+ @ObjectLink node: TaroTextAreaElement
94
36
 
95
37
  aboutToAppear () {
96
38
  if (this.node) {
@@ -105,16 +47,17 @@ export default struct TaroTextArea {
105
47
  }
106
48
 
107
49
  build () {
108
- if (this.node) {
50
+ if (this.node && this.node.hmStyle?.display !== 'none') {
109
51
  TextArea({ text: this.value, placeholder: this.node._attrs?.placeholder || '', controller: this.node.controller })
110
52
  .key(this.node._nid)
111
53
  .maxLength(Number(this.node._attrs?.maxlength) || null)
112
54
  .placeholderColor(getPlaceholderColor(this.node))
113
- .textStyle(getNormalAttributes(this.node))
55
+ .attributeModifier(commonStyleModify.setNode(this.node))
56
+ .textStyle(this.node?.hmStyle)
114
57
  .textAttr(getFontAttributes(this.node))
115
58
  .onChange((value: string) => {
116
59
  const event: TaroEvent = createTaroEvent('input', { detail: { value } }, this.node)
117
-
60
+
118
61
  this.value = value
119
62
  this.node?.updateFormWidgetValue(value)
120
63
  eventHandler(event, 'input', this.node)
@@ -126,7 +69,7 @@ export default struct TaroTextArea {
126
69
  })
127
70
  .onFocus(() => {
128
71
  const event: TaroEvent = createTaroEvent('focus', { detail: { value: this.value, height: this.node?._height } }, this.node)
129
-
72
+
130
73
  eventHandler(event, 'focus', this.node)
131
74
  })
132
75
  .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
@@ -60,7 +60,7 @@ class AttributeManager {
60
60
  const dataValue: string = AttributeManager.getNodeStyle(style, 'animation')
61
61
 
62
62
  if (dataValue) {
63
- let values: string[] = dataValue.trim().split(new RegExp("/\s+/"))
63
+ let values: string[] = dataValue.toString().trim().split(new RegExp("/\s+/"))
64
64
  switch (values.length) {
65
65
  case 4:
66
66
  res = { duration: values[0], curve: values[1], delay: values[2] }
@@ -36,4 +36,4 @@ export class DynamicCenter {
36
36
  this.bindComponentToNodeWithDFS(node.childNodes[i] as TaroElement, component)
37
37
  }
38
38
  }
39
- }
39
+ }
@@ -1,4 +1,5 @@
1
1
  import type { TaroElement } from '@tarojs/runtime'
2
+ import { isUndefined } from '@tarojs/shared'
2
3
 
3
4
  interface IFlexOptions {
4
5
  direction: FlexDirection,
@@ -17,21 +18,21 @@ class FlexManager {
17
18
  static convertFlexAlignItemsToColumnOrRow (direction: FlexDirection, alignItems: ItemAlign | undefined): VerticalAlign | HorizontalAlign {
18
19
  if (direction === FlexDirection.Column) {
19
20
  switch (alignItems) {
20
- case ItemAlign.Start:
21
- return HorizontalAlign.Start
21
+ case ItemAlign.Center:
22
+ return HorizontalAlign.Center
22
23
  case ItemAlign.End:
23
24
  return HorizontalAlign.End
24
25
  default:
25
- return HorizontalAlign.Center
26
+ return HorizontalAlign.Start
26
27
  }
27
28
  } else {
28
29
  switch (alignItems) {
29
- case ItemAlign.Start:
30
- return VerticalAlign.Top
30
+ case ItemAlign.Center:
31
+ return VerticalAlign.Center
31
32
  case ItemAlign.End:
32
33
  return VerticalAlign.Bottom
33
34
  default:
34
- return VerticalAlign.Center
35
+ return VerticalAlign.Top
35
36
  }
36
37
  }
37
38
  }
@@ -39,7 +40,7 @@ class FlexManager {
39
40
  static flexOptions (node: TaroElement): IFlexOptions {
40
41
  const hmStyle = node.hmStyle
41
42
  const isFlex = FlexManager.isFlexNode(node)
42
- const justifyContent: FlexAlign = isFlex ? (hmStyle.justifyContent || FlexAlign.Center) : FlexAlign.Start
43
+ const justifyContent: FlexAlign = isFlex ? (isUndefined(hmStyle.justifyContent) ? FlexAlign.Start : hmStyle.justifyContent) : FlexAlign.Start
43
44
 
44
45
  let flexDirection = hmStyle.flexDirection
45
46
  if (!flexDirection && flexDirection !== 0) {
@@ -1,6 +1,6 @@
1
- import { getNormalAttributes, getFontAttributes } from './styles'
1
+ import { getNormalAttributes, getFontAttributes, getStyleAttr } from './styles'
2
2
 
3
- import type { Func } from '@tarojs/runtime/dist/runtime.esm'
3
+ import type { TFunc } from '@tarojs/runtime/dist/runtime.esm'
4
4
  import type { TaroElement } from '@tarojs/runtime'
5
5
 
6
6
  export const parseStyles = (styles = ''): Record<string, string> => {
@@ -20,7 +20,7 @@ export const parseStyles = (styles = ''): Record<string, string> => {
20
20
  return styleObj
21
21
  }
22
22
 
23
- export function shouldBindEvent (cb: Func, node: TaroElement | null, eventNames: string[], disabled = false) {
23
+ export function shouldBindEvent (cb: TFunc, node: TaroElement | null, eventNames: string[], disabled = false) {
24
24
  if (!node || node._attrs?.disabled || disabled) return null
25
25
  if (!node.__listeners) {
26
26
  return null
@@ -36,4 +36,5 @@ export function getNodeThresholds (node: TaroElement): number[] | null {
36
36
  return node?._nodeInfo.thresholds || null
37
37
  }
38
38
 
39
- export { getNormalAttributes, getFontAttributes }
39
+
40
+ export { getNormalAttributes, getFontAttributes, getStyleAttr }
@@ -99,5 +99,4 @@ function parseTag(htmlString, startIndex) {
99
99
  return tag
100
100
  }
101
101
 
102
-
103
- export default parseHTML
102
+ export default parseHTML
@@ -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])
@@ -30,7 +33,7 @@ export function getUnit (val) {
30
33
  function handleNodeStyleData (dataValue: string, handler: (values: string[]) => { [key: string]: string } | void) {
31
34
  let res: any = {}
32
35
  if (dataValue) {
33
- const values = dataValue.trim().split(/\s+/)
36
+ const values = dataValue.toString().trim().split(/\s+/)
34
37
  const data = handler(values)
35
38
 
36
39
  if (!data) return res
@@ -81,3 +84,53 @@ export function getNodeMarginOrPaddingData (dataValue: string) {
81
84
  }
82
85
  })
83
86
  }
87
+
88
+ export function generateText (node: TaroRichTextElement): string {
89
+ return parseHtmlNode(node._attrs.nodes || '')
90
+ }
91
+
92
+ // 将nodeTree转换成harmony需要的string结构
93
+ function nodeToHtml(node: RichTextProps.Text | RichTextProps.HTMLElement): string {
94
+ if (node.type === 'text') {
95
+ return node.text
96
+ }
97
+ if (node.attrs) {
98
+ const attributes = Object.entries(node.attrs)
99
+ .map((item: [string, string]) => `${item[0]}="${item[1]}"`)
100
+ .join(' ')
101
+ const childrenHtml: string = typeof node.children === 'string' ? node.children : (node.children || []).map((child: RichTextProps.Text | RichTextProps.HTMLElement) => nodeToHtml(child)).join('')
102
+ return `<${node.name}${attributes ? ' ' + attributes : ''}>${childrenHtml}</${node.name}>`
103
+ }
104
+ return ''
105
+ }
106
+
107
+ function parseHtmlNode (nodes: Array<RichTextProps.Text | RichTextProps.HTMLElement> | string) {
108
+ return typeof nodes === 'string' ? nodes: `<div>${nodes.map(node => nodeToHtml(node)).join('')}</div>`
109
+ }
110
+
111
+ // 背景偏移算法:https://developer.mozilla.org/zh-CN/docs/Web/CSS/background-position
112
+ export function computeBackgroundPosition(style) {
113
+ let offsetX = 0
114
+ let offsetY = 0
115
+ if (style.backgroundSize && typeof style.backgroundSize !== 'number') {
116
+ if (!isUndefined(style.backgroundSize.width) && style.width) {
117
+ if (typeof style.backgroundPosition.x === 'string' && style.backgroundPosition.x.indexOf('%') > 0) {
118
+ // (container width - image width) * (position x%) = (x offset value)
119
+ const width = parseFloat(style.width)
120
+ const bgWidth = parseFloat(style.backgroundSize.width)
121
+ const bgOffsetX = parseFloat(style.backgroundPosition.x)
122
+ offsetX = Number((width - bgWidth) * (bgOffsetX) / 100) || 0
123
+ }
124
+ }
125
+ if (!isUndefined(style.backgroundSize.height) && style.height) {
126
+ if (typeof style.backgroundPosition.y === 'string' && style.backgroundPosition.y.indexOf('%') > 0) {
127
+ // (container height - image height) * (position y%) = (y offset value)
128
+ const height = parseFloat(style.height)
129
+ const bgHeight = parseFloat(style.backgroundSize.height)
130
+ const bgOffsetY = parseFloat(style.backgroundPosition.y)
131
+ offsetY = Number((height - bgHeight) * (bgOffsetY) / 100) || 0
132
+ }
133
+ }
134
+ }
135
+ return { offsetX: isNaN(offsetX) ? style.backgroundPosition.x : offsetX, offsetY: isNaN(offsetY) ? style.backgroundPosition.y: offsetY }
136
+ }
@@ -1,125 +1,85 @@
1
1
  import { isUndefined } from '@tarojs/shared'
2
2
  import { ObjectAssign } from '@tarojs/runtime'
3
3
 
4
- import { FlexManager } from './FlexManager'
5
- import { TEXT_DEFAULT_STYLE } from './constant/style'
4
+ import { FlexManager } from './flexManager'
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, TaroStyleType, TaroTextStyleType, HarmonyStyle } from '@tarojs/runtime'
9
8
 
10
9
  export function getFontAttributes (node: TaroElement): TaroTextStyleType {
11
10
  const hmStyle = node.hmStyle
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
+
14
30
  const attributes: TaroAny = {
15
- WebkitLineClamp: attrs.maxLines || hmStyle.WebkitLineClamp || Infinity,
31
+ WebkitLineClamp: WebkitLineClamp,
16
32
  // 已做处理的属性
17
33
  letterSpacing: hmStyle.letterSpacing,
18
34
  textAlign: hmStyle.textAlign,
19
- textOverflow: hmStyle.textOverflow
35
+ textOverflow: hmStyle.textOverflow,
36
+ verticalAlign: hmStyle.verticalAlign,
37
+ lineHeight: lineHeight
20
38
  }
21
39
 
22
40
  return attributes
23
41
  }
24
42
 
25
43
  // 模拟 div 自动撑满父元素的情况
26
- function isMaxWidthView (node: TaroElement) {
44
+ export function isMaxWidthView (node: TaroElement) {
27
45
  const parentNode: TaroElement = node.parentNode as TaroElement
28
-
29
- return node.tagName === 'VIEW' && parentNode.tagName === 'VIEW' &&
46
+
47
+ return node.tagName === 'VIEW' && parentNode && parentNode.tagName === 'VIEW' &&
30
48
  !(FlexManager.isFlexNode(parentNode) && FlexManager.flexOptions(parentNode).direction !== FlexDirection.Column)
31
49
  }
32
50
 
33
- export function getNormalAttributes (node: TaroElement): TaroStyleType {
51
+ export function getNormalAttributes (node: TaroElement): HarmonyStyle {
34
52
  const hmStyle = node.hmStyle
53
+
54
+ if (!hmStyle) return {}
35
55
 
36
56
  const _nid = node._nid
37
57
  const _attrs: StandardProps = node._attrs || {}
38
58
 
39
- let linearGradient: HarmonyType.LinearGradient | undefined = undefined
40
- // 渐变
41
- if (hmStyle.backgroundImage?.colors) {
42
- linearGradient = hmStyle.backgroundImage
43
- }
59
+ let normalAttributes = hmStyle
44
60
 
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
- // focus: _attrs.focus || false,
113
- }
61
+ // 覆盖属性
62
+ normalAttributes.id = _attrs.id || _nid
114
63
 
115
64
  // taro_page 等写死在运行时里的节点,没有 _nodeInfo
116
65
  if (node._nodeInfo) {
117
66
  const overwriteStyle: TaroStyleType = node._nodeInfo?.overwriteStyle
118
-
119
67
  // 处理覆盖属性:如动画的覆盖
120
68
  if (overwriteStyle) {
121
- normalAttributes = ObjectAssign(normalAttributes, overwriteStyle)
69
+ normalAttributes = ObjectAssign({}, normalAttributes, overwriteStyle)
122
70
  }
123
71
  }
124
72
  return normalAttributes
125
73
  }
74
+
75
+
76
+ export function getStyleAttr(node: TaroElement | null, key: string): TaroAny {
77
+ if (!node) return null
78
+ const hmStyle = node.hmStyle
79
+ if (!hmStyle) return null
80
+ // 覆盖属性
81
+ if (key === 'width') {
82
+ return isMaxWidthView(node) && isUndefined(hmStyle.width) ? '100%' : hmStyle.width
83
+ }
84
+ return hmStyle[key]
85
+ }
@@ -1,9 +1,10 @@
1
1
  import { AREA_CHANGE_EVENT_NAME, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
2
2
 
3
+ import commonStyleModify from './style'
3
4
  import { TOUCH_EVENT_MAP } from './utils/constant/event'
4
- import { getNormalAttributes, shouldBindEvent, getNodeThresholds } from './utils/helper'
5
+ import { shouldBindEvent, getNodeThresholds } from './utils/helper'
5
6
 
6
- import type { TaroStyleType, TaroAny, TaroVideoElement, TaroEvent } from '@tarojs/runtime'
7
+ import type { TaroAny, TaroVideoElement, TaroEvent } from '@tarojs/runtime'
7
8
 
8
9
  export interface VideoOptions {
9
10
  src?: string | Resource
@@ -21,71 +22,6 @@ export interface VideoUpdateEvent {
21
22
  time: number
22
23
  }
23
24
 
24
- @Extend(Video)
25
- function attrs (style: TaroStyleType) {
26
- .id(style.id)
27
- .key(style.id)
28
- .flexGrow(style.flexGrow)
29
- .flexShrink(style.flexShrink)
30
- .flexBasis(style.flexBasis)
31
- .alignSelf(style.alignSelf)
32
- .padding({
33
- top: style.paddingTop,
34
- right: style.paddingRight,
35
- bottom: style.paddingBottom,
36
- left: style.paddingLeft
37
- })
38
- .margin({
39
- top: style.marginTop,
40
- right: style.marginRight,
41
- bottom: style.marginBottom,
42
- left: style.marginLeft
43
- })
44
- .width(style.width)
45
- .height(style.height)
46
- .constraintSize({
47
- minWidth: style.minWidth,
48
- maxWidth: style.maxWidth,
49
- minHeight: style.minHeight,
50
- maxHeight: style.maxHeight
51
- })
52
- .backgroundColor(style.backgroundColor)
53
- .backgroundImage(style.backgroundImage?.src, style.backgroundRepeat)
54
- .backgroundImageSize(style.backgroundSize)
55
- .backgroundImagePosition(style.backgroundPosition)
56
- .borderStyle({
57
- top: style.borderTopStyle,
58
- right: style.borderRightStyle,
59
- bottom: style.borderBottomStyle,
60
- left: style.borderLeftStyle
61
- })
62
- .borderWidth({
63
- top: style.borderTopWidth,
64
- right: style.borderRightWidth,
65
- bottom: style.borderBottomWidth,
66
- left: style.borderLeftWidth
67
- })
68
- .borderColor({
69
- top: style.borderTopColor,
70
- right: style.borderRightColor,
71
- bottom: style.borderBottomColor,
72
- left: style.borderLeftColor
73
- })
74
- .borderRadius({
75
- topLeft: style.borderTopLeftRadius,
76
- topRight: style.borderTopRightRadius,
77
- bottomLeft: style.borderBottomLeftRadius,
78
- bottomRight: style.borderBottomRightRadius
79
- })
80
- .zIndex(style.zIndex)
81
- .opacity(style.opacity)
82
- .linearGradient(style.linearGradient)
83
- .clip(style.overflow)
84
- .rotate({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y, angle: 0 })
85
- .scale({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y })
86
- .transform(style.transform)
87
- }
88
-
89
25
  @Extend(Video)
90
26
  function props(attr: VideoAttrs) {
91
27
  .muted(attr.muted)
@@ -142,25 +78,34 @@ function handleUpdate (node: TaroVideoElement, e: VideoUpdateEvent) {
142
78
  emitEvent(node, 'timeUpdate', { currentTime: e.time})
143
79
  }
144
80
 
145
- @Builder
146
- export default function TaroVideo (node: TaroVideoElement) {
147
- Video(getVideoData(node))
148
- .attrs(getNormalAttributes(node))
149
- .props(getVideoProps(node))
150
- .aspectRatio(4 / 3)
151
- .onStart(shouldBindEvent(() => { emitEvent(node, 'play') }, node, ['play']))
152
- .onPause(shouldBindEvent(() => { emitEvent(node, 'pause') }, node, ['pause']))
153
- .onFinish(shouldBindEvent(() => { emitEvent(node, 'ended') }, node, ['ended']))
154
- .onError(shouldBindEvent(() => { emitEvent(node, 'error') }, node, ['error']))
155
- .onUpdate((e) => { handleUpdate(node, e) })
156
- .onPrepared(shouldBindEvent((e: TaroAny) => { emitEvent(node, 'loadedMetaData', { duration: e.duration }) }, node, ['loadedmetadata']))
157
- .onSeeking(shouldBindEvent((e: TaroAny) => { emitEvent(node, 'seeking', { duration: e.time }) }, node, ['seeking']))
158
- .onSeeked(shouldBindEvent(() => { emitEvent(node, 'seeked') }, node, ['seeked']))
159
- .onFullscreenChange(shouldBindEvent((e: TaroAny) => { emitEvent(node, 'fullScreenChange', { fullScreen: e.fullscreen}) }, node, ['fullscreenchange']))
160
- .onClick((e: ClickEvent) => { eventHandler(e, 'click', node) })
161
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
162
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
163
- node._nodeInfo.areaInfo = res[1]
164
- }))
165
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
81
+ @Component
82
+ export default struct TaroVideo {
83
+ @Builder customBuilder() {}
84
+ @BuilderParam createLazyChildren: (node: TaroVideoElement) => void = this.customBuilder
85
+ @ObjectLink node: TaroVideoElement
86
+
87
+ build () {
88
+ if (this.node.hmStyle?.display !== 'none') {
89
+ Video(getVideoData(this.node))
90
+ .attributeModifier(commonStyleModify.setNode(this.node))
91
+ .props(getVideoProps(this.node))
92
+ .aspectRatio(4 / 3)
93
+ .onStart(shouldBindEvent(() => { emitEvent(this.node, 'play') }, this.node, ['play']))
94
+ .onPause(shouldBindEvent(() => { emitEvent(this.node, 'pause') }, this.node, ['pause']))
95
+ .onFinish(shouldBindEvent(() => { emitEvent(this.node, 'ended') }, this.node, ['ended']))
96
+ .onError(shouldBindEvent(() => { emitEvent(this.node, 'error') }, this.node, ['error']))
97
+ .onUpdate((e) => { handleUpdate(this.node, e) })
98
+ .onPrepared(shouldBindEvent((e: TaroAny) => { emitEvent(this.node, 'loadedMetaData', { duration: e.duration }) }, this.node, ['loadedmetadata']))
99
+ .onSeeking(shouldBindEvent((e: TaroAny) => { emitEvent(this.node, 'seeking', { duration: e.time }) }, this.node, ['seeking']))
100
+ .onSeeked(shouldBindEvent(() => { emitEvent(this.node, 'seeked') }, this.node, ['seeked']))
101
+ .onFullscreenChange(shouldBindEvent((e: TaroAny) => { emitEvent(this.node, 'fullScreenChange', { fullScreen: e.fullscreen}) }, this.node, ['fullscreenchange']))
102
+ .onClick((e: ClickEvent) => { eventHandler(e, 'click', this.node) })
103
+ .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
104
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
105
+ this.node._nodeInfo.areaInfo = res[1]
106
+ }))
107
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
108
+ }
109
+ }
110
+
166
111
  }