@tarojs/plugin-platform-harmony-ets 4.0.0-beta.13 → 4.0.0-beta.131
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/apis/base/system.ts +60 -25
- package/dist/apis/base/weapp/life-cycle.ts +1 -1
- package/dist/apis/canvas/index.ts +10 -1
- package/dist/apis/device/clipboard.ts +23 -8
- package/dist/apis/framework/index.ts +1 -1
- package/dist/apis/index.ts +24 -16
- package/dist/apis/media/image/index.ts +169 -17
- package/dist/apis/network/downloadFile.ts +3 -1
- package/dist/apis/network/uploadFile.ts +3 -1
- package/dist/apis/route/index.ts +1 -2
- package/dist/apis/storage/index.ts +135 -131
- package/dist/apis/ui/animation/animation.ts +71 -29
- package/dist/apis/ui/background.ts +3 -2
- package/dist/apis/ui/interaction/index.ts +58 -59
- package/dist/apis/ui/navigation-bar/index.ts +2 -2
- package/dist/apis/ui/pull-down-refresh.ts +9 -3
- package/dist/apis/ui/scroll/index.ts +5 -5
- package/dist/apis/ui/tab-bar.ts +4 -5
- package/dist/apis/utils/handler.ts +2 -1
- package/dist/apis/utils/index.ts +20 -2
- package/dist/apis/utils/permissions.ts +6 -0
- package/dist/apis/wxml/IntersectionObserver.ts +18 -10
- package/dist/apis/wxml/selectorQuery.ts +26 -13
- package/dist/components-harmony-ets/button.ets +36 -9
- package/dist/components-harmony-ets/canvas.ets +51 -0
- package/dist/components-harmony-ets/checkbox.ets +69 -60
- package/dist/components-harmony-ets/form.ets +33 -15
- package/dist/components-harmony-ets/icon.ets +16 -8
- package/dist/components-harmony-ets/image.ets +22 -6
- package/dist/components-harmony-ets/index.ets +39 -0
- package/dist/components-harmony-ets/innerHtml.ets +6 -5
- package/dist/components-harmony-ets/input.ets +63 -37
- package/dist/components-harmony-ets/label.ets +43 -21
- package/dist/components-harmony-ets/listView.ets +32 -0
- package/dist/components-harmony-ets/movableArea.ets +110 -51
- package/dist/components-harmony-ets/movableView.ets +74 -47
- package/dist/components-harmony-ets/navigationBar.ets +65 -0
- package/dist/components-harmony-ets/pageMeta.ets +94 -0
- package/dist/components-harmony-ets/picker.ets +36 -33
- package/dist/components-harmony-ets/progress.ets +31 -24
- package/dist/components-harmony-ets/pseudo.ets +43 -35
- package/dist/components-harmony-ets/radio.ets +75 -66
- package/dist/components-harmony-ets/richText.ets +4 -25
- package/dist/components-harmony-ets/scrollList.ets +108 -0
- package/dist/components-harmony-ets/scrollView.ets +53 -44
- package/dist/components-harmony-ets/slider.ets +19 -15
- package/dist/components-harmony-ets/stickySection.ets +42 -0
- package/dist/components-harmony-ets/style.ets +274 -38
- package/dist/components-harmony-ets/swiper.ets +42 -5
- package/dist/components-harmony-ets/switch.ets +36 -32
- package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
- package/dist/components-harmony-ets/text.ets +102 -46
- package/dist/components-harmony-ets/textArea.ets +49 -34
- package/dist/components-harmony-ets/utils/AttributeManager.ets +2 -2
- package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -2
- package/dist/components-harmony-ets/utils/flexManager.ets +43 -13
- package/dist/components-harmony-ets/utils/helper.ets +20 -8
- package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
- package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
- package/dist/components-harmony-ets/utils/index.ts +54 -50
- package/dist/components-harmony-ets/utils/styles.ets +165 -104
- package/dist/components-harmony-ets/video.ets +28 -20
- package/dist/components-harmony-ets/view.ets +44 -38
- package/dist/components-harmony-ets/webView.ets +6 -5
- package/dist/index.d.ts +152 -0
- package/dist/index.js +73 -44
- package/dist/index.js.map +1 -1
- package/dist/runtime-ets/bom/URL.ts +2 -0
- package/dist/runtime-ets/bom/document.ts +5 -4
- package/dist/runtime-ets/bom/getComputedStyle.ts +2 -3
- package/dist/runtime-ets/bom/history.ts +1 -0
- package/dist/runtime-ets/bom/location.ts +1 -0
- package/dist/runtime-ets/bom/navigator.ts +1 -21
- package/dist/runtime-ets/bom/raf.ts +1 -37
- package/dist/runtime-ets/bom/window.ts +9 -5
- package/dist/runtime-ets/constant.ts +17 -10
- package/dist/runtime-ets/current.ts +26 -2
- package/dist/runtime-ets/dom/bind.ts +28 -12
- package/dist/runtime-ets/dom/class-list.ts +2 -2
- package/dist/runtime-ets/dom/cssNesting.ts +419 -0
- package/dist/runtime-ets/dom/cssStyleDeclaration.ts +28 -42
- package/dist/runtime-ets/dom/document.ts +9 -12
- package/dist/runtime-ets/dom/element/canvas.ts +137 -0
- package/dist/runtime-ets/dom/element/element.ts +355 -71
- package/dist/runtime-ets/dom/element/form.ts +26 -22
- package/dist/runtime-ets/dom/element/index.ts +22 -2
- package/dist/runtime-ets/dom/element/movableArea.ts +0 -1
- package/dist/runtime-ets/dom/element/movableView.ts +238 -2
- package/dist/runtime-ets/dom/element/normal.ts +27 -6
- package/dist/runtime-ets/dom/element/progress.ts +0 -2
- package/dist/runtime-ets/dom/element/text.ts +0 -8
- package/dist/runtime-ets/dom/element/video.ts +4 -4
- package/dist/runtime-ets/dom/element/webView.ts +4 -5
- package/dist/runtime-ets/dom/event-source.ts +1 -0
- package/dist/runtime-ets/dom/event.ts +3 -5
- package/dist/runtime-ets/dom/eventTarget.ts +3 -4
- package/dist/runtime-ets/dom/node.ts +53 -22
- package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +401 -243
- package/dist/runtime-ets/dom/stylesheet/index.ts +27 -316
- package/dist/runtime-ets/dom/stylesheet/type.ts +52 -11
- package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
- package/dist/runtime-ets/emitter/emitter.ts +1 -0
- package/dist/runtime-ets/env.ts +1 -0
- package/dist/runtime-ets/index.ts +23 -7
- package/dist/runtime-ets/interface/event.ts +1 -1
- package/dist/runtime-ets/interface/index.ts +6 -0
- package/dist/runtime-ets/utils/index.ts +78 -19
- package/dist/runtime-ets/utils/info.ts +2 -2
- package/dist/runtime-ets/utils/router.ts +9 -0
- package/dist/runtime-framework/react/app.ts +10 -10
- package/dist/runtime-framework/react/hooks.ts +1 -2
- package/dist/runtime-framework/react/index.ts +0 -2
- package/dist/runtime-framework/react/native-page.ts +212 -80
- package/dist/runtime-framework/react/page.ts +3 -10
- package/dist/runtime-framework/react/utils/index.ts +3 -3
- package/dist/runtime-framework/solid/app.ts +29 -46
- package/dist/runtime-framework/solid/connect.ts +21 -3
- package/dist/runtime-framework/solid/hooks.ts +16 -11
- package/dist/runtime-framework/solid/index.ts +6 -2
- package/dist/runtime-framework/solid/page.ts +84 -31
- package/dist/runtime-framework/solid/reconciler/props.ts +73 -29
- package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
- package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
- package/dist/runtime-framework/solid/utils/index.ts +3 -5
- package/dist/runtime-utils.d.ts +826 -0
- package/dist/runtime-utils.js +575 -284
- package/dist/runtime-utils.js.map +1 -1
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.js +575 -284
- package/dist/runtime.js.map +1 -1
- package/index.js +3 -1
- package/package.json +14 -15
- package/static/media/cancel.svg +1 -1
- package/static/media/circle.svg +1 -1
- package/static/media/clear.svg +1 -1
- package/static/media/download.svg +1 -1
- package/static/media/info.svg +1 -1
- package/static/media/info_circle.svg +1 -1
- package/static/media/search.svg +1 -1
- package/static/media/success.svg +1 -1
- package/static/media/success_no_circle.svg +1 -1
- package/static/media/warn.svg +1 -1
- package/types/harmony.d.ts +5 -0
- package/types/index.d.ts +4 -0
- package/types/runtime.d.ts +8 -1
- /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
|
@@ -1,68 +1,93 @@
|
|
|
1
|
+
import { isString } from '@tarojs/shared'
|
|
1
2
|
import { eventHandler, convertNumber2VP, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, NodeType } from '@tarojs/runtime'
|
|
2
3
|
|
|
3
|
-
import commonStyleModify from './style'
|
|
4
|
+
import commonStyleModify, { textModify, setNormalTextAttributeIntoInstance } from './style'
|
|
4
5
|
import { getButtonColor } from './button'
|
|
6
|
+
import { getImageMode } from './image'
|
|
5
7
|
import { BUTTON_THEME_COLOR } from './utils/constant/style'
|
|
6
|
-
import { getNodeThresholds,
|
|
8
|
+
import { getNodeThresholds, getStyleAttr, shouldBindEvent, getNormalAttributes } from './utils/helper'
|
|
7
9
|
|
|
8
|
-
import type {
|
|
10
|
+
import type { HarmonyStyle, TaroAny, TaroButtonElement, TaroElement, TaroTextElement } from '@tarojs/runtime'
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
.id(style.id)
|
|
13
|
-
.key(style.id)
|
|
14
|
-
.opacity(style.opacity)
|
|
15
|
-
.fontColor(style.color)
|
|
16
|
-
.fontSize(style.fontSize)
|
|
17
|
-
.fontWeight(style.fontWeight)
|
|
18
|
-
.fontStyle(style.fontStyle)
|
|
19
|
-
.fontFamily(style.fontFamily)
|
|
20
|
-
.lineHeight(style.lineHeight)
|
|
21
|
-
.decoration({
|
|
22
|
-
type: style.textDecoration,
|
|
23
|
-
color: style.color
|
|
24
|
-
})
|
|
25
|
-
}
|
|
12
|
+
function getButtonFontSize (node: TaroButtonElement): string | number {
|
|
13
|
+
const isMini = node._attrs.size === 'mini'
|
|
26
14
|
|
|
27
|
-
|
|
28
|
-
function textSpecialFontStyle(attr: TaroTextStyleType) {
|
|
29
|
-
.textAlign(attr.textAlign)
|
|
30
|
-
.textOverflow(attr.textOverflow)
|
|
31
|
-
.maxLines(attr.WebkitLineClamp)
|
|
32
|
-
.letterSpacing(attr.letterSpacing)
|
|
15
|
+
return isMini ? convertNumber2VP(26) : convertNumber2VP(36)
|
|
33
16
|
}
|
|
34
17
|
|
|
35
|
-
function
|
|
36
|
-
|
|
18
|
+
function getTextInViewWidth (node: TaroElement | null): TaroAny {
|
|
19
|
+
if (node) {
|
|
20
|
+
const hmStyle = node.hmStyle || {}
|
|
21
|
+
const isFlexView = hmStyle.display === 'flex'
|
|
22
|
+
const width: TaroAny = getStyleAttr(node, 'width')
|
|
23
|
+
const isPercentWidth = isString(width) && width.includes('%')
|
|
37
24
|
|
|
38
|
-
|
|
25
|
+
return isFlexView || isPercentWidth ? null : getStyleAttr(node, 'width')
|
|
26
|
+
}
|
|
39
27
|
}
|
|
40
28
|
|
|
29
|
+
|
|
41
30
|
@Component
|
|
42
31
|
export default struct TaroText {
|
|
32
|
+
@Builder customBuilder() {}
|
|
33
|
+
@BuilderParam createLazyChildren: (node: TaroTextElement, layer?: number) => void = this.customBuilder
|
|
43
34
|
@ObjectLink node: TaroTextElement
|
|
35
|
+
@State overwriteStyle: Record<string, TaroAny> = {}
|
|
36
|
+
|
|
37
|
+
aboutToAppear(): void {
|
|
38
|
+
if (this.node) {
|
|
39
|
+
this.node._instance = this
|
|
40
|
+
}
|
|
41
|
+
}
|
|
44
42
|
|
|
45
43
|
build () {
|
|
46
|
-
if (this.node.nodeType === NodeType.TEXT_NODE
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
44
|
+
if (this.node.nodeType === NodeType.TEXT_NODE) {
|
|
45
|
+
if (this.node.parentNode) {
|
|
46
|
+
if ((this.node.parentNode as TaroElement).tagName === 'BUTTON') {
|
|
47
|
+
Text(this.node.textContent)
|
|
48
|
+
.attributeModifier(textModify.setNode(this.node?.parentElement as TaroElement, {
|
|
49
|
+
fontSize: getButtonFontSize(this.node.parentNode as TaroButtonElement),
|
|
50
|
+
color: getButtonColor(this.node.parentNode as TaroButtonElement, BUTTON_THEME_COLOR.get((this.node.parentNode as TaroButtonElement)._attrs.type || '').text)
|
|
51
|
+
}))
|
|
52
|
+
} else {
|
|
53
|
+
Text(this.node.textContent)
|
|
54
|
+
.attributeModifier(textModify.setNode(this.node?.parentElement as TaroElement))
|
|
55
|
+
.width(getTextInViewWidth(this.node.parentElement))
|
|
56
|
+
}
|
|
59
57
|
}
|
|
60
58
|
} else {
|
|
61
|
-
Text(this.node.textContent)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
59
|
+
Text(this.node.textContent) {
|
|
60
|
+
// text 下还有标签
|
|
61
|
+
if (this.node.childNodes.length > 1 || ((this.node.childNodes[0] && this.node.childNodes[0] as TaroElement)?.nodeType === NodeType.ELEMENT_NODE)) {
|
|
62
|
+
ForEach(this.node.childNodes, (item: TaroElement) => {
|
|
63
|
+
if (item.tagName === 'IMAGE') {
|
|
64
|
+
ImageSpan(item.getAttribute('src'))
|
|
65
|
+
.attributeModifier(commonStyleModify.setNode(item))
|
|
66
|
+
.objectFit(getImageMode(item.getAttribute('mode')))
|
|
67
|
+
.verticalAlign(getImageSpanAlignment(this.node?.hmStyle?.verticalAlign))
|
|
68
|
+
.onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', item) }, item, ['click']))
|
|
69
|
+
} else if (item.nodeType === NodeType.TEXT_NODE) {
|
|
70
|
+
Span(item.textContent)
|
|
71
|
+
} else if (item.tagName === 'TEXT') {
|
|
72
|
+
Span(item.textContent)
|
|
73
|
+
.attributeModifier(spanModify.setNode(item))
|
|
74
|
+
.letterSpacing(item._st.hmStyle.letterSpacing)
|
|
75
|
+
.textBackgroundStyle({
|
|
76
|
+
color: item._st.hmStyle.backgroundColor,
|
|
77
|
+
radius: {
|
|
78
|
+
topLeft: item._st.hmStyle.borderTopLeftRadius,
|
|
79
|
+
topRight: item._st.hmStyle.borderTopRightRadius,
|
|
80
|
+
bottomLeft: item._st.hmStyle.borderBottomLeftRadius,
|
|
81
|
+
bottomRight: item._st.hmStyle.borderBottomRightRadius,
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
.onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', item) }, item, ['click']))
|
|
85
|
+
}
|
|
86
|
+
}, (item: TaroElement) => `${item._nid}${this.node._updateTrigger}`)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
.onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', this.node) }, this.node, ['click']))
|
|
90
|
+
.attributeModifier(textModify.setNode(this.node).withNormalStyle().setAnimationStyle(this.overwriteStyle))
|
|
66
91
|
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
67
92
|
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
68
93
|
this.node._nodeInfo.areaInfo = res[1]
|
|
@@ -70,3 +95,34 @@ export default struct TaroText {
|
|
|
70
95
|
}
|
|
71
96
|
}
|
|
72
97
|
}
|
|
98
|
+
|
|
99
|
+
function getImageSpanAlignment (align: TaroAny): TaroAny {
|
|
100
|
+
if (align === Alignment.Top) {
|
|
101
|
+
return ImageSpanAlignment.TOP
|
|
102
|
+
} else if (align === Alignment.Bottom) {
|
|
103
|
+
return ImageSpanAlignment.BOTTOM
|
|
104
|
+
} else if (align === Alignment.Center) {
|
|
105
|
+
return ImageSpanAlignment.CENTER
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
class SpanStyleModify implements AttributeModifier<SpanAttribute> {
|
|
110
|
+
node: TaroTextElement | null = null
|
|
111
|
+
style: HarmonyStyle | null = null
|
|
112
|
+
overwriteStyle: Record<string, TaroAny> = {}
|
|
113
|
+
withNormal = false
|
|
114
|
+
|
|
115
|
+
setNode (node: TaroTextElement) {
|
|
116
|
+
this.node = node
|
|
117
|
+
this.style = getNormalAttributes(this.node)
|
|
118
|
+
return this
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
applyNormalAttribute(instance: SpanAttribute): void {
|
|
122
|
+
if (this.node && this.style) {
|
|
123
|
+
setNormalTextAttributeIntoInstance(instance, this.style, this.node)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const spanModify = new SpanStyleModify()
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
|
|
2
2
|
|
|
3
3
|
import commonStyleModify from './style'
|
|
4
|
-
import { getNodeThresholds,
|
|
4
|
+
import { getNodeThresholds, getFontAttributes, shouldBindEvent, parseStyles } from './utils/helper'
|
|
5
5
|
|
|
6
6
|
import type { TaroAny, TaroStyleType, TaroTextStyleType, TaroTextAreaElement, TaroEvent } from '@tarojs/runtime'
|
|
7
7
|
|
|
8
|
+
interface TextareaAttrs extends TaroTextStyleType {
|
|
9
|
+
autoFocus?: boolean
|
|
10
|
+
disabled?: boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
8
13
|
@Extend(TextArea)
|
|
9
14
|
function textStyle (style: TaroStyleType) {
|
|
10
15
|
.fontColor(style.color)
|
|
@@ -15,9 +20,18 @@ function textStyle (style: TaroStyleType) {
|
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
@Extend(TextArea)
|
|
18
|
-
function textAttr(attr:
|
|
23
|
+
function textAttr(attr: TextareaAttrs) {
|
|
19
24
|
.textAlign(attr.textAlign)
|
|
20
25
|
.maxLines(attr.WebkitLineClamp)
|
|
26
|
+
.defaultFocus(attr.autoFocus)
|
|
27
|
+
.enabled(!attr.disabled)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function getAttributes(node: TaroTextAreaElement): TextareaAttrs {
|
|
31
|
+
const attrs: TaroAny = getFontAttributes(node)
|
|
32
|
+
attrs.autoFocus = node._attrs.autoFocus || node._attrs.focus || false
|
|
33
|
+
attrs.disabled = node._attrs.disabled || false
|
|
34
|
+
return attrs
|
|
21
35
|
}
|
|
22
36
|
|
|
23
37
|
function getPlaceholderColor (node: TaroTextAreaElement): string {
|
|
@@ -30,7 +44,10 @@ function getPlaceholderColor (node: TaroTextAreaElement): string {
|
|
|
30
44
|
export default struct TaroTextArea {
|
|
31
45
|
@State value: string = ''
|
|
32
46
|
|
|
47
|
+
@Builder customBuilder() {}
|
|
48
|
+
@BuilderParam createLazyChildren: (node: TaroTextAreaElement, layer?: number) => void = this.customBuilder
|
|
33
49
|
@ObjectLink node: TaroTextAreaElement
|
|
50
|
+
@State overwriteStyle: Record<string, TaroAny> = {}
|
|
34
51
|
|
|
35
52
|
aboutToAppear () {
|
|
36
53
|
if (this.node) {
|
|
@@ -45,37 +62,35 @@ export default struct TaroTextArea {
|
|
|
45
62
|
}
|
|
46
63
|
|
|
47
64
|
build () {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
79
|
-
}
|
|
65
|
+
TextArea({ text: this.value, placeholder: this.node._attrs?.placeholder || '', controller: this.node.controller })
|
|
66
|
+
.key(this.node._nid.toString())
|
|
67
|
+
.maxLength(Number(this.node._attrs?.maxlength) || null)
|
|
68
|
+
.placeholderColor(getPlaceholderColor(this.node))
|
|
69
|
+
.attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
|
|
70
|
+
.textStyle(this.node?.hmStyle)
|
|
71
|
+
.textAttr(getAttributes(this.node))
|
|
72
|
+
.onChange((value: string) => {
|
|
73
|
+
const event: TaroEvent = createTaroEvent('input', { detail: { value } }, this.node)
|
|
74
|
+
|
|
75
|
+
this.value = value
|
|
76
|
+
this.node?.updateFormWidgetValue(value)
|
|
77
|
+
eventHandler(event, 'input', this.node)
|
|
78
|
+
})
|
|
79
|
+
.onClick(shouldBindEvent((e: ClickEvent) => { eventHandler(e, 'click', this.node) }, this.node, ['click']))
|
|
80
|
+
.onBlur(() => {
|
|
81
|
+
const event: TaroEvent = createTaroEvent('blur', { detail: { value: this.value } }, this.node)
|
|
82
|
+
eventHandler(event, 'blur', this.node)
|
|
83
|
+
})
|
|
84
|
+
.onFocus(() => {
|
|
85
|
+
const event: TaroEvent = createTaroEvent('focus', { detail: { value: this.value, height: this.node?._height } }, this.node)
|
|
86
|
+
|
|
87
|
+
eventHandler(event, 'focus', this.node)
|
|
88
|
+
})
|
|
89
|
+
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
90
|
+
if (this.node) {
|
|
91
|
+
this.node._nodeInfo.areaInfo = res[1]
|
|
92
|
+
}
|
|
93
|
+
}))
|
|
94
|
+
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
80
95
|
}
|
|
81
96
|
}
|
|
@@ -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] }
|
|
@@ -140,7 +140,7 @@ class AttributeManager {
|
|
|
140
140
|
}
|
|
141
141
|
let resultTransform: matrix4.Matrix4Transit
|
|
142
142
|
|
|
143
|
-
const matches = transform.match(new RegExp("/(\w+)\(([^)]+)\)/g")) || [];
|
|
143
|
+
const matches: string[] = transform.match(new RegExp("/(\w+)\(([^)]+)\)/g")) || [];
|
|
144
144
|
|
|
145
145
|
// 处理matrix
|
|
146
146
|
|
|
@@ -11,7 +11,7 @@ export class DynamicCenter {
|
|
|
11
11
|
if (!node._isCompileMode || !node._instance) return
|
|
12
12
|
|
|
13
13
|
if (node._attrs?._dynamicID) {
|
|
14
|
-
node._instance[node._attrs._dynamicID] =
|
|
14
|
+
node._instance[node._attrs._dynamicID] = new TaroElement('Ignore')
|
|
15
15
|
}
|
|
16
16
|
node._instance = null
|
|
17
17
|
}
|
|
@@ -36,4 +36,4 @@ export class DynamicCenter {
|
|
|
36
36
|
this.bindComponentToNodeWithDFS(node.childNodes[i] as TaroElement, component)
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
}
|
|
39
|
+
}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import type { TaroElement } from '@tarojs/runtime'
|
|
1
|
+
import type { TaroElement, HarmonyStyle } from '@tarojs/runtime'
|
|
2
2
|
import { isUndefined } from '@tarojs/shared'
|
|
3
|
+
import { getNormalAttributes } from './styles'
|
|
3
4
|
|
|
4
5
|
interface IFlexOptions {
|
|
5
6
|
direction: FlexDirection,
|
|
6
7
|
justifyContent: FlexAlign,
|
|
7
|
-
alignItems:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// alignContent: FlexAlignContent
|
|
8
|
+
alignItems: ItemAlign,
|
|
9
|
+
wrap?: FlexWrap,
|
|
10
|
+
alignContent?: FlexAlign
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
class FlexManager {
|
|
14
14
|
static isFlexNode (node: TaroElement): boolean {
|
|
15
15
|
return !!node.hmStyle?.display?.includes('flex')
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
static convertFlexAlignItemsToColumnOrRow (direction: FlexDirection, alignItems: ItemAlign | undefined): VerticalAlign | HorizontalAlign {
|
|
19
19
|
if (direction === FlexDirection.Column) {
|
|
20
20
|
switch (alignItems) {
|
|
@@ -37,23 +37,53 @@ class FlexManager {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
static useFlexLayout (node: TaroElement): boolean {
|
|
41
|
+
const hmStyle: HarmonyStyle = getNormalAttributes(node) || {}
|
|
42
|
+
const isReverse = hmStyle.flexDirection && [FlexDirection.RowReverse, FlexDirection.ColumnReverse].indexOf(hmStyle.flexDirection) !== -1;
|
|
43
|
+
const isUnknownAlign = [ItemAlign.Stretch, ItemAlign.Baseline].indexOf(hmStyle.alignItems!) !== -1;
|
|
44
|
+
return !isUndefined(hmStyle.flexWrap) || isReverse || isUnknownAlign;
|
|
45
|
+
}
|
|
46
|
+
|
|
40
47
|
static flexOptions (node: TaroElement): IFlexOptions {
|
|
41
|
-
const hmStyle = node
|
|
48
|
+
const hmStyle: HarmonyStyle = getNormalAttributes(node) || {}
|
|
42
49
|
const isFlex = FlexManager.isFlexNode(node)
|
|
43
|
-
const justifyContent: FlexAlign = isFlex ? (isUndefined(hmStyle.justifyContent) ? FlexAlign.Start : hmStyle.justifyContent) : FlexAlign.Start
|
|
44
|
-
|
|
45
50
|
let flexDirection = hmStyle.flexDirection
|
|
46
51
|
if (!flexDirection && flexDirection !== 0) {
|
|
47
52
|
flexDirection = hmStyle.display === 'flex' ? FlexDirection.Row : FlexDirection.Column
|
|
48
53
|
}
|
|
49
54
|
|
|
50
|
-
const alignItems = isFlex ? FlexManager.convertFlexAlignItemsToColumnOrRow(flexDirection, hmStyle.alignItems) : HorizontalAlign.Start
|
|
51
|
-
|
|
52
55
|
return {
|
|
53
|
-
alignItems,
|
|
54
|
-
justifyContent,
|
|
56
|
+
alignItems: isFlex ? (isUndefined(hmStyle.alignItems) ? ItemAlign.Start : hmStyle.alignItems) : ItemAlign.Start,
|
|
57
|
+
justifyContent: isFlex ? (isUndefined(hmStyle.justifyContent) ? FlexAlign.Start : hmStyle.justifyContent) : FlexAlign.Start,
|
|
55
58
|
direction: flexDirection,
|
|
59
|
+
wrap: isFlex ? hmStyle.flexWrap: FlexWrap.NoWrap,
|
|
60
|
+
alignContent: isFlex ? hmStyle.alignContent: FlexAlign.Start
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
static direction (node: TaroElement): FlexDirection {
|
|
65
|
+
const hmStyle: HarmonyStyle = getNormalAttributes(node)
|
|
66
|
+
let flexDirection = hmStyle.flexDirection
|
|
67
|
+
if (!flexDirection && flexDirection !== 0) {
|
|
68
|
+
flexDirection = hmStyle.display === 'flex' ? FlexDirection.Row : FlexDirection.Column
|
|
56
69
|
}
|
|
70
|
+
return flexDirection
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static alignItems<T> (node: TaroElement): T {
|
|
74
|
+
const hmStyle: HarmonyStyle = getNormalAttributes(node)
|
|
75
|
+
const isFlex = FlexManager.isFlexNode(node)
|
|
76
|
+
let flexDirection = hmStyle.flexDirection
|
|
77
|
+
if (!flexDirection && flexDirection !== 0) {
|
|
78
|
+
flexDirection = hmStyle.display === 'flex' ? FlexDirection.Row : FlexDirection.Column
|
|
79
|
+
}
|
|
80
|
+
return (isFlex ? FlexManager.convertFlexAlignItemsToColumnOrRow(flexDirection, hmStyle.alignItems) : HorizontalAlign.Start) as T
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
static justifyContent (node: TaroElement): FlexAlign {
|
|
84
|
+
const hmStyle: HarmonyStyle = getNormalAttributes(node)
|
|
85
|
+
const isFlex = FlexManager.isFlexNode(node)
|
|
86
|
+
return isFlex ? (isUndefined(hmStyle.justifyContent) ? FlexAlign.Start : hmStyle.justifyContent) : FlexAlign.Start
|
|
57
87
|
}
|
|
58
88
|
}
|
|
59
89
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { VIEW } from '@tarojs/runtime'
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
|
|
3
|
+
import { getNormalAttributes, getFontAttributes, getStyleAttr } from './styles'
|
|
4
|
+
|
|
5
|
+
import type { TaroAny, TaroElement, TaroNode } from '@tarojs/runtime'
|
|
5
6
|
|
|
6
7
|
export const parseStyles = (styles = ''): Record<string, string> => {
|
|
7
8
|
const styleObj: Record<string, string> = {}
|
|
@@ -9,7 +10,7 @@ export const parseStyles = (styles = ''): Record<string, string> => {
|
|
|
9
10
|
.split(';')
|
|
10
11
|
.filter((style) => style.split(':').length === 2)
|
|
11
12
|
.map((style) => [
|
|
12
|
-
style.split(':')[0].trim().replace(new RegExp("
|
|
13
|
+
style.split(':')[0].trim().replace(new RegExp("-([a-z])", "g"), (_, letter: string): string => letter.toUpperCase()),
|
|
13
14
|
style.split(':')[1].trim()
|
|
14
15
|
])
|
|
15
16
|
.forEach((style) => {
|
|
@@ -20,7 +21,7 @@ export const parseStyles = (styles = ''): Record<string, string> => {
|
|
|
20
21
|
return styleObj
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
export function shouldBindEvent (cb:
|
|
24
|
+
export function shouldBindEvent (cb: TaroAny, node: TaroElement | null, eventNames: string[], disabled = false): TaroAny {
|
|
24
25
|
if (!node || node._attrs?.disabled || disabled) return null
|
|
25
26
|
if (!node.__listeners) {
|
|
26
27
|
return null
|
|
@@ -31,9 +32,20 @@ export function shouldBindEvent (cb: TFunc, node: TaroElement | null, eventNames
|
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
export function getNodeThresholds (node: TaroElement): number[] | null {
|
|
34
|
-
|
|
35
|
+
return node?._nodeInfo?.thresholds || null
|
|
36
|
+
}
|
|
35
37
|
|
|
36
|
-
|
|
38
|
+
export function isTagFirstChild (node: TaroElement, tagName = VIEW, level = 0): boolean {
|
|
39
|
+
const parent: TaroElement | null = node.parentElement
|
|
40
|
+
const list: TaroNode[] = node.parentNode?.childNodes || []
|
|
41
|
+
if (list.length < 1 || level < 0) return false
|
|
42
|
+
else if (!parent) return true
|
|
43
|
+
|
|
44
|
+
if (parent.nodeName === tagName.toUpperCase()) {
|
|
45
|
+
return list[0] === node
|
|
46
|
+
} else {
|
|
47
|
+
return (list[0] === node) && isTagFirstChild(parent, tagName, --level)
|
|
48
|
+
}
|
|
37
49
|
}
|
|
38
50
|
|
|
39
|
-
export { getNormalAttributes,
|
|
51
|
+
export { getNormalAttributes, getFontAttributes, getStyleAttr }
|
|
@@ -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+
|
|
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
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
|
69
|
-
|
|
70
|
-
|
|
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
|
}
|