@tarojs/plugin-platform-harmony-ets 4.0.0-canary.8 → 4.0.0

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 (135) hide show
  1. package/dist/apis/base/system.ts +73 -20
  2. package/dist/apis/canvas/index.ts +10 -1
  3. package/dist/apis/device/clipboard.ts +23 -8
  4. package/dist/apis/framework/index.ts +1 -5
  5. package/dist/apis/index.ts +27 -17
  6. package/dist/apis/media/image/index.ts +169 -17
  7. package/dist/apis/network/request.ts +5 -5
  8. package/dist/apis/route/index.ts +15 -0
  9. package/dist/apis/storage/index.ts +146 -78
  10. package/dist/apis/ui/animation/animation.ts +71 -29
  11. package/dist/apis/ui/background.ts +2 -1
  12. package/dist/apis/ui/interaction/index.ts +58 -59
  13. package/dist/apis/ui/navigation-bar/index.ts +1 -1
  14. package/dist/apis/ui/pull-down-refresh.ts +9 -3
  15. package/dist/apis/ui/scroll/index.ts +5 -5
  16. package/dist/apis/ui/tab-bar.ts +3 -3
  17. package/dist/apis/utils/index.ts +21 -2
  18. package/dist/apis/utils/permissions.ts +6 -0
  19. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  20. package/dist/apis/wxml/index.ts +2 -0
  21. package/dist/apis/wxml/selectorQuery.ts +26 -13
  22. package/dist/components-harmony-ets/button.ets +63 -77
  23. package/dist/components-harmony-ets/canvas.ets +51 -0
  24. package/dist/components-harmony-ets/checkbox.ets +75 -258
  25. package/dist/components-harmony-ets/form.ets +51 -158
  26. package/dist/components-harmony-ets/icon.ets +33 -83
  27. package/dist/components-harmony-ets/image.ets +35 -79
  28. package/dist/components-harmony-ets/index.ets +92 -0
  29. package/dist/components-harmony-ets/innerHtml.ets +11 -6
  30. package/dist/components-harmony-ets/input.ets +64 -101
  31. package/dist/components-harmony-ets/label.ets +72 -174
  32. package/dist/components-harmony-ets/listView.ets +31 -0
  33. package/dist/components-harmony-ets/movableArea.ets +126 -0
  34. package/dist/components-harmony-ets/movableView.ets +93 -0
  35. package/dist/components-harmony-ets/navigationBar.ets +65 -0
  36. package/dist/components-harmony-ets/pageMeta.ets +94 -0
  37. package/dist/components-harmony-ets/picker.ets +46 -163
  38. package/dist/components-harmony-ets/progress.ets +52 -0
  39. package/dist/components-harmony-ets/pseudo.ets +80 -0
  40. package/dist/components-harmony-ets/radio.ets +80 -264
  41. package/dist/components-harmony-ets/richText.ets +20 -102
  42. package/dist/components-harmony-ets/scrollList.ets +108 -0
  43. package/dist/components-harmony-ets/scrollView.ets +71 -160
  44. package/dist/components-harmony-ets/slider.ets +22 -82
  45. package/dist/components-harmony-ets/stickySection.ets +42 -0
  46. package/dist/components-harmony-ets/style.ets +410 -0
  47. package/dist/components-harmony-ets/swiper.ets +64 -87
  48. package/dist/components-harmony-ets/switch.ets +39 -99
  49. package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
  50. package/dist/components-harmony-ets/text.ets +111 -113
  51. package/dist/components-harmony-ets/textArea.ets +51 -95
  52. package/dist/components-harmony-ets/utils/AttributeManager.ets +2 -2
  53. package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -2
  54. package/dist/components-harmony-ets/utils/flexManager.ets +50 -19
  55. package/dist/components-harmony-ets/utils/helper.ets +20 -8
  56. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  57. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  58. package/dist/components-harmony-ets/utils/index.ts +54 -50
  59. package/dist/components-harmony-ets/utils/styles.ets +172 -92
  60. package/dist/components-harmony-ets/video.ets +37 -88
  61. package/dist/components-harmony-ets/view.ets +63 -159
  62. package/dist/components-harmony-ets/webView.ets +41 -98
  63. package/dist/index.d.ts +152 -0
  64. package/dist/index.js +187 -56
  65. package/dist/index.js.map +1 -1
  66. package/dist/runtime-ets/bom/document.ts +6 -4
  67. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
  68. package/dist/runtime-ets/bom/window.ts +9 -2
  69. package/dist/runtime-ets/current.ts +5 -1
  70. package/dist/runtime-ets/dom/bind.ts +28 -12
  71. package/dist/runtime-ets/dom/class-list.ts +2 -2
  72. package/dist/runtime-ets/dom/cssNesting.ts +419 -0
  73. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +28 -42
  74. package/dist/runtime-ets/dom/document.ts +22 -8
  75. package/dist/runtime-ets/dom/element/canvas.ts +136 -0
  76. package/dist/runtime-ets/dom/element/element.ts +376 -57
  77. package/dist/runtime-ets/dom/element/form.ts +31 -26
  78. package/dist/runtime-ets/dom/element/index.ts +30 -2
  79. package/dist/runtime-ets/dom/element/movableArea.ts +11 -0
  80. package/dist/runtime-ets/dom/element/movableView.ts +248 -0
  81. package/dist/runtime-ets/dom/element/normal.ts +35 -8
  82. package/dist/runtime-ets/dom/element/progress.ts +11 -0
  83. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  84. package/dist/runtime-ets/dom/element/text.ts +1 -8
  85. package/dist/runtime-ets/dom/element/video.ts +5 -4
  86. package/dist/runtime-ets/dom/element/webView.ts +12 -5
  87. package/dist/runtime-ets/dom/event.ts +3 -5
  88. package/dist/runtime-ets/dom/eventTarget.ts +2 -3
  89. package/dist/runtime-ets/dom/node.ts +65 -32
  90. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +418 -237
  91. package/dist/runtime-ets/dom/stylesheet/index.ts +29 -311
  92. package/dist/runtime-ets/dom/stylesheet/type.ts +53 -11
  93. package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
  94. package/dist/runtime-ets/index.ts +2 -2
  95. package/dist/runtime-ets/interface/event.ts +1 -1
  96. package/dist/runtime-ets/utils/index.ts +74 -13
  97. package/dist/runtime-ets/utils/info.ts +2 -2
  98. package/dist/runtime-framework/react/app.ts +25 -30
  99. package/dist/runtime-framework/react/hooks.ts +3 -4
  100. package/dist/runtime-framework/react/index.ts +0 -2
  101. package/dist/runtime-framework/react/native-page.ts +219 -82
  102. package/dist/runtime-framework/react/page.ts +6 -10
  103. package/dist/runtime-framework/react/utils/index.ts +3 -3
  104. package/dist/runtime-framework/solid/app.ts +30 -46
  105. package/dist/runtime-framework/solid/connect.ts +21 -3
  106. package/dist/runtime-framework/solid/hooks.ts +17 -12
  107. package/dist/runtime-framework/solid/index.ts +6 -2
  108. package/dist/runtime-framework/solid/page.ts +85 -31
  109. package/dist/runtime-framework/solid/reconciler/props.ts +70 -25
  110. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  111. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  112. package/dist/runtime-framework/solid/utils/index.ts +3 -5
  113. package/dist/runtime-utils.d.ts +827 -0
  114. package/dist/runtime-utils.js +618 -245
  115. package/dist/runtime-utils.js.map +1 -1
  116. package/dist/runtime.d.ts +1 -0
  117. package/dist/runtime.js +618 -245
  118. package/dist/runtime.js.map +1 -1
  119. package/index.js +3 -1
  120. package/package.json +14 -15
  121. package/static/media/cancel.svg +1 -1
  122. package/static/media/circle.svg +1 -1
  123. package/static/media/clear.svg +1 -1
  124. package/static/media/download.svg +1 -1
  125. package/static/media/info.svg +1 -1
  126. package/static/media/info_circle.svg +1 -1
  127. package/static/media/search.svg +1 -1
  128. package/static/media/success.svg +1 -1
  129. package/static/media/success_no_circle.svg +1 -1
  130. package/static/media/warn.svg +1 -1
  131. package/types/harmony.d.ts +5 -0
  132. package/types/index.d.ts +4 -0
  133. package/types/runtime.d.ts +3 -1
  134. package/dist/runtime-ets/utils/bind.ts +0 -24
  135. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
