@tarojs/plugin-platform-harmony-ets 4.0.0-beta.17 → 4.0.0-beta.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components-harmony-ets/button.ets +32 -29
- package/dist/components-harmony-ets/checkbox.ets +2 -2
- package/dist/components-harmony-ets/form.ets +28 -25
- package/dist/components-harmony-ets/icon.ets +18 -16
- package/dist/components-harmony-ets/image.ets +13 -11
- package/dist/components-harmony-ets/innerHtml.ets +1 -1
- package/dist/components-harmony-ets/input.ets +1 -1
- package/dist/components-harmony-ets/label.ets +39 -36
- package/dist/components-harmony-ets/movableArea.ets +1 -1
- package/dist/components-harmony-ets/movableView.ets +1 -1
- package/dist/components-harmony-ets/picker.ets +1 -1
- package/dist/components-harmony-ets/progress.ets +1 -1
- package/dist/components-harmony-ets/pseudo.ets +20 -19
- package/dist/components-harmony-ets/radio.ets +2 -2
- package/dist/components-harmony-ets/richText.ets +10 -31
- package/dist/components-harmony-ets/scrollView.ets +54 -43
- package/dist/components-harmony-ets/slider.ets +1 -1
- package/dist/components-harmony-ets/style.ets +40 -6
- package/dist/components-harmony-ets/swiper.ets +19 -17
- package/dist/components-harmony-ets/switch.ets +1 -1
- package/dist/components-harmony-ets/text.ets +13 -10
- package/dist/components-harmony-ets/textArea.ets +1 -1
- package/dist/components-harmony-ets/utils/index.ts +54 -1
- package/dist/components-harmony-ets/utils/styles.ets +8 -2
- package/dist/components-harmony-ets/video.ets +3 -1
- package/dist/components-harmony-ets/view.ets +38 -27
- package/dist/components-harmony-ets/webView.ets +34 -33
- package/dist/index.d.ts +149 -0
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/dist/runtime-ets/dom/cssNesting.ts +24 -37
- package/dist/runtime-ets/dom/element/element.ts +2 -10
- package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +19 -0
- package/dist/runtime-ets/dom/stylesheet/index.ts +13 -0
- package/dist/runtime-ets/dom/stylesheet/type.ts +11 -3
- package/dist/runtime-ets/dom/stylesheet/util.ts +17 -10
- package/dist/runtime-utils.d.ts +825 -0
- package/dist/runtime.d.ts +1 -0
- package/index.js +3 -1
- package/package.json +8 -8
- package/types/index.d.ts +4 -0
|
@@ -2,6 +2,7 @@ import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBL
|
|
|
2
2
|
|
|
3
3
|
import commonStyleModify from './style'
|
|
4
4
|
import PseduoChildren from './pseudo'
|
|
5
|
+
import { createLazyChildren } from './render'
|
|
5
6
|
import { FlexManager } from './utils/FlexManager'
|
|
6
7
|
import { TOUCH_EVENT_MAP } from './utils/constant/event'
|
|
7
8
|
import { getNodeThresholds, getNormalAttributes, shouldBindEvent } from './utils/helper'
|
|
@@ -82,51 +83,61 @@ export default struct TaroScrollView {
|
|
|
82
83
|
@ObjectLink node: TaroScrollViewElement
|
|
83
84
|
|
|
84
85
|
build () {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
if (this.node.hmStyle?.display !== 'none') {
|
|
87
|
+
Scroll(this.node.scroller) {
|
|
88
|
+
if (this.node._attrs.scrollX) {
|
|
89
|
+
Row() {
|
|
90
|
+
if (this.node._pseudo_before || this.node._pseudo_after) {
|
|
91
|
+
PseduoChildren(this.node)
|
|
92
|
+
} else {
|
|
93
|
+
createLazyChildren(this.node)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
.attributeModifier(commonStyleModify.setNode(this.node))
|
|
97
|
+
.rowAttrs(getNormalAttributes(this.node))
|
|
98
|
+
.width(null)
|
|
99
|
+
.onAreaChange(shouldBindEvent((_: Area, areaResult: Area) => {
|
|
100
|
+
this.node._nodeInfo._scroll = areaResult
|
|
101
|
+
}, this.node, ['scroll', 'scrollstart', 'scrollend']))
|
|
102
|
+
.alignItems(FlexManager.flexOptions(this.node).alignItems as VerticalAlign)
|
|
103
|
+
.justifyContent(FlexManager.flexOptions(this.node).justifyContent)
|
|
104
|
+
.flexGrow(0).flexShrink(0)
|
|
105
|
+
} else {
|
|
106
|
+
Column() {
|
|
107
|
+
if (this.node._pseudo_before || this.node._pseudo_after) {
|
|
108
|
+
PseduoChildren(this.node)
|
|
109
|
+
} else {
|
|
110
|
+
createLazyChildren(this.node)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
.attributeModifier(commonStyleModify.setNode(this.node))
|
|
114
|
+
.columnAttrs(getNormalAttributes(this.node))
|
|
115
|
+
.height(null)
|
|
116
|
+
.alignItems(HorizontalAlign.Start)
|
|
117
|
+
.onAreaChange(shouldBindEvent((_: Area, areaResult: Area) => {
|
|
118
|
+
this.node._nodeInfo._scroll = areaResult
|
|
119
|
+
}, this.node, ['scroll', 'scrollstart', 'scrollend']))
|
|
120
|
+
.alignItems(FlexManager.flexOptions(this.node).alignItems as HorizontalAlign)
|
|
121
|
+
.justifyContent(FlexManager.flexOptions(this.node).justifyContent)
|
|
122
|
+
.flexGrow(0).flexShrink(0)
|
|
89
123
|
}
|
|
90
|
-
.attributeModifier(commonStyleModify.setNode(this.node))
|
|
91
|
-
.rowAttrs(getNormalAttributes(this.node))
|
|
92
|
-
.width(null)
|
|
93
|
-
.onAreaChange(shouldBindEvent((_: Area, areaResult: Area) => {
|
|
94
|
-
this.node._nodeInfo._scroll = areaResult
|
|
95
|
-
}, this.node, ['scroll', 'scrollstart', 'scrollend']))
|
|
96
|
-
.alignItems(FlexManager.flexOptions(this.node).alignItems as VerticalAlign)
|
|
97
|
-
.justifyContent(FlexManager.flexOptions(this.node).justifyContent)
|
|
98
|
-
.flexGrow(0).flexShrink(0)
|
|
99
|
-
} else {
|
|
100
|
-
Column() {
|
|
101
|
-
PseduoChildren(this.node)
|
|
102
|
-
}
|
|
103
|
-
.attributeModifier(commonStyleModify.setNode(this.node))
|
|
104
|
-
.columnAttrs(getNormalAttributes(this.node))
|
|
105
|
-
.height(null)
|
|
106
|
-
.alignItems(HorizontalAlign.Start)
|
|
107
|
-
.onAreaChange(shouldBindEvent((_: Area, areaResult: Area) => {
|
|
108
|
-
this.node._nodeInfo._scroll = areaResult
|
|
109
|
-
}, this.node, ['scroll', 'scrollstart', 'scrollend']))
|
|
110
|
-
.alignItems(FlexManager.flexOptions(this.node).alignItems as HorizontalAlign)
|
|
111
|
-
.justifyContent(FlexManager.flexOptions(this.node).justifyContent)
|
|
112
|
-
.flexGrow(0).flexShrink(0)
|
|
113
124
|
}
|
|
125
|
+
.width(getNormalAttributes(this.node).width)
|
|
126
|
+
.height(getNormalAttributes(this.node).height)
|
|
127
|
+
.flexGrow(getNormalAttributes(this.node).flexGrow)
|
|
128
|
+
.flexShrink(getNormalAttributes(this.node).flexShrink)
|
|
129
|
+
.scrollable(getScrollable(this.node))
|
|
130
|
+
.scrollBar(getAttributes(this.node).scrollBar)
|
|
131
|
+
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
|
|
132
|
+
.onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
|
|
133
|
+
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
134
|
+
this.node._nodeInfo.areaInfo = res[1]
|
|
135
|
+
}))
|
|
136
|
+
.onScroll(shouldBindEvent(() => { handleScrollEvent(this.node, 'scroll') }, this.node, ['scroll']))
|
|
137
|
+
.onScrollStart(shouldBindEvent(() => { handleScrollEvent(this.node, 'scrollstart') }, this.node, ['scrollstart']))
|
|
138
|
+
.onScrollStop(shouldBindEvent(() => { handleScrollEvent(this.node, 'scrollend') }, this.node, ['scrollend']))
|
|
139
|
+
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
140
|
+
.onReachEnd(shouldBindEvent(() => { handleScrollEvent(this.node, 'scrolltolower') }, this.node, ['scrolltolower']))
|
|
114
141
|
}
|
|
115
|
-
.width(getNormalAttributes(this.node).width)
|
|
116
|
-
.height(getNormalAttributes(this.node).height)
|
|
117
|
-
.flexGrow(getNormalAttributes(this.node).flexGrow)
|
|
118
|
-
.flexShrink(getNormalAttributes(this.node).flexShrink)
|
|
119
|
-
.scrollable(getScrollable(this.node))
|
|
120
|
-
.scrollBar(getAttributes(this.node).scrollBar)
|
|
121
|
-
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
|
|
122
|
-
.onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
|
|
123
|
-
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
124
|
-
this.node._nodeInfo.areaInfo = res[1]
|
|
125
|
-
}))
|
|
126
|
-
.onScroll(shouldBindEvent(() => { handleScrollEvent(this.node, 'scroll') }, this.node, ['scroll']))
|
|
127
|
-
.onScrollStart(shouldBindEvent(() => { handleScrollEvent(this.node, 'scrollstart') }, this.node, ['scrollstart']))
|
|
128
|
-
.onScrollStop(shouldBindEvent(() => { handleScrollEvent(this.node, 'scrollend') }, this.node, ['scrollend']))
|
|
129
|
-
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
130
|
-
.onReachEnd(shouldBindEvent(() => { handleScrollEvent(this.node, 'scrolltolower') }, this.node, ['scrolltolower']))
|
|
131
142
|
}
|
|
132
143
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { HarmonyStyle, TaroElement, TaroStyleType } from '@tarojs/runtime'
|
|
2
2
|
import { isUndefined } from '../shared'
|
|
3
|
+
import { computeBackgroundPosition } from './utils'
|
|
3
4
|
import { getNormalAttributes, getStyle } from './utils/helper'
|
|
4
5
|
|
|
5
6
|
function getTop (node: TaroElement): Length | number {
|
|
@@ -101,7 +102,15 @@ function setNormalAttributeIntoInstance(instance: CommonAttribute, style: TaroSt
|
|
|
101
102
|
instance.backgroundImageSize(style.backgroundSize)
|
|
102
103
|
}
|
|
103
104
|
if (!isUndefined(style.backgroundPosition)) {
|
|
104
|
-
|
|
105
|
+
if (typeof style.backgroundPosition !== 'number') {
|
|
106
|
+
let pos = computeBackgroundPosition(style)
|
|
107
|
+
instance.backgroundImagePosition({
|
|
108
|
+
x: pos.offsetX,
|
|
109
|
+
y: pos.offsetY,
|
|
110
|
+
})
|
|
111
|
+
} else {
|
|
112
|
+
instance.backgroundImagePosition(style.backgroundPosition)
|
|
113
|
+
}
|
|
105
114
|
}
|
|
106
115
|
if (!isUndefined(style.borderTopStyle) || !isUndefined(style.borderRightStyle) || !isUndefined(style.borderBottomStyle) || !isUndefined(style.borderLeftStyle)) {
|
|
107
116
|
instance.borderStyle({
|
|
@@ -147,12 +156,37 @@ function setNormalAttributeIntoInstance(instance: CommonAttribute, style: TaroSt
|
|
|
147
156
|
if (!isUndefined(style.overflow)) {
|
|
148
157
|
instance.clip(style.overflow)
|
|
149
158
|
}
|
|
150
|
-
if (!isUndefined(style.transformOrigin)) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
159
|
+
// if (!isUndefined(style.transformOrigin)) {
|
|
160
|
+
// instance.rotate({ centerX: style.transformOrigin.x, centerY: style.transformOrigin.y, angle: 0 })
|
|
161
|
+
// instance.scale({ centerX: style.transformOrigin.x, centerY: style.transformOrigin.y })
|
|
162
|
+
// }
|
|
154
163
|
if (!isUndefined(style.transform)) {
|
|
155
|
-
|
|
164
|
+
if (style.transform.Translate) {
|
|
165
|
+
instance.translate({
|
|
166
|
+
x: style.transform.Translate.x || 0,
|
|
167
|
+
y: style.transform.Translate.y || 0,
|
|
168
|
+
z: style.transform.Translate.z || 0,
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
if (style.transform.Scale) {
|
|
172
|
+
instance.scale({
|
|
173
|
+
x: style.transform.Scale.x || 0,
|
|
174
|
+
y: style.transform.Scale.y || 0,
|
|
175
|
+
z: style.transform.Scale.z || 0,
|
|
176
|
+
centerX: style.transformOrigin?.x,
|
|
177
|
+
centerY: style.transformOrigin?.y,
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
if (style.transform.Rotate) {
|
|
181
|
+
instance.rotate({
|
|
182
|
+
x: style.transform.Rotate.x || 0,
|
|
183
|
+
y: style.transform.Rotate.y || 0,
|
|
184
|
+
z: style.transform.Rotate.z || 0,
|
|
185
|
+
centerX: style.transformOrigin?.x,
|
|
186
|
+
centerY: style.transformOrigin?.y,
|
|
187
|
+
angle: 0
|
|
188
|
+
})
|
|
189
|
+
}
|
|
156
190
|
}
|
|
157
191
|
if (style.position === 'absolute' || style.position === 'fixed') {
|
|
158
192
|
instance.position({
|
|
@@ -45,23 +45,25 @@ export default struct TaroSwiper {
|
|
|
45
45
|
@ObjectLink node: TaroSwiperElement
|
|
46
46
|
|
|
47
47
|
build () {
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
if (this.node.hmStyle?.display !== 'none') {
|
|
49
|
+
Swiper(this.node.controller) {
|
|
50
|
+
createLazyChildren(this.node)
|
|
51
|
+
}
|
|
52
|
+
.attributeModifier(commonStyleModify.setNode(this.node))
|
|
53
|
+
.swiperAttr(getSwiperAttributes(this.node))
|
|
54
|
+
.indicatorStyle({
|
|
55
|
+
color: this.node.getAttribute('indicatorColor'),
|
|
56
|
+
selectedColor: this.node.getAttribute('indicatorActiveColor')
|
|
57
|
+
})
|
|
58
|
+
.onChange((index: number) => {
|
|
59
|
+
const event: TaroEvent = createTaroEvent('change', { detail: { current: index } }, this.node)
|
|
60
|
+
eventHandler(event, 'change', this.node)
|
|
61
|
+
})
|
|
62
|
+
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
|
|
63
|
+
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
64
|
+
this.node._nodeInfo.areaInfo = res[1]
|
|
65
|
+
}))
|
|
66
|
+
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
50
67
|
}
|
|
51
|
-
.attributeModifier(commonStyleModify.setNode(this.node))
|
|
52
|
-
.swiperAttr(getSwiperAttributes(this.node))
|
|
53
|
-
.indicatorStyle({
|
|
54
|
-
color: this.node.getAttribute('indicatorColor'),
|
|
55
|
-
selectedColor: this.node.getAttribute('indicatorActiveColor')
|
|
56
|
-
})
|
|
57
|
-
.onChange((index: number) => {
|
|
58
|
-
const event: TaroEvent = createTaroEvent('change', { detail: { current: index } }, this.node)
|
|
59
|
-
eventHandler(event, 'change', this.node)
|
|
60
|
-
})
|
|
61
|
-
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
|
|
62
|
-
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
63
|
-
this.node._nodeInfo.areaInfo = res[1]
|
|
64
|
-
}))
|
|
65
|
-
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
66
68
|
}
|
|
67
69
|
}
|
|
@@ -38,7 +38,7 @@ export default struct TaroSwitch {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
build () {
|
|
41
|
-
if (this.node) {
|
|
41
|
+
if (this.node && this.node.hmStyle?.display !== 'none') {
|
|
42
42
|
Toggle({
|
|
43
43
|
type: this.node._attrs.type !== 'checkbox' ? ToggleType.Switch : ToggleType.Checkbox,
|
|
44
44
|
isOn: this.node.checked,
|
|
@@ -17,7 +17,6 @@ function textNormalFontStyle (style: TaroStyleType) {
|
|
|
17
17
|
.fontWeight(style.fontWeight)
|
|
18
18
|
.fontStyle(style.fontStyle)
|
|
19
19
|
.fontFamily(style.fontFamily)
|
|
20
|
-
.lineHeight(style.lineHeight)
|
|
21
20
|
.decoration({
|
|
22
21
|
type: style.textDecoration,
|
|
23
22
|
color: style.color
|
|
@@ -27,9 +26,11 @@ function textNormalFontStyle (style: TaroStyleType) {
|
|
|
27
26
|
@Extend(Text)
|
|
28
27
|
function textSpecialFontStyle(attr: TaroTextStyleType) {
|
|
29
28
|
.textAlign(attr.textAlign)
|
|
29
|
+
.align(attr.verticalAlign)
|
|
30
30
|
.textOverflow(attr.textOverflow)
|
|
31
31
|
.maxLines(attr.WebkitLineClamp)
|
|
32
32
|
.letterSpacing(attr.letterSpacing)
|
|
33
|
+
.lineHeight(attr.lineHeight)
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
function getButtonFontSize (node: TaroButtonElement) {
|
|
@@ -60,15 +61,17 @@ export default struct TaroText {
|
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
} else {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
this.node
|
|
71
|
-
|
|
64
|
+
if (this.node.hmStyle?.display !== 'none') {
|
|
65
|
+
Text(this.node.textContent)
|
|
66
|
+
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
|
|
67
|
+
.attributeModifier(commonStyleModify.setNode(this.node))
|
|
68
|
+
.textNormalFontStyle(getNormalAttributes(this.node))
|
|
69
|
+
.textSpecialFontStyle(getFontAttributes(this.node))
|
|
70
|
+
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
71
|
+
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
72
|
+
this.node._nodeInfo.areaInfo = res[1]
|
|
73
|
+
}))
|
|
74
|
+
}
|
|
72
75
|
}
|
|
73
76
|
}
|
|
74
77
|
}
|
|
@@ -45,7 +45,7 @@ export default struct TaroTextArea {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
build () {
|
|
48
|
-
if (this.node) {
|
|
48
|
+
if (this.node && this.node.hmStyle?.display !== 'none') {
|
|
49
49
|
TextArea({ text: this.value, placeholder: this.node._attrs?.placeholder || '', controller: this.node.controller })
|
|
50
50
|
.key(this.node._nid)
|
|
51
51
|
.maxLength(Number(this.node._attrs?.maxlength) || null)
|
|
@@ -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])
|
|
@@ -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
|
+
}
|
|
@@ -13,12 +13,19 @@ export function getFontAttributes (node: TaroElement): TaroTextStyleType {
|
|
|
13
13
|
|
|
14
14
|
if (!hmStyle) return {}
|
|
15
15
|
|
|
16
|
+
let lineHeight = hmStyle.lineHeight
|
|
17
|
+
if (!isUndefined(hmStyle.verticalAlign)) {
|
|
18
|
+
lineHeight = 0
|
|
19
|
+
}
|
|
20
|
+
|
|
16
21
|
const attributes: TaroAny = {
|
|
17
22
|
WebkitLineClamp: attrs.maxLines || hmStyle.WebkitLineClamp || Infinity,
|
|
18
23
|
// 已做处理的属性
|
|
19
24
|
letterSpacing: hmStyle.letterSpacing,
|
|
20
25
|
textAlign: hmStyle.textAlign,
|
|
21
|
-
textOverflow: hmStyle.textOverflow
|
|
26
|
+
textOverflow: hmStyle.textOverflow,
|
|
27
|
+
verticalAlign: hmStyle.verticalAlign,
|
|
28
|
+
lineHeight: lineHeight
|
|
22
29
|
}
|
|
23
30
|
|
|
24
31
|
return attributes
|
|
@@ -131,7 +138,6 @@ export function getStyle(hmStyle: HarmonyStyle): TaroStyleType {
|
|
|
131
138
|
fontStyle: hmStyle.fontStyle,
|
|
132
139
|
fontWeight: hmStyle.fontWeight,
|
|
133
140
|
fontFamily: hmStyle.fontFamily || TEXT_DEFAULT_STYLE.FONT_FAMILY,
|
|
134
|
-
lineHeight: hmStyle.lineHeight,
|
|
135
141
|
textDecoration: hmStyle.textDecoration,
|
|
136
142
|
// 其他
|
|
137
143
|
overflow: hmStyle.overflow,
|
|
@@ -83,7 +83,8 @@ export default struct TaroVideo {
|
|
|
83
83
|
@ObjectLink node: TaroVideoElement
|
|
84
84
|
|
|
85
85
|
build () {
|
|
86
|
-
|
|
86
|
+
if (this.node.hmStyle?.display !== 'none') {
|
|
87
|
+
Video(getVideoData(this.node))
|
|
87
88
|
.attributeModifier(commonStyleModify.setNode(this.node))
|
|
88
89
|
.props(getVideoProps(this.node))
|
|
89
90
|
.aspectRatio(4 / 3)
|
|
@@ -102,6 +103,7 @@ export default struct TaroVideo {
|
|
|
102
103
|
this.node._nodeInfo.areaInfo = res[1]
|
|
103
104
|
}))
|
|
104
105
|
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
106
|
+
}
|
|
105
107
|
}
|
|
106
108
|
|
|
107
109
|
}
|
|
@@ -2,6 +2,7 @@ import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBL
|
|
|
2
2
|
|
|
3
3
|
import commonStyleModify from './style'
|
|
4
4
|
import PseduoChildren from './pseudo'
|
|
5
|
+
import { createLazyChildren } from './render'
|
|
5
6
|
import { TOUCH_EVENT_MAP } from './utils/constant/event'
|
|
6
7
|
import { FlexManager } from './utils/flexManager'
|
|
7
8
|
import { getNodeThresholds, getNormalAttributes, shouldBindEvent } from './utils/helper'
|
|
@@ -33,34 +34,44 @@ export default struct TaroView {
|
|
|
33
34
|
@ObjectLink node: TaroViewElement
|
|
34
35
|
|
|
35
36
|
build () {
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
if (this.node.hmStyle?.display !== 'none') {
|
|
38
|
+
if (FlexManager.isFlexNode(this.node) && FlexManager.flexOptions(this.node).direction !== FlexDirection.Column) {
|
|
39
|
+
Row() {
|
|
40
|
+
if (this.node._pseudo_before || this.node._pseudo_after) {
|
|
41
|
+
PseduoChildren(this.node)
|
|
42
|
+
} else {
|
|
43
|
+
createLazyChildren(this.node)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
.attributeModifier(commonStyleModify.setNode(this.node))
|
|
47
|
+
.rowAttrs(getNormalAttributes(this.node))
|
|
48
|
+
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
|
|
49
|
+
.onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
|
|
50
|
+
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
51
|
+
this.node._nodeInfo.areaInfo = res[1]
|
|
52
|
+
}))
|
|
53
|
+
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
54
|
+
.alignItems(FlexManager.flexOptions(this.node).alignItems as VerticalAlign)
|
|
55
|
+
.justifyContent(FlexManager.flexOptions(this.node).justifyContent)
|
|
56
|
+
} else {
|
|
57
|
+
Column() {
|
|
58
|
+
if (this.node._pseudo_before || this.node._pseudo_after) {
|
|
59
|
+
PseduoChildren(this.node)
|
|
60
|
+
} else {
|
|
61
|
+
createLazyChildren(this.node)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
.attributeModifier(commonStyleModify.setNode(this.node))
|
|
65
|
+
.columnAttrs(getNormalAttributes(this.node))
|
|
66
|
+
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
|
|
67
|
+
.onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
|
|
68
|
+
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
69
|
+
this.node._nodeInfo.areaInfo = res[1]
|
|
70
|
+
}))
|
|
71
|
+
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
72
|
+
.alignItems(FlexManager.flexOptions(this.node).alignItems as HorizontalAlign)
|
|
73
|
+
.justifyContent(FlexManager.flexOptions(this.node).justifyContent)
|
|
39
74
|
}
|
|
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()))
|
|
44
|
-
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
45
|
-
this.node._nodeInfo.areaInfo = res[1]
|
|
46
|
-
}))
|
|
47
|
-
.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
|
-
} else {
|
|
51
|
-
Column() {
|
|
52
|
-
PseduoChildren(this.node)
|
|
53
|
-
}
|
|
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()))
|
|
58
|
-
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
59
|
-
this.node._nodeInfo.areaInfo = res[1]
|
|
60
|
-
}))
|
|
61
|
-
.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
75
|
}
|
|
65
76
|
}
|
|
66
77
|
}
|
|
@@ -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 {
|
|
4
|
+
import { shouldBindEvent, getNodeThresholds } from './utils/helper'
|
|
5
5
|
|
|
6
|
-
import type { TaroAny, TaroWebViewElement,
|
|
6
|
+
import type { TaroAny, TaroWebViewElement, TaroEvent } from '@tarojs/runtime'
|
|
7
7
|
|
|
8
8
|
interface IPageLoad {
|
|
9
9
|
url: string
|
|
@@ -19,37 +19,38 @@ export default struct TaroWebView {
|
|
|
19
19
|
@ObjectLink node: TaroWebViewElement
|
|
20
20
|
|
|
21
21
|
build () {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
22
|
+
if (this.node.hmStyle?.display !== 'none') {
|
|
23
|
+
Web({ src: this.node._attrs.src, controller: this.node.controller })
|
|
24
|
+
.attributeModifier(commonStyleModify.setNode(this.node))
|
|
25
|
+
.onPageEnd((e: IPageLoad) => {
|
|
26
|
+
// 1. 创建消息端口
|
|
27
|
+
this.node.ports = this.node.controller.createWebMessagePorts(true)
|
|
28
|
+
// 2. 发送端口1到HTML5
|
|
29
|
+
this.node.controller.postMessage('init_web_messageport', [this.node.ports[1]], '*');
|
|
30
|
+
// 3. 保存端口0到本地
|
|
31
|
+
this.node.nativePort = this.node.ports[0]
|
|
32
|
+
// 4. 设置回调函数
|
|
33
|
+
this.node.nativePort.onMessageEventExt((result) => {
|
|
34
|
+
const message = this.node.handleMessageFromWeb(result)
|
|
35
|
+
const messageEvent: TaroEvent = createTaroEvent('message', { detail: { data: message } }, this.node)
|
|
36
|
+
|
|
37
|
+
eventHandler(messageEvent, 'message', this.node)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
const onLoadEvent: TaroEvent = createTaroEvent('load', { detail: { src: this.node._attrs.src } }, this.node)
|
|
41
|
+
|
|
42
|
+
eventHandler(onLoadEvent, 'load', this.node)
|
|
37
43
|
})
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
50
|
-
this.node._nodeInfo.areaInfo = res[1]
|
|
51
|
-
}))
|
|
52
|
-
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
53
|
-
|
|
44
|
+
.onErrorReceive(shouldBindEvent((e: IError) => {
|
|
45
|
+
const event: TaroEvent = createTaroEvent('error', { detail: { url: this.node._attrs.src, fullUrl: e.request.getRequestUrl() } }, this.node)
|
|
46
|
+
|
|
47
|
+
eventHandler(event, 'error', this.node)
|
|
48
|
+
}, this.node, ['error']))
|
|
49
|
+
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
|
|
50
|
+
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
51
|
+
this.node._nodeInfo.areaInfo = res[1]
|
|
52
|
+
}))
|
|
53
|
+
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
54
|
+
}
|
|
54
55
|
}
|
|
55
56
|
}
|