@tarojs/plugin-platform-harmony-ets 4.0.0-beta.14 → 4.0.0-beta.16
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/movableArea.ets +53 -8
- package/dist/components-harmony-ets/movableView.ets +54 -30
- package/dist/components-harmony-ets/text.ets +15 -13
- package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
- package/dist/components-harmony-ets/utils/index.ts +1 -1
- package/dist/components-harmony-ets/utils/styles.ets +4 -0
- package/dist/runtime-ets/dom/cssNesting.ts +214 -0
- package/dist/runtime-ets/dom/element/index.ts +3 -0
- package/dist/runtime-ets/dom/element/movableView.ts +184 -2
- package/dist/runtime-ets/dom/stylesheet/util.ts +1 -1
- package/dist/runtime-ets/index.ts +1 -0
- package/package.json +8 -8
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TaroMovableAreaElement, TaroStyleType } from '@tarojs/runtime'
|
|
1
|
+
import type { TaroMovableAreaElement, TaroStyleType, TaroMovableViewElement} from '@tarojs/runtime'
|
|
2
2
|
import commonStyleModify from './style'
|
|
3
3
|
import { createLazyChildren } from './render'
|
|
4
4
|
|
|
@@ -30,9 +30,6 @@ function columnAttrs(style: TaroStyleType) {
|
|
|
30
30
|
export default struct TaroMovableArea {
|
|
31
31
|
@ObjectLink node: TaroMovableAreaElement
|
|
32
32
|
|
|
33
|
-
@Provide areaWidth: Length = 0
|
|
34
|
-
@Provide areaHeight: Length = 0
|
|
35
|
-
|
|
36
33
|
build() {
|
|
37
34
|
if (this.node) {
|
|
38
35
|
if (FlexManager.isFlexNode(this.node) && FlexManager.flexOptions(this.node).direction !== FlexDirection.Column) {
|
|
@@ -45,9 +42,33 @@ export default struct TaroMovableArea {
|
|
|
45
42
|
.justifyContent(FlexManager.flexOptions(this.node).justifyContent)
|
|
46
43
|
.clip(true)
|
|
47
44
|
.onAreaChange((oldValue: Area, newValue: Area) => {
|
|
48
|
-
this.
|
|
49
|
-
|
|
45
|
+
this.node.childNodes.forEach(item => {
|
|
46
|
+
if(item.nodeName === 'MOVABLE-VIEW') {
|
|
47
|
+
;(item as TaroMovableViewElement).area = {
|
|
48
|
+
w: Number( newValue.width),
|
|
49
|
+
h: Number(newValue.height)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
})
|
|
50
53
|
})
|
|
54
|
+
.gesture(
|
|
55
|
+
PinchGesture({ fingers: 2 }).onActionStart((event: GestureEvent) => {
|
|
56
|
+
this.node.childNodes.forEach(item => {
|
|
57
|
+
if(item.nodeName === 'MOVABLE-VIEW') {
|
|
58
|
+
;(item as TaroMovableViewElement).startScale()
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
}).onActionUpdate((event) => {
|
|
62
|
+
const scaleArea = this.node.getAttribute('scaleArea')
|
|
63
|
+
if (scaleArea) {
|
|
64
|
+
this.node.childNodes.forEach(item => {
|
|
65
|
+
if(item.nodeName === 'MOVABLE-VIEW') {
|
|
66
|
+
;(item as TaroMovableViewElement).doScale(event.scale)
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
)
|
|
51
72
|
} else {
|
|
52
73
|
Column() {
|
|
53
74
|
createLazyChildren(this.node)
|
|
@@ -58,9 +79,33 @@ export default struct TaroMovableArea {
|
|
|
58
79
|
.justifyContent(FlexManager.flexOptions(this.node).justifyContent)
|
|
59
80
|
.clip(true)
|
|
60
81
|
.onAreaChange((oldValue: Area, newValue: Area) => {
|
|
61
|
-
this.
|
|
62
|
-
|
|
82
|
+
this.node.childNodes.forEach(item => {
|
|
83
|
+
if(item.nodeName === 'MOVABLE-VIEW') {
|
|
84
|
+
;(item as TaroMovableViewElement).area = {
|
|
85
|
+
w: Number( newValue.width),
|
|
86
|
+
h: Number(newValue.height)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
})
|
|
63
90
|
})
|
|
91
|
+
.gesture(
|
|
92
|
+
PinchGesture({ fingers: 2 }).onActionStart((event: GestureEvent) => {
|
|
93
|
+
this.node.childNodes.forEach(item => {
|
|
94
|
+
if(item.nodeName === 'MOVABLE-VIEW') {
|
|
95
|
+
;(item as TaroMovableViewElement).startScale()
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
}).onActionUpdate((event) => {
|
|
99
|
+
const scaleArea = this.node.getAttribute('scaleArea')
|
|
100
|
+
if (scaleArea) {
|
|
101
|
+
this.node.childNodes.forEach(item => {
|
|
102
|
+
if(item.nodeName === 'MOVABLE-VIEW') {
|
|
103
|
+
;(item as TaroMovableViewElement).doScale(event.scale)
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
)
|
|
64
109
|
}
|
|
65
110
|
}
|
|
66
111
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type { TaroMovableViewElement, TaroStyleType } from '@tarojs/runtime'
|
|
1
|
+
import type { TaroMovableViewElement, TaroStyleType, TaroAny } from '@tarojs/runtime'
|
|
2
2
|
|
|
3
3
|
import commonStyleModify from './style'
|
|
4
4
|
import { createLazyChildren } from './render'
|
|
5
5
|
|
|
6
6
|
import { FlexManager } from './utils/flexManager'
|
|
7
7
|
import { getNormalAttributes, } from './utils/helper'
|
|
8
|
+
|
|
8
9
|
@Extend(Row)
|
|
9
10
|
function rowAttrs(style: TaroStyleType) {
|
|
10
11
|
.constraintSize({
|
|
@@ -25,42 +26,65 @@ function columnAttrs(style: TaroStyleType) {
|
|
|
25
26
|
})
|
|
26
27
|
}
|
|
27
28
|
|
|
29
|
+
|
|
28
30
|
@Component
|
|
29
|
-
export default struct
|
|
31
|
+
export default struct TaroMovableView {
|
|
30
32
|
@ObjectLink node: TaroMovableViewElement
|
|
31
33
|
|
|
32
|
-
@Provide areaWidth: Length = 0
|
|
33
|
-
@Provide areaHeight: Length = 0
|
|
34
|
-
|
|
35
34
|
build() {
|
|
36
35
|
if (this.node) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
36
|
+
Stack() {
|
|
37
|
+
if (FlexManager.isFlexNode(this.node) && FlexManager.flexOptions(this.node)
|
|
38
|
+
.direction !== FlexDirection.Column) {
|
|
39
|
+
Row() {
|
|
40
|
+
createLazyChildren(this.node)
|
|
41
|
+
}
|
|
42
|
+
.attributeModifier(commonStyleModify.setNode(this.node))
|
|
43
|
+
.rowAttrs(getNormalAttributes(this.node))
|
|
44
|
+
.alignItems(FlexManager.flexOptions(this.node).alignItems as VerticalAlign)
|
|
45
|
+
.justifyContent(FlexManager.flexOptions(this.node).justifyContent)
|
|
46
|
+
} else {
|
|
47
|
+
Column() {
|
|
48
|
+
createLazyChildren(this.node)
|
|
49
|
+
}
|
|
50
|
+
.attributeModifier(commonStyleModify.setNode(this.node))
|
|
51
|
+
.columnAttrs(getNormalAttributes(this.node))
|
|
52
|
+
.alignItems(FlexManager.flexOptions(this.node).alignItems as HorizontalAlign)
|
|
53
|
+
.justifyContent(FlexManager.flexOptions(this.node).justifyContent)
|
|
53
54
|
}
|
|
54
|
-
.attributeModifier(commonStyleModify.setNode(this.node))
|
|
55
|
-
.columnAttrs(getNormalAttributes(this.node))
|
|
56
|
-
.alignItems(FlexManager.flexOptions(this.node).alignItems as HorizontalAlign)
|
|
57
|
-
.justifyContent(FlexManager.flexOptions(this.node).justifyContent)
|
|
58
|
-
.clip(true)
|
|
59
|
-
.onAreaChange((oldValue: Area, newValue: Area) => {
|
|
60
|
-
this.areaWidth = newValue.width
|
|
61
|
-
this.areaHeight = newValue.height
|
|
62
|
-
})
|
|
63
55
|
}
|
|
56
|
+
.translate({ x: this.node.position.x, y: this.node.position.y })
|
|
57
|
+
.scale({ x: this.node.scaleValue, y: this.node.scaleValue })
|
|
58
|
+
.onAreaChange((oldValue: Area, newValue: Area) => {
|
|
59
|
+
this.node.selfSize = {w: Number(newValue.width), h: Number(newValue.height)}
|
|
60
|
+
})
|
|
61
|
+
.gesture(
|
|
62
|
+
GestureGroup(GestureMode.Exclusive,
|
|
63
|
+
PanGesture({fingers:1}).onActionStart((e: GestureEvent) => {
|
|
64
|
+
|
|
65
|
+
this.node.startMove()
|
|
66
|
+
}).onActionUpdate((e: GestureEvent) => {
|
|
67
|
+
|
|
68
|
+
this.node.doMove({
|
|
69
|
+
x: e.offsetX,
|
|
70
|
+
y: e.offsetY
|
|
71
|
+
})
|
|
72
|
+
// 事件处理
|
|
73
|
+
const bindchange = this.node.getAttribute('bindchange')
|
|
74
|
+
if (typeof bindchange === 'function') {
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
}).onActionEnd(() => {
|
|
78
|
+
// this.updatePosition()
|
|
79
|
+
this.node.checkPositionBoundary(this.node.position, this.node.scaleValue)
|
|
80
|
+
}),
|
|
81
|
+
PinchGesture({ fingers: 2 }).onActionStart((event: GestureEvent) => {
|
|
82
|
+
this.node.startScale()
|
|
83
|
+
}).onActionUpdate((event) => {
|
|
84
|
+
this.node.doScale(event.scale)
|
|
85
|
+
})
|
|
86
|
+
)
|
|
87
|
+
)
|
|
64
88
|
}
|
|
65
89
|
}
|
|
66
90
|
}
|
|
@@ -43,19 +43,21 @@ export default struct TaroText {
|
|
|
43
43
|
@ObjectLink node: TaroTextElement
|
|
44
44
|
|
|
45
45
|
build () {
|
|
46
|
-
if (this.node.nodeType === NodeType.TEXT_NODE
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
46
|
+
if (this.node.nodeType === NodeType.TEXT_NODE) {
|
|
47
|
+
if (this.node.parentNode) {
|
|
48
|
+
if ((this.node.parentNode as TaroElement).tagName === 'BUTTON') {
|
|
49
|
+
Text(this.node.textContent)
|
|
50
|
+
.textNormalFontStyle(getNormalAttributes(this.node.parentNode as TaroElement))
|
|
51
|
+
.textSpecialFontStyle(getFontAttributes(this.node.parentNode as TaroElement))
|
|
52
|
+
.fontSize((this.node.parentNode as TaroButtonElement).hmStyle.fontSize || getButtonFontSize(this.node.parentNode as TaroButtonElement))
|
|
53
|
+
.fontColor((this.node.parentNode as TaroButtonElement).hmStyle.color || getButtonColor(this.node.parentNode as TaroButtonElement, BUTTON_THEME_COLOR.get((this.node.parentNode as TaroButtonElement)._attrs.type).text))
|
|
54
|
+
} else {
|
|
55
|
+
Text(this.node.textContent)
|
|
56
|
+
.textNormalFontStyle(getNormalAttributes(this.node.parentNode as TaroElement))
|
|
57
|
+
.textSpecialFontStyle(getFontAttributes(this.node.parentNode as TaroElement))
|
|
58
|
+
.width(getNormalAttributes(this.node.parentNode as TaroElement).width)
|
|
59
|
+
.height(getNormalAttributes(this.node.parentNode as TaroElement).height)
|
|
60
|
+
}
|
|
59
61
|
}
|
|
60
62
|
} else {
|
|
61
63
|
Text(this.node.textContent)
|
|
@@ -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] }
|
|
@@ -30,7 +30,7 @@ export function getUnit (val) {
|
|
|
30
30
|
function handleNodeStyleData (dataValue: string, handler: (values: string[]) => { [key: string]: string } | void) {
|
|
31
31
|
let res: any = {}
|
|
32
32
|
if (dataValue) {
|
|
33
|
-
const values = dataValue.trim().split(/\s+/)
|
|
33
|
+
const values = dataValue.toString().trim().split(/\s+/)
|
|
34
34
|
const data = handler(values)
|
|
35
35
|
|
|
36
36
|
if (!data) return res
|
|
@@ -11,6 +11,8 @@ export function getFontAttributes (node: TaroElement): TaroTextStyleType {
|
|
|
11
11
|
const hmStyle = node.hmStyle
|
|
12
12
|
const attrs: TextProps = node._attrs || {}
|
|
13
13
|
|
|
14
|
+
if (!hmStyle) return {}
|
|
15
|
+
|
|
14
16
|
const attributes: TaroAny = {
|
|
15
17
|
WebkitLineClamp: attrs.maxLines || hmStyle.WebkitLineClamp || Infinity,
|
|
16
18
|
// 已做处理的属性
|
|
@@ -32,6 +34,8 @@ function isMaxWidthView (node: TaroElement) {
|
|
|
32
34
|
|
|
33
35
|
export function getNormalAttributes (node: TaroElement): TaroStyleType {
|
|
34
36
|
const hmStyle = node.hmStyle
|
|
37
|
+
|
|
38
|
+
if (!hmStyle) return {}
|
|
35
39
|
|
|
36
40
|
const _nid = node._nid
|
|
37
41
|
const _attrs: StandardProps = node._attrs || {}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
// 抽出来的嵌套查询
|
|
2
|
+
// const __nesting_style__ = [
|
|
3
|
+
// {
|
|
4
|
+
// selectors: ['container', '>', 'hello', ' ', 'txt'],
|
|
5
|
+
// declaration: {
|
|
6
|
+
// _color: "#00F00F",
|
|
7
|
+
// _fontSize: convertNumber2VP(40),
|
|
8
|
+
// }
|
|
9
|
+
// },
|
|
10
|
+
// ]
|
|
11
|
+
//
|
|
12
|
+
// function Index() {
|
|
13
|
+
// return __combine_nesting_style__(jsx(TaroViewTagName, {
|
|
14
|
+
// className: "container aaa",
|
|
15
|
+
// style: calcDynamicStyle(__inner_style__(), "container", null),
|
|
16
|
+
// children: [
|
|
17
|
+
// jsx(TaroTextTagName, {
|
|
18
|
+
// className: "txt cc",
|
|
19
|
+
// style: calcDynamicStyle(__inner_style__(), "txt", null),
|
|
20
|
+
// children: "Hello!"
|
|
21
|
+
// }),
|
|
22
|
+
// jsx(TaroViewTagName, {
|
|
23
|
+
// className: "hello",
|
|
24
|
+
// style: calcDynamicStyle(__inner_style__(), "hello", null),
|
|
25
|
+
// children: [
|
|
26
|
+
// jsx(TaroTextTagName, {
|
|
27
|
+
// className: "txt",
|
|
28
|
+
// style: calcDynamicStyle(__inner_style__(), "txt", null),
|
|
29
|
+
// children: "wo2rld!"
|
|
30
|
+
// }),
|
|
31
|
+
// jsx(TaroTextTagName, {
|
|
32
|
+
// className: "txt2",
|
|
33
|
+
// style: calcDynamicStyle(__inner_style__(), "txt2", null),
|
|
34
|
+
// children: "Hello wo2rld!"
|
|
35
|
+
// })
|
|
36
|
+
// ]
|
|
37
|
+
// })
|
|
38
|
+
// ]
|
|
39
|
+
// }), __nesting_style__);
|
|
40
|
+
// }
|
|
41
|
+
|
|
42
|
+
import { ReactElement } from 'react'
|
|
43
|
+
|
|
44
|
+
type TMappingNode = {
|
|
45
|
+
children: TMapping
|
|
46
|
+
descendants: TMapping
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
type TMapping = Record<string, TMappingNode>
|
|
50
|
+
|
|
51
|
+
type TSelectorNode = {
|
|
52
|
+
mapping: TMapping
|
|
53
|
+
node: ReactElement
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type NestingStyle = {
|
|
57
|
+
selectors: string[]
|
|
58
|
+
declaration: Record<string, any>
|
|
59
|
+
}[]
|
|
60
|
+
|
|
61
|
+
// 构建映射表
|
|
62
|
+
function depthTraversal(root: ReactElement) {
|
|
63
|
+
const class_mapping: TMapping = {}
|
|
64
|
+
// 记录别名,防止冲突
|
|
65
|
+
const selector_alias: Record<string, string[]> = {}
|
|
66
|
+
// 统计重名次数:{ txt: 1, cc: 2 }
|
|
67
|
+
const selector_alias_count: Record<string, number> = {}
|
|
68
|
+
|
|
69
|
+
const traverse = (tree) => {
|
|
70
|
+
if (tree) {
|
|
71
|
+
// 拆分classnames
|
|
72
|
+
const classnames = tree.props.className.split(' ')
|
|
73
|
+
|
|
74
|
+
const result: Record<string, TMapping> = {}
|
|
75
|
+
|
|
76
|
+
// 后代选择器
|
|
77
|
+
const descendant_map = {
|
|
78
|
+
children: {},
|
|
79
|
+
descendants: {}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (tree.props.children) {
|
|
83
|
+
// 遍历叶子节点
|
|
84
|
+
if (tree.props.children instanceof Array) {
|
|
85
|
+
for (let i = 0; i < tree.props.children.length; i++) {
|
|
86
|
+
// 收集叶子节点所拥有的类名
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
88
|
+
processLeaf(tree.props.children[i], descendant_map)
|
|
89
|
+
}
|
|
90
|
+
} else if (typeof tree.props.children !== 'string'){
|
|
91
|
+
// 收集叶子节点所拥有的类名
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
93
|
+
processLeaf(tree.props.children, descendant_map)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
for (let i = 0; i < classnames.length; i++) {
|
|
97
|
+
const cls = classnames[i]
|
|
98
|
+
let name = cls
|
|
99
|
+
if (selector_alias_count[name]) {
|
|
100
|
+
// 存在重名,需要使用别名替代
|
|
101
|
+
const oldName = name
|
|
102
|
+
name = `___${name}${selector_alias_count[oldName]}`
|
|
103
|
+
selector_alias_count[oldName] = selector_alias_count[oldName] + 1
|
|
104
|
+
selector_alias[oldName] ? selector_alias[oldName].push(name) : (selector_alias[oldName] = [name])
|
|
105
|
+
}
|
|
106
|
+
selector_alias_count[name] = 1
|
|
107
|
+
|
|
108
|
+
class_mapping[name] = descendant_map
|
|
109
|
+
result[name] = {
|
|
110
|
+
ref: descendant_map,
|
|
111
|
+
node: tree
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return result
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const processLeaf = (leaf, descendant_map: TMappingNode) => {
|
|
120
|
+
if (!leaf) return
|
|
121
|
+
const leaf_map = traverse(leaf)
|
|
122
|
+
if (!leaf_map) return
|
|
123
|
+
// 直接后代
|
|
124
|
+
Object.assign(descendant_map.children, leaf_map)
|
|
125
|
+
// 子孙后代
|
|
126
|
+
Object.assign(descendant_map.descendants, leaf_map)
|
|
127
|
+
const keys = Object.keys(leaf_map)
|
|
128
|
+
for (let i = 0; i < keys.length; i++) {
|
|
129
|
+
const leaf_child_map = class_mapping[keys[i]]
|
|
130
|
+
if (leaf_child_map) {
|
|
131
|
+
Object.assign(descendant_map.descendants, leaf_child_map.children)
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
traverse(root)
|
|
137
|
+
return {
|
|
138
|
+
mapping: class_mapping,
|
|
139
|
+
alias: selector_alias
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// 将嵌套样式与节点合并
|
|
144
|
+
function combineStyle(nestingStyle: NestingStyle, class_mapping: TMapping, alias: Record<string, string[]>) {
|
|
145
|
+
|
|
146
|
+
const findElement = (selector_string, combinator_type, selector_mapping) => {
|
|
147
|
+
let selector_list = [selector_string]
|
|
148
|
+
const selector_nodes: TSelectorNode[] = []
|
|
149
|
+
// 判断是否存在别名
|
|
150
|
+
if (alias[selector_string]) {
|
|
151
|
+
selector_list = selector_list.concat(alias[selector_string])
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
for (let i = 0; i < selector_list.length; i++) {
|
|
155
|
+
const selector = selector_list[i]
|
|
156
|
+
// 查询选择器的节点
|
|
157
|
+
const object = selector_mapping[selector]
|
|
158
|
+
if (object) {
|
|
159
|
+
selector_nodes.push({
|
|
160
|
+
mapping: (object.ref || object)[combinator_type === '>' ? 'children' : 'descendants'],
|
|
161
|
+
node: object.node
|
|
162
|
+
})
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return selector_nodes
|
|
166
|
+
}
|
|
167
|
+
const findSelector = (selectors, current_mapping): TSelectorNode[] => {
|
|
168
|
+
const new_selectors = selectors.slice()
|
|
169
|
+
const selector_string = new_selectors.shift()
|
|
170
|
+
const combinator_type = new_selectors.shift()
|
|
171
|
+
const _elements = findElement(selector_string, combinator_type, current_mapping)
|
|
172
|
+
if (_elements.length) {
|
|
173
|
+
if (new_selectors.length) {
|
|
174
|
+
let elements: TSelectorNode[] = []
|
|
175
|
+
_elements.forEach(element => {
|
|
176
|
+
elements = elements.concat(findSelector(new_selectors.slice(), element.mapping))
|
|
177
|
+
})
|
|
178
|
+
return elements
|
|
179
|
+
} else {
|
|
180
|
+
return _elements
|
|
181
|
+
}
|
|
182
|
+
} else {
|
|
183
|
+
return []
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// 合并样式
|
|
187
|
+
nestingStyle.forEach(({ selectors, declaration }) => {
|
|
188
|
+
// 获取选中的节点列表
|
|
189
|
+
const selectors_elements = findSelector(selectors, class_mapping)
|
|
190
|
+
for (let i = 0; i < selectors_elements.length; i++) {
|
|
191
|
+
const ele = selectors_elements[i].node
|
|
192
|
+
if (ele) {
|
|
193
|
+
if (ele.props.style) {
|
|
194
|
+
Object.assign(ele.props.style, declaration)
|
|
195
|
+
} else {
|
|
196
|
+
ele.props.style = declaration
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
})
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// 合并嵌套样式
|
|
204
|
+
// 1、构建映射表,生成一份扁平的样式表结构
|
|
205
|
+
// 2、遍历嵌套样式,根据选择器查找节点,合并样式
|
|
206
|
+
function __combine_nesting_style__(react_tree: ReactElement, styles: NestingStyle) {
|
|
207
|
+
// 循环一遍,构建出一颗JSX映射表
|
|
208
|
+
const { mapping, alias } = depthTraversal(react_tree)
|
|
209
|
+
// 合并样式
|
|
210
|
+
combineStyle(styles, mapping, alias)
|
|
211
|
+
return react_tree
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export default __combine_nesting_style__
|
|
@@ -39,6 +39,9 @@ export function initHarmonyElement () {
|
|
|
39
39
|
case 'image': return new TaroImageElement()
|
|
40
40
|
case 'text': return new TaroTextElement()
|
|
41
41
|
case 'button': return new TaroButtonElement()
|
|
42
|
+
case 'movable-area': return new TaroMovableAreaElement()
|
|
43
|
+
case 'movable-view': return new TaroMovableViewElement()
|
|
44
|
+
case 'progress': return new TaroProgressElement()
|
|
42
45
|
case 'scroll-view': return new TaroScrollViewElement()
|
|
43
46
|
case 'checkbox-group': return new TaroCheckboxGroupElement()
|
|
44
47
|
case 'input': return new TaroInputElement()
|
|
@@ -1,12 +1,194 @@
|
|
|
1
|
-
|
|
2
1
|
import { TaroElement } from './element'
|
|
3
2
|
|
|
4
3
|
import type { MovableViewProps } from '@tarojs/components/types'
|
|
5
4
|
|
|
5
|
+
type Tsize = {
|
|
6
|
+
w: number
|
|
7
|
+
h: number
|
|
8
|
+
}
|
|
9
|
+
type Tpoint = {
|
|
10
|
+
x: number
|
|
11
|
+
y: number
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function calcPosition(postion: number, start: number, end: number) {
|
|
15
|
+
if (postion <= end && postion >= start) {
|
|
16
|
+
return postion
|
|
17
|
+
} else if (postion < start) {
|
|
18
|
+
return start
|
|
19
|
+
} else {
|
|
20
|
+
return end
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
6
24
|
@Observed
|
|
7
|
-
export class TaroMovableViewElement extends TaroElement<MovableViewProps & {
|
|
25
|
+
export class TaroMovableViewElement extends TaroElement<MovableViewProps & { animation: undefined }> {
|
|
26
|
+
_scaleValue = 1
|
|
27
|
+
_scalevalueTemp = 1
|
|
28
|
+
|
|
29
|
+
// 父级区别的大小
|
|
30
|
+
_area?: Tsize
|
|
31
|
+
// 自己元素的大小
|
|
32
|
+
_selfSize?: Tsize
|
|
33
|
+
|
|
34
|
+
// 元素的位置
|
|
35
|
+
_position: Tpoint = {
|
|
36
|
+
x: 0,
|
|
37
|
+
y: 0,
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
_positionTemp: Tpoint = {
|
|
41
|
+
x: 0,
|
|
42
|
+
y: 0,
|
|
43
|
+
}
|
|
8
44
|
|
|
9
45
|
constructor() {
|
|
10
46
|
super('MovableView')
|
|
11
47
|
}
|
|
48
|
+
|
|
49
|
+
get _outOfBounds() {
|
|
50
|
+
if (this.getAttribute('outOfBounds')) {
|
|
51
|
+
return this.selfSize ? this.selfSize.w / 3 : 0
|
|
52
|
+
}
|
|
53
|
+
return 0
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
set area(val: Tsize) {
|
|
57
|
+
this._area = val
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get area(): Tsize | undefined {
|
|
61
|
+
return this._area
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
startScale() {
|
|
65
|
+
this._scalevalueTemp = this._scaleValue
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
doScale(val: number) {
|
|
69
|
+
const scale = this.getAttribute('scale')
|
|
70
|
+
|
|
71
|
+
// 禁止缩放的时候不生效
|
|
72
|
+
if (scale) {
|
|
73
|
+
this.scaleValue = val * this._scalevalueTemp
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
set scaleValue(val: number) {
|
|
78
|
+
if (this.checkScaleValueInBounds(val)) {
|
|
79
|
+
this._scaleValue = val
|
|
80
|
+
|
|
81
|
+
this.checkPositionBoundary(this.position, val)
|
|
82
|
+
|
|
83
|
+
const bindscale = this.getAttribute('bindscale')
|
|
84
|
+
typeof bindscale === 'function' && bindscale({ ...this.position, scale: this.scaleValue })
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
get scaleValue() {
|
|
90
|
+
return this._scaleValue
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
startMove() {
|
|
94
|
+
this._positionTemp = this._position
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
doMove(val: Tpoint) {
|
|
98
|
+
if (!this.area || !this.selfSize) return
|
|
99
|
+
if (this.getAttribute('disabled')) return
|
|
100
|
+
const direction = this.getAttribute('direction')
|
|
101
|
+
|
|
102
|
+
// 容器的宽高终点
|
|
103
|
+
const areaWidthEnd = this.area.w - this.selfSize.w * this.scaleValue
|
|
104
|
+
const areaHeightEnd = this.area.h - this.selfSize.h * this.scaleValue
|
|
105
|
+
|
|
106
|
+
const incrementWidth = (this.scaleValue - 1) * this.selfSize.w
|
|
107
|
+
const incrementHeight = (this.scaleValue - 1) * this.selfSize.h
|
|
108
|
+
|
|
109
|
+
let x = this._positionTemp.x
|
|
110
|
+
let y = this._positionTemp.y
|
|
111
|
+
if (['all', 'horizontal'].includes(direction)) {
|
|
112
|
+
const nextX = this._positionTemp.x + val.x * this.scaleValue
|
|
113
|
+
x = calcPosition(
|
|
114
|
+
nextX,
|
|
115
|
+
incrementWidth * 0.5 - this._outOfBounds,
|
|
116
|
+
areaWidthEnd + incrementWidth * 0.5 + this._outOfBounds
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (['all', 'vertical'].includes(direction)) {
|
|
121
|
+
const nextY = this._positionTemp.y + val.y * this.scaleValue
|
|
122
|
+
y = calcPosition(
|
|
123
|
+
nextY,
|
|
124
|
+
incrementHeight * 0.5 - this._outOfBounds,
|
|
125
|
+
areaHeightEnd + incrementHeight * 0.5 + this._outOfBounds
|
|
126
|
+
)
|
|
127
|
+
}
|
|
128
|
+
const bindchange = this.getAttribute('bindchange')
|
|
129
|
+
if (typeof bindchange === 'function') {
|
|
130
|
+
bindchange({ x, y, source: 'touch' })
|
|
131
|
+
}
|
|
132
|
+
this.position = {
|
|
133
|
+
x: x,
|
|
134
|
+
y: y,
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
get position() {
|
|
139
|
+
return this._position
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
set position(val: Tpoint) {
|
|
143
|
+
this._position = val
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
set selfSize(val: Tsize) {
|
|
147
|
+
this._selfSize = val
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
get selfSize(): Tsize | undefined {
|
|
151
|
+
return this._selfSize
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
checkPositionBoundary(position: Tpoint, scale: number) {
|
|
155
|
+
if (!this.area || !this.selfSize) {
|
|
156
|
+
return { x: 0, y: 0 }
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const areaWidthEnd = this.area.w - this.selfSize.w * scale
|
|
160
|
+
const areaHeightEnd = this.area.h - this.selfSize.h * scale
|
|
161
|
+
|
|
162
|
+
const incrementWidth = (scale - 1) * this.selfSize.w
|
|
163
|
+
const incrementHeight = (scale - 1) * this.selfSize.h
|
|
164
|
+
|
|
165
|
+
this.position = {
|
|
166
|
+
x: calcPosition(position.x, incrementWidth * 0.5, areaWidthEnd + incrementWidth * 0.5),
|
|
167
|
+
y: calcPosition(position.y, incrementHeight * 0.5, areaHeightEnd + incrementHeight * 0.5),
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
checkScaleValueInBounds(currentScale: number) {
|
|
172
|
+
const scaleMin = this.getAttribute('scaleMin')
|
|
173
|
+
const scaleMax = this.getAttribute('scaleMax')
|
|
174
|
+
|
|
175
|
+
if (scaleMin && Number(scaleMin) >= 0.1 && currentScale < Number(scaleMin)) {
|
|
176
|
+
return false
|
|
177
|
+
} else if (scaleMax && Number(scaleMax) >= 0.1 && currentScale > Number(scaleMax)) {
|
|
178
|
+
return false
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return true
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
public setAttribute(name: string, value: any): void {
|
|
185
|
+
if (name === 'x') {
|
|
186
|
+
this.checkPositionBoundary({ x: value, y: this.position.y }, this.scaleValue)
|
|
187
|
+
}
|
|
188
|
+
if (name === 'y') {
|
|
189
|
+
this.checkPositionBoundary({ x: this.position.x, y: value }, this.scaleValue)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
super.setAttribute(name, value)
|
|
193
|
+
}
|
|
12
194
|
}
|
|
@@ -192,7 +192,7 @@ export class BORDER_STYLE_MAP {
|
|
|
192
192
|
export function getNodeMarginOrPaddingData (dataValue: string) {
|
|
193
193
|
let res: any = {}
|
|
194
194
|
if (dataValue) {
|
|
195
|
-
const values = dataValue.trim().split(new RegExp('\\s+'))
|
|
195
|
+
const values = dataValue.toString().trim().split(new RegExp('\\s+'))
|
|
196
196
|
switch (values.length) {
|
|
197
197
|
case 1:
|
|
198
198
|
res = { top: values[0], right: values[0], bottom: values[0], left: values[0] }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarojs/plugin-platform-harmony-ets",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.16",
|
|
4
4
|
"description": "OpenHarmony & 鸿蒙系统插件",
|
|
5
5
|
"author": "O2Team",
|
|
6
6
|
"homepage": "https://gitee.com/openharmony-sig/taro",
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"webpack-sources": "^3.2.3",
|
|
28
|
-
"@tarojs/components": "4.0.0-beta.
|
|
29
|
-
"@tarojs/helper": "4.0.0-beta.
|
|
30
|
-
"@tarojs/runner-utils": "4.0.0-beta.
|
|
31
|
-
"@tarojs/runtime": "4.0.0-beta.
|
|
32
|
-
"@tarojs/service": "4.0.0-beta.
|
|
33
|
-
"@tarojs/shared": "4.0.0-beta.
|
|
34
|
-
"@tarojs/taro": "4.0.0-beta.
|
|
28
|
+
"@tarojs/components": "4.0.0-beta.16",
|
|
29
|
+
"@tarojs/helper": "4.0.0-beta.16",
|
|
30
|
+
"@tarojs/runner-utils": "4.0.0-beta.16",
|
|
31
|
+
"@tarojs/runtime": "4.0.0-beta.16",
|
|
32
|
+
"@tarojs/service": "4.0.0-beta.16",
|
|
33
|
+
"@tarojs/shared": "4.0.0-beta.16",
|
|
34
|
+
"@tarojs/taro": "4.0.0-beta.16"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@rollup/plugin-commonjs": "^25.0.7",
|