@@ -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)
@@ -137,30 +73,43 @@ function getVideoProps (node: TaroVideoElement): VideoAttrs {
137
73
  }
138
74
 
139
75
  function handleUpdate (node: TaroVideoElement, e: VideoUpdateEvent) {
140
- node._currentTime = e.time
76
+ node._nodeInfo._currentTime = e.time
141
77
 
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]
81
+ @Component
82
+ export default struct TaroVideo {
83
+ @Builder customBuilder() {}
84
+ @BuilderParam createLazyChildren: (node: TaroVideoElement, layer?: number) => void = this.customBuilder
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
+ }
93
+
94
+ build () {
95
+ Video(getVideoData(this.node))
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]
164
111
  }))
165
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
112
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
113
+ }
114
+
166
115
  }
@@ -1,169 +1,73 @@
1
1
  import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME } from '@tarojs/runtime'
2
2
 
3
- import { createLazyChildren } from './render'
3
+ import commonStyleModify, { rowModify, columnModify } from './style'
4
+ import PseduoChildren from './pseudo'
4
5
  import { TOUCH_EVENT_MAP } from './utils/constant/event'
5
- import { FlexManager } from './utils/FlexManager'
6
- import { getNodeThresholds, getNormalAttributes, shouldBindEvent } from './utils/helper'
6
+ import { FlexManager } from './utils/flexManager'
7
+ import { getNodeThresholds, shouldBindEvent } from './utils/helper'
7
8
 
8
- import type { TaroViewElement, TaroAny, TaroStyleType } from '@tarojs/runtime'
9
+ import type { TaroViewElement, TaroAny } from '@tarojs/runtime'
10
+ import { isUndefined } from '@tarojs/shared'
9
11
 
10
- @Extend(Column)
11
- function columnAttrs (style: TaroStyleType) {
12
- .id(style.id)
13
- .key(style.id)
14
- .flexGrow(style.flexGrow)
15
- .flexShrink(style.flexShrink)
16
- .flexBasis(style.flexBasis)
17
- .alignSelf(style.alignSelf)
18
- .padding({
19
- top: style.paddingTop,
20
- right: style.paddingRight,
21
- bottom: style.paddingBottom,
22
- left: style.paddingLeft
23
- })
24
- .margin({
25
- top: style.marginTop,
26
- right: style.marginRight,
27
- bottom: style.marginBottom,
28
- left: style.marginLeft
29
- })
30
- .width(style.width)
31
- .height(style.height)
32
- .constraintSize({
33
- minWidth: style.minWidth,
34
- maxWidth: style.maxWidth,
35
- minHeight: style.minHeight,
36
- maxHeight: style.maxHeight
37
- })
38
- .backgroundColor(style.backgroundColor)
39
- .backgroundImage(style.backgroundImage?.src, style.backgroundRepeat)
40
- .backgroundImageSize(style.backgroundSize)
41
- .backgroundImagePosition(style.backgroundPosition)
42
- .borderStyle({
43
- top: style.borderTopStyle,
44
- right: style.borderRightStyle,
45
- bottom: style.borderBottomStyle,
46
- left: style.borderLeftStyle
47
- })
48
- .borderWidth({
49
- top: style.borderTopWidth,
50
- right: style.borderRightWidth,
51
- bottom: style.borderBottomWidth,
52
- left: style.borderLeftWidth
53
- })
54
- .borderColor({
55
- top: style.borderTopColor,
56
- right: style.borderRightColor,
57
- bottom: style.borderBottomColor,
58
- left: style.borderLeftColor
59
- })
60
- .borderRadius({
61
- topLeft: style.borderTopLeftRadius,
62
- topRight: style.borderTopRightRadius,
63
- bottomLeft: style.borderBottomLeftRadius,
64
- bottomRight: style.borderBottomRightRadius
65
- })
66
- .zIndex(style.zIndex)
67
- .opacity(style.opacity)
68
- .linearGradient(style.linearGradient)
69
- .clip(style.overflow)
70
- .rotate({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y, angle: 0 })
71
- .scale({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y })
72
- .transform(style.transform)
73
- }
74
-
75
- @Extend(Row)
76
- function rowAttrs (style: TaroStyleType) {
77
- .id(style.id)
78
- .key(style.id)
79
- .flexGrow(style.flexGrow)
80
- .flexShrink(style.flexShrink)
81
- .flexBasis(style.flexBasis)
82
- .alignSelf(style.alignSelf)
83
- .padding({
84
- top: style.paddingTop,
85
- right: style.paddingRight,
86
- bottom: style.paddingBottom,
87
- left: style.paddingLeft
88
- })
89
- .margin({
90
- top: style.marginTop,
91
- right: style.marginRight,
92
- bottom: style.marginBottom,
93
- left: style.marginLeft
94
- })
95
- .width(style.width)
96
- .height(style.height)
97
- .constraintSize({
98
- minWidth: style.minWidth,
99
- maxWidth: style.maxWidth,
100
- minHeight: style.minHeight,
101
- maxHeight: style.maxHeight
102
- })
103
- .backgroundColor(style.backgroundColor)
104
- .backgroundImage(style.backgroundImage?.src, style.backgroundRepeat)
105
- .backgroundImageSize(style.backgroundSize)
106
- .backgroundImagePosition(style.backgroundPosition)
107
- .borderStyle({
108
- top: style.borderTopStyle,
109
- right: style.borderRightStyle,
110
- bottom: style.borderBottomStyle,
111
- left: style.borderLeftStyle
112
- })
113
- .borderWidth({
114
- top: style.borderTopWidth,
115
- right: style.borderRightWidth,
116
- bottom: style.borderBottomWidth,
117
- left: style.borderLeftWidth
118
- })
119
- .borderColor({
120
- top: style.borderTopColor,
121
- right: style.borderRightColor,
122
- bottom: style.borderBottomColor,
123
- left: style.borderLeftColor
124
- })
125
- .borderRadius({
126
- topLeft: style.borderTopLeftRadius,
127
- topRight: style.borderTopRightRadius,
128
- bottomLeft: style.borderBottomLeftRadius,
129
- bottomRight: style.borderBottomRightRadius
130
- })
131
- .zIndex(style.zIndex)
132
- .opacity(style.opacity)
133
- .linearGradient(style.linearGradient)
134
- .clip(style.overflow)
135
- .rotate({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y, angle: 0 })
136
- .scale({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y })
137
- .transform(style.transform)
138
- }
12
+ @Component
13
+ export default struct TaroView {
14
+ @Builder customBuilder() {}
15
+ @BuilderParam createLazyChildren: (node: TaroViewElement, layer?: number) => void = this.customBuilder
16
+ @ObjectLink node: TaroViewElement
17
+ @State overwriteStyle: Record<string, TaroAny> = {}
139
18
 
140
- @Builder
141
- export default function TaroView (node: TaroViewElement) {
142
- if (FlexManager.isFlexNode(node) && FlexManager.flexOptions(node).direction !== FlexDirection.Column) {
143
- Row() {
144
- createLazyChildren(node)
19
+ aboutToAppear(): void {
20
+ if (this.node) {
21
+ this.node._instance = this
145
22
  }
146
- .rowAttrs(getNormalAttributes(node))
147
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
148
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
149
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
150
- node._nodeInfo.areaInfo = res[1]
151
- }))
152
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
153
- .alignItems(FlexManager.flexOptions(node).alignItems as VerticalAlign)
154
- .justifyContent(FlexManager.flexOptions(node).justifyContent)
155
- } else {
156
- Column() {
157
- createLazyChildren(node)
23
+ }
24
+
25
+ build () {
26
+ if (FlexManager.useFlexLayout(this.node)) {
27
+ Flex(FlexManager.flexOptions(this.node)) {
28
+ if (this.node._pseudo_before || this.node._pseudo_after) {
29
+ PseduoChildren({ node: this.node, createLazyChildren: this.createLazyChildren })
30
+ } else {
31
+ this.createLazyChildren(this.node, 0)
32
+ }
33
+ }
34
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
35
+ .onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', this.node) }, this.node, ['click']))
36
+ .onTouch(shouldBindEvent((e: TouchEvent) => { eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node) }, this.node, TOUCH_EVENT_MAP.values()))
37
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
38
+ this.node._nodeInfo.areaInfo = res[1]
39
+ }))
40
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
41
+ } else if (FlexManager.isFlexNode(this.node) && FlexManager.direction(this.node) !== FlexDirection.Column) {
42
+ Row() {
43
+ if (this.node._pseudo_before || this.node._pseudo_after) {
44
+ PseduoChildren({ node: this.node, createLazyChildren: this.createLazyChildren })
45
+ } else {
46
+ this.createLazyChildren(this.node, 0)
47
+ }
48
+ }
49
+ .attributeModifier(rowModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
50
+ .onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', this.node) }, this.node, ['click']))
51
+ .onTouch(shouldBindEvent((e: TouchEvent) => { eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node) }, this.node, TOUCH_EVENT_MAP.values()))
52
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
53
+ this.node._nodeInfo.areaInfo = res[1]
54
+ }))
55
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
56
+ } else {
57
+ Column() {
58
+ if (this.node._pseudo_before || this.node._pseudo_after) {
59
+ PseduoChildren({ node: this.node, createLazyChildren: this.createLazyChildren })
60
+ } else {
61
+ this.createLazyChildren(this.node, 0)
62
+ }
63
+ }
64
+ .attributeModifier(columnModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
65
+ .onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', this.node) }, this.node, ['click']))
66
+ .onTouch(shouldBindEvent((e: TouchEvent) => { eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node) }, this.node, TOUCH_EVENT_MAP.values()))
67
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
68
+ this.node._nodeInfo.areaInfo = res[1]
69
+ }))
70
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
158
71
  }
159
- .columnAttrs(getNormalAttributes(node))
160
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
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))
166
- .alignItems(FlexManager.flexOptions(node).alignItems as HorizontalAlign)
167
- .justifyContent(FlexManager.flexOptions(node).justifyContent)
168
72
  }
169
73
  }
@@ -1,8 +1,9 @@
1
1
  import { AREA_CHANGE_EVENT_NAME, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
2
2
 
3
- import { getNormalAttributes, shouldBindEvent, getNodeThresholds } from './utils/helper'
3
+ import commonStyleModify from './style'
4
+ import { shouldBindEvent, getNodeThresholds } from './utils/helper'
4
5
 
5
- import type { TaroAny, TaroWebViewElement, TaroStyleType, TaroEvent } from '@tarojs/runtime'
6
+ import type { TaroAny, TaroWebViewElement, TaroEvent } from '@tarojs/runtime'
6
7
 
7
8
  interface IPageLoad {
8
9
  url: string
@@ -13,101 +14,43 @@ interface IError {
13
14
  error: WebResourceError
14
15
  }
15
16
 
16
- @Extend(Web)
17
- function attrs (style: TaroStyleType) {
18
- .id(style.id)
19
- .key(style.id)
20
- .flexGrow(style.flexGrow)
21
- .flexShrink(style.flexShrink)
22
- .flexBasis(style.flexBasis)
23
- .alignSelf(style.alignSelf)
24
- .padding({
25
- top: style.paddingTop,
26
- right: style.paddingRight,
27
- bottom: style.paddingBottom,
28
- left: style.paddingLeft
29
- })
30
- .margin({
31
- top: style.marginTop,
32
- right: style.marginRight,
33
- bottom: style.marginBottom,
34
- left: style.marginLeft
35
- })
36
- .width(style.width)
37
- .height(style.height)
38
- .constraintSize({
39
- minWidth: style.minWidth,
40
- maxWidth: style.maxWidth,
41
- minHeight: style.minHeight,
42
- maxHeight: style.maxHeight
43
- })
44
- .backgroundColor(style.backgroundColor)
45
- .backgroundImage(style.backgroundImage?.src, style.backgroundRepeat)
46
- .backgroundImageSize(style.backgroundSize)
47
- .backgroundImagePosition(style.backgroundPosition)
48
- .borderStyle({
49
- top: style.borderTopStyle,
50
- right: style.borderRightStyle,
51
- bottom: style.borderBottomStyle,
52
- left: style.borderLeftStyle
53
- })
54
- .borderWidth({
55
- top: style.borderTopWidth,
56
- right: style.borderRightWidth,
57
- bottom: style.borderBottomWidth,
58
- left: style.borderLeftWidth
59
- })
60
- .borderColor({
61
- top: style.borderTopColor,
62
- right: style.borderRightColor,
63
- bottom: style.borderBottomColor,
64
- left: style.borderLeftColor
65
- })
66
- .borderRadius({
67
- topLeft: style.borderTopLeftRadius,
68
- topRight: style.borderTopRightRadius,
69
- bottomLeft: style.borderBottomLeftRadius,
70
- bottomRight: style.borderBottomRightRadius
71
- })
72
- .zIndex(style.zIndex)
73
- .opacity(style.opacity)
74
- .clip(style.overflow)
75
- .rotate({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y, angle: 0 })
76
- .scale({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y })
77
- .transform(style.transform)
78
- }
79
-
80
- @Builder
81
- export default function TaroWebView (node: TaroWebViewElement) {
82
- Web({ src: node._attrs.src, controller: node.controller })
83
- .attrs(getNormalAttributes(node))
84
- .onPageEnd((e: IPageLoad) => {
85
- // 1. 创建消息端口
86
- node.ports = node.controller.createWebMessagePorts(true)
87
- // 2. 发送端口1到HTML5
88
- node.controller.postMessage('init_web_messageport', [node.ports[1]], '*');
89
- // 3. 保存端口0到本地
90
- node.nativePort = node.ports[0]
91
- // 4. 设置回调函数
92
- node.nativePort.onMessageEventExt((result) => {
93
- const message = node.handleMessageFromWeb(result)
94
- const messageEvent: TaroEvent = createTaroEvent('message', { detail: { data: message } }, node)
95
-
96
- eventHandler(messageEvent, 'message', node)
17
+ @Component
18
+ export default struct TaroWebView {
19
+ @Builder customBuilder() {}
20
+ @BuilderParam createLazyChildren: (node: TaroWebViewElement, layer?: number) => void = this.customBuilder
21
+ @ObjectLink node: TaroWebViewElement
22
+
23
+ build () {
24
+ Web({ src: this.node._attrs.src, controller: this.node.controller })
25
+ .attributeModifier(commonStyleModify.setNode(this.node))
26
+ .onPageEnd((e: IPageLoad) => {
27
+ // 1. 创建消息端口
28
+ this.node.ports = this.node.controller.createWebMessagePorts(true)
29
+ // 2. 发送端口1到HTML5
30
+ this.node.controller.postMessage('init_web_messageport', [this.node.ports[1]], '*');
31
+ // 3. 保存端口0到本地
32
+ this.node.nativePort = this.node.ports[0]
33
+ // 4. 设置回调函数
34
+ this.node.nativePort.onMessageEventExt((result) => {
35
+ const message = this.node.handleMessageFromWeb(result)
36
+ const messageEvent: TaroEvent = createTaroEvent('message', { detail: { data: message } }, this.node)
37
+
38
+ eventHandler(messageEvent, 'message', this.node)
39
+ })
40
+
41
+ const onLoadEvent: TaroEvent = createTaroEvent('load', { detail: { src: this.node._attrs.src } }, this.node)
42
+
43
+ eventHandler(onLoadEvent, 'load', this.node)
97
44
  })
98
-
99
- const onLoadEvent: TaroEvent = createTaroEvent('load', { detail: { src: node._attrs.src } }, node)
100
-
101
- eventHandler(onLoadEvent, 'load', node)
102
- })
103
- .onErrorReceive(shouldBindEvent((e: IError) => {
104
- const event: TaroEvent = createTaroEvent('error', { detail: { url: node._attrs.src, fullUrl: e.request.getRequestUrl() } }, node)
105
-
106
- eventHandler(event, 'error', node)
107
- }, node, ['error']))
108
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
109
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
110
- node._nodeInfo.areaInfo = res[1]
111
- }))
112
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
45
+ .onErrorReceive(shouldBindEvent((e: IError) => {
46
+ const event: TaroEvent = createTaroEvent('error', { detail: { url: this.node._attrs.src, fullUrl: e.request.getRequestUrl() } }, this.node)
47
+
48
+ eventHandler(event, 'error', this.node)
49
+ }, this.node, ['error']))
50
+ .onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', this.node) }, this.node, ['click']))
51
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
52
+ this.node._nodeInfo.areaInfo = res[1]
53
+ }))
54
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
55
+ }
113
56
  }