@tarojs/plugin-platform-harmony-ets 4.0.0-alpha.0 → 4.0.0-alpha.11
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 +73 -20
- package/dist/apis/canvas/index.ts +10 -1
- package/dist/apis/device/clipboard.ts +16 -8
- package/dist/apis/device/memory.ts +10 -3
- package/dist/apis/framework/index.ts +1 -5
- package/dist/apis/index.ts +27 -17
- package/dist/apis/media/image/index.ts +1 -1
- package/dist/apis/media/video/VideoContext.ts +56 -7
- package/dist/apis/media/video/index.ts +3 -2
- package/dist/apis/network/request.ts +5 -5
- package/dist/apis/route/index.ts +15 -0
- package/dist/apis/storage/index.ts +146 -78
- package/dist/apis/ui/animation/animation.ts +71 -29
- package/dist/apis/ui/background.ts +2 -1
- package/dist/apis/ui/interaction/index.ts +42 -59
- package/dist/apis/ui/navigation-bar/index.ts +1 -1
- 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 +3 -3
- package/dist/apis/utils/index.ts +1 -1
- package/dist/apis/wxml/IntersectionObserver.ts +18 -10
- package/dist/apis/wxml/index.ts +2 -0
- package/dist/apis/wxml/selectorQuery.ts +26 -13
- package/dist/components-harmony-ets/button.ets +68 -68
- package/dist/components-harmony-ets/canvas.ets +51 -0
- package/dist/components-harmony-ets/checkbox.ets +81 -102
- package/dist/components-harmony-ets/form.ets +54 -45
- package/dist/components-harmony-ets/icon.ets +34 -50
- package/dist/components-harmony-ets/image.ets +35 -45
- package/dist/components-harmony-ets/index.ets +92 -0
- package/dist/components-harmony-ets/innerHtml.ets +11 -6
- package/dist/components-harmony-ets/input.ets +51 -67
- package/dist/components-harmony-ets/label.ets +73 -53
- package/dist/components-harmony-ets/listView.ets +26 -0
- package/dist/components-harmony-ets/movableArea.ets +124 -0
- package/dist/components-harmony-ets/movableView.ets +93 -0
- 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 +74 -77
- package/dist/components-harmony-ets/progress.ets +52 -0
- package/dist/components-harmony-ets/pseudo.ets +80 -0
- package/dist/components-harmony-ets/radio.ets +82 -104
- package/dist/components-harmony-ets/richText.ets +20 -68
- package/dist/components-harmony-ets/scrollList.ets +94 -0
- package/dist/components-harmony-ets/scrollView.ets +67 -103
- package/dist/components-harmony-ets/slider.ets +23 -47
- package/dist/components-harmony-ets/stickySection.ets +42 -0
- package/dist/components-harmony-ets/style.ets +396 -0
- package/dist/components-harmony-ets/swiper.ets +64 -53
- package/dist/components-harmony-ets/switch.ets +44 -55
- package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
- package/dist/components-harmony-ets/text.ets +134 -75
- package/dist/components-harmony-ets/textArea.ets +54 -62
- package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
- package/dist/components-harmony-ets/utils/DynamicCenter.ts +4 -13
- package/dist/components-harmony-ets/utils/flexManager.ets +76 -8
- package/dist/components-harmony-ets/utils/helper.ets +20 -7
- 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 +178 -63
- package/dist/components-harmony-ets/video.ets +37 -54
- package/dist/components-harmony-ets/view.ets +63 -94
- package/dist/components-harmony-ets/webView.ets +56 -0
- package/dist/index.d.ts +152 -0
- package/dist/index.js +199 -58
- package/dist/index.js.map +1 -1
- package/dist/runtime-ets/bom/document.ts +6 -4
- package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
- package/dist/runtime-ets/bom/window.ts +9 -2
- package/dist/runtime-ets/current.ts +3 -0
- 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 +409 -0
- package/dist/runtime-ets/dom/cssStyleDeclaration.ts +29 -19
- package/dist/runtime-ets/dom/document.ts +22 -8
- package/dist/runtime-ets/dom/element/canvas.ts +136 -0
- package/dist/runtime-ets/dom/element/element.ts +334 -57
- package/dist/runtime-ets/dom/element/form.ts +32 -26
- package/dist/runtime-ets/dom/element/index.ts +33 -2
- package/dist/runtime-ets/dom/element/movableArea.ts +11 -0
- package/dist/runtime-ets/dom/element/movableView.ts +242 -0
- package/dist/runtime-ets/dom/element/normal.ts +36 -8
- package/dist/runtime-ets/dom/element/progress.ts +11 -0
- package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
- package/dist/runtime-ets/dom/element/text.ts +1 -8
- package/dist/runtime-ets/dom/element/video.ts +5 -4
- package/dist/runtime-ets/dom/element/webView.ts +68 -0
- package/dist/runtime-ets/dom/event.ts +2 -4
- package/dist/runtime-ets/dom/eventTarget.ts +2 -3
- package/dist/runtime-ets/dom/node.ts +62 -27
- package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +805 -0
- package/dist/runtime-ets/dom/stylesheet/index.ts +98 -518
- package/dist/runtime-ets/dom/stylesheet/type.ts +92 -17
- package/dist/runtime-ets/dom/stylesheet/util.ts +74 -16
- package/dist/runtime-ets/index.ts +2 -2
- package/dist/runtime-ets/interface/event.ts +3 -2
- package/dist/runtime-ets/utils/index.ts +77 -12
- package/dist/runtime-ets/utils/info.ts +4 -2
- package/dist/runtime-framework/react/app.ts +17 -22
- package/dist/runtime-framework/react/hooks.ts +3 -4
- package/dist/runtime-framework/react/index.ts +1 -2
- package/dist/runtime-framework/react/native-page.ts +421 -0
- package/dist/runtime-framework/react/page.ts +4 -9
- package/dist/runtime-framework/solid/app.ts +25 -45
- package/dist/runtime-framework/solid/connect.ts +21 -3
- package/dist/runtime-framework/solid/hooks.ts +17 -12
- package/dist/runtime-framework/solid/index.ts +6 -2
- package/dist/runtime-framework/solid/page.ts +84 -30
- package/dist/runtime-framework/solid/reconciler/props.ts +70 -25
- 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 +0 -2
- package/dist/runtime-utils.d.ts +827 -0
- package/dist/runtime-utils.js +510 -237
- package/dist/runtime-utils.js.map +1 -1
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.js +510 -237
- package/dist/runtime.js.map +1 -1
- package/index.js +3 -1
- package/package.json +14 -15
- package/static/media/cancel.svg +1 -0
- package/static/media/circle.svg +1 -0
- package/static/media/clear.svg +1 -0
- package/static/media/download.svg +1 -0
- package/static/media/info.svg +1 -0
- package/static/media/info_circle.svg +1 -0
- package/static/media/search.svg +1 -0
- package/static/media/success.svg +1 -0
- package/static/media/success_no_circle.svg +1 -0
- package/static/media/taro_arrow_left.svg +1 -0
- package/static/media/taro_home.svg +1 -0
- package/static/media/waiting.svg +1 -0
- package/static/media/warn.svg +1 -0
- package/types/harmony.d.ts +4 -0
- package/types/index.d.ts +4 -0
- package/types/runtime.d.ts +3 -1
- package/dist/runtime-ets/utils/bind.ts +0 -24
- /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
|
@@ -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
|
}
|
|
@@ -1,88 +1,203 @@
|
|
|
1
|
+
import { isUndefined } from '@tarojs/shared'
|
|
1
2
|
import { ObjectAssign } from '@tarojs/runtime'
|
|
2
3
|
|
|
3
|
-
import {
|
|
4
|
+
import { FlexManager } from './flexManager'
|
|
4
5
|
|
|
5
|
-
import type { StandardProps } from '@tarojs/components/types'
|
|
6
|
-
import type { TaroAny, TaroElement, TaroStyleType, TaroTextStyleType,
|
|
6
|
+
import type { StandardProps, TextProps } from '@tarojs/components/types'
|
|
7
|
+
import type { TaroAny, TaroElement, TaroStyleType, TaroTextStyleType, HarmonyStyle } from '@tarojs/runtime'
|
|
7
8
|
|
|
8
9
|
export function getFontAttributes (node: TaroElement): TaroTextStyleType {
|
|
9
|
-
|
|
10
|
+
let hmStyle = getNormalAttributes(node)
|
|
11
|
+
const attrs: TextProps = node._attrs || {}
|
|
12
|
+
|
|
13
|
+
if (!hmStyle) return {}
|
|
14
|
+
|
|
15
|
+
let lineHeight = hmStyle.lineHeight
|
|
16
|
+
if (!isUndefined(hmStyle.verticalAlign)) {
|
|
17
|
+
lineHeight = 0
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let WebkitLineClamp = attrs.maxLines || hmStyle.WebkitLineClamp || Infinity
|
|
21
|
+
if (hmStyle.textOverflow && !isUndefined(hmStyle.textOverflow.overflow)) {
|
|
22
|
+
switch (hmStyle.textOverflow.overflow) {
|
|
23
|
+
case TextOverflow.Clip:
|
|
24
|
+
case TextOverflow.Ellipsis:
|
|
25
|
+
case TextOverflow.None: WebkitLineClamp = WebkitLineClamp || 1; break
|
|
26
|
+
default: break
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const isFlexText = hmStyle.display === 'flex'
|
|
31
|
+
let textAlign = hmStyle.textAlign
|
|
32
|
+
let verticalAlign = hmStyle.verticalAlign
|
|
33
|
+
|
|
34
|
+
// 按照 w3c 规范,一旦设置了 display: flex,textAlign 和 verticalAlign 都会直接失效
|
|
35
|
+
// 需要使用 justifyContent 和 alignItems
|
|
36
|
+
if (isFlexText) {
|
|
37
|
+
switch (hmStyle.justifyContent) {
|
|
38
|
+
case FlexAlign.Start:
|
|
39
|
+
textAlign = TextAlign.Start
|
|
40
|
+
break
|
|
41
|
+
case FlexAlign.Center:
|
|
42
|
+
textAlign = TextAlign.Center
|
|
43
|
+
break
|
|
44
|
+
case FlexAlign.End:
|
|
45
|
+
textAlign = TextAlign.End
|
|
46
|
+
break
|
|
47
|
+
case FlexAlign.SpaceBetween:
|
|
48
|
+
case FlexAlign.SpaceAround:
|
|
49
|
+
textAlign = TextAlign.JUSTIFY
|
|
50
|
+
break
|
|
51
|
+
default:
|
|
52
|
+
textAlign = TextAlign.Start
|
|
53
|
+
break
|
|
54
|
+
}
|
|
55
|
+
switch (hmStyle.alignItems) {
|
|
56
|
+
case ItemAlign.Start:
|
|
57
|
+
verticalAlign = Alignment.Top
|
|
58
|
+
break
|
|
59
|
+
case ItemAlign.Center:
|
|
60
|
+
verticalAlign = Alignment.Center
|
|
61
|
+
break
|
|
62
|
+
case ItemAlign.End:
|
|
63
|
+
verticalAlign = Alignment.End
|
|
64
|
+
break
|
|
65
|
+
default:
|
|
66
|
+
verticalAlign = Alignment.Top
|
|
67
|
+
break
|
|
68
|
+
}
|
|
69
|
+
}
|
|
10
70
|
|
|
11
71
|
const attributes: TaroAny = {
|
|
12
|
-
|
|
72
|
+
textAlign,
|
|
73
|
+
verticalAlign,
|
|
74
|
+
WebkitLineClamp: WebkitLineClamp,
|
|
13
75
|
// 已做处理的属性
|
|
14
76
|
letterSpacing: hmStyle.letterSpacing,
|
|
15
|
-
|
|
16
|
-
|
|
77
|
+
textOverflow: hmStyle.textOverflow,
|
|
78
|
+
lineHeight: lineHeight
|
|
17
79
|
}
|
|
18
80
|
|
|
19
81
|
return attributes
|
|
20
82
|
}
|
|
21
83
|
|
|
22
|
-
|
|
84
|
+
// 模拟 div 自动撑满父元素的情况
|
|
85
|
+
export function isMaxWidthView (node: TaroElement) {
|
|
86
|
+
const parentNode: TaroElement = node.parentNode as TaroElement
|
|
87
|
+
|
|
88
|
+
return node.tagName === 'VIEW' && parentNode && parentNode.tagName === 'VIEW' && !FlexManager.isFlexNode(parentNode)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function getNormalAttributes (node: TaroElement, initStyle?: HarmonyStyle): HarmonyStyle {
|
|
23
92
|
const hmStyle = node.hmStyle
|
|
93
|
+
|
|
94
|
+
if (!hmStyle) return {}
|
|
24
95
|
|
|
25
96
|
const _nid = node._nid
|
|
26
97
|
const _attrs: StandardProps = node._attrs || {}
|
|
27
98
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
flexBasis: hmStyle.flexBasis,
|
|
37
|
-
flexGrow: hmStyle.flexGrow,
|
|
38
|
-
flexShrink: hmStyle.flexShrink,
|
|
39
|
-
alignSelf: hmStyle.alignSelf,
|
|
40
|
-
// 尺寸相关
|
|
41
|
-
width: hmStyle.width,
|
|
42
|
-
height: hmStyle.height,
|
|
43
|
-
constraintSize: hmStyle.constraintSize,
|
|
44
|
-
margin: hmStyle.margin,
|
|
45
|
-
padding: hmStyle.padding,
|
|
46
|
-
// 边框相关
|
|
47
|
-
borderStyle: hmStyle.borderStyle,
|
|
48
|
-
borderWidth: hmStyle.borderWidth,
|
|
49
|
-
borderColor: hmStyle.borderColor,
|
|
50
|
-
borderRadius: hmStyle.borderRadius,
|
|
51
|
-
// 背景相关
|
|
52
|
-
backgroundColor: hmStyle.backgroundColor,
|
|
53
|
-
backgroundImage: hmStyle.backgroundImage,
|
|
54
|
-
backgroundImageSize: hmStyle.backgroundImageSize,
|
|
55
|
-
backgroundRepeat: hmStyle.backgroundRepeat,
|
|
56
|
-
backgroundImagePosition: hmStyle.backgroundImagePosition,
|
|
57
|
-
linearGradient: hmStyle.linearGradient,
|
|
58
|
-
// 变换相关
|
|
59
|
-
rotate: transformRotate,
|
|
60
|
-
translate: transformTranslate,
|
|
61
|
-
scale: transformScale,
|
|
62
|
-
transform: transformTransform,
|
|
63
|
-
// 通用文本相关
|
|
64
|
-
color: hmStyle.color,
|
|
65
|
-
fontSize: hmStyle.fontSize,
|
|
66
|
-
fontStyle: hmStyle.fontStyle,
|
|
67
|
-
fontWeight: hmStyle.fontWeight,
|
|
68
|
-
fontFamily: hmStyle.fontFamily || TEXT_DEFAULT_STYLE.FONT_FAMILY,
|
|
69
|
-
lineHeight: hmStyle.lineHeight,
|
|
70
|
-
decoration: hmStyle.decoration,
|
|
71
|
-
// 其他
|
|
72
|
-
clip: hmStyle.clip,
|
|
73
|
-
id: _attrs.id || _nid,
|
|
74
|
-
opacity: hmStyle.opacity,
|
|
75
|
-
// focus: _attrs.focus || false,
|
|
99
|
+
let normalAttributes = hmStyle
|
|
100
|
+
|
|
101
|
+
// 覆盖属性
|
|
102
|
+
normalAttributes.id = _attrs.id || _nid
|
|
103
|
+
|
|
104
|
+
let pseudoStylesheet = getPseudoClass(node)
|
|
105
|
+
if (pseudoStylesheet) {
|
|
106
|
+
normalAttributes = ObjectAssign({}, normalAttributes, pseudoStylesheet)
|
|
76
107
|
}
|
|
77
108
|
|
|
78
|
-
//
|
|
79
|
-
if (
|
|
80
|
-
|
|
109
|
+
// 初始化默认的值
|
|
110
|
+
if (initStyle) {
|
|
111
|
+
normalAttributes = ObjectAssign({}, initStyle, normalAttributes)
|
|
112
|
+
}
|
|
113
|
+
return normalAttributes
|
|
114
|
+
}
|
|
81
115
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
116
|
+
// 应用伪类样式
|
|
117
|
+
function getPseudoClass (node: TaroElement): HarmonyStyle | null {
|
|
118
|
+
// 伪类
|
|
119
|
+
const _pseudo_class = Object.keys(node._pseudo_class)
|
|
120
|
+
if (_pseudo_class.length) {
|
|
121
|
+
for (let i = 0; i < _pseudo_class.length; i++) {
|
|
122
|
+
const pseudoKey = _pseudo_class[i]
|
|
123
|
+
const pseudoStylesheet = node._pseudo_class[pseudoKey]
|
|
124
|
+
if (!pseudoStylesheet) continue
|
|
125
|
+
switch(pseudoKey) {
|
|
126
|
+
case "::first-child": {
|
|
127
|
+
if (node.parentNode?.firstChild?._nid === node._nid) {
|
|
128
|
+
return pseudoStylesheet.hmStyle
|
|
129
|
+
}
|
|
130
|
+
break
|
|
131
|
+
}
|
|
132
|
+
case "::last-child": {
|
|
133
|
+
if (node.parentNode?.lastChild?._nid === node._nid) {
|
|
134
|
+
return pseudoStylesheet.hmStyle
|
|
135
|
+
}
|
|
136
|
+
break
|
|
137
|
+
}
|
|
138
|
+
case "::empty": {
|
|
139
|
+
if (node.children?.length === 0) {
|
|
140
|
+
return pseudoStylesheet.hmStyle
|
|
141
|
+
}
|
|
142
|
+
break
|
|
143
|
+
}
|
|
144
|
+
default: {
|
|
145
|
+
// 解析nth-child()
|
|
146
|
+
// 找出当前节点在父节点中的位置
|
|
147
|
+
// 公式
|
|
148
|
+
let matchs: [number, number] | null = null
|
|
149
|
+
if (pseudoKey === '::nth-child(odd)') {
|
|
150
|
+
matchs = [2, 1]
|
|
151
|
+
} else if (pseudoKey === '::nth-child(even)') {
|
|
152
|
+
matchs = [2, 0]
|
|
153
|
+
} else {
|
|
154
|
+
matchs = parseNthChild(pseudoKey)
|
|
155
|
+
}
|
|
156
|
+
if (matchs) {
|
|
157
|
+
let index = node.parentNode?.childNodes.findIndex((child) => child._nid === node._nid)
|
|
158
|
+
if (isUndefined(index)) return null
|
|
159
|
+
else {
|
|
160
|
+
index = index + 1
|
|
161
|
+
if (matchs[0] === 0) {
|
|
162
|
+
if (index === matchs[1]) {
|
|
163
|
+
return pseudoStylesheet.hmStyle
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
if ((index - matchs[1]) % matchs[0] === 0) {
|
|
167
|
+
return pseudoStylesheet.hmStyle
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
85
174
|
}
|
|
86
175
|
}
|
|
87
|
-
return
|
|
176
|
+
return null
|
|
88
177
|
}
|
|
178
|
+
|
|
179
|
+
// 正则匹配nth-child
|
|
180
|
+
function parseNthChild(selector: string): [number, number] | null {
|
|
181
|
+
const regex = /nth-child\((?:(-?\d*)n\s*)?([+-]?\s*\d+)?\)/;
|
|
182
|
+
const match = selector.match(regex);
|
|
183
|
+
|
|
184
|
+
if (match) {
|
|
185
|
+
const a = match[1] ? parseInt(match[1]) : 0;
|
|
186
|
+
const b = match[2] ? parseInt(match[2]) : 0;
|
|
187
|
+
return [a, b];
|
|
188
|
+
} else {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
export function getStyleAttr(node: TaroElement | null, key: string): TaroAny {
|
|
195
|
+
if (!node) return null
|
|
196
|
+
const hmStyle = node.hmStyle
|
|
197
|
+
if (!hmStyle) return null
|
|
198
|
+
// 覆盖属性
|
|
199
|
+
if (key === 'width') {
|
|
200
|
+
return isMaxWidthView(node) && isUndefined(hmStyle.width) ? '100%' : hmStyle.width
|
|
201
|
+
}
|
|
202
|
+
return hmStyle[key]
|
|
203
|
+
}
|
|
@@ -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 {
|
|
5
|
+
import { shouldBindEvent, getNodeThresholds } from './utils/helper'
|
|
5
6
|
|
|
6
|
-
import type {
|
|
7
|
+
import type { TaroAny, TaroVideoElement, TaroEvent } from '@tarojs/runtime'
|
|
7
8
|
|
|
8
9
|
export interface VideoOptions {
|
|
9
10
|
src?: string | Resource
|
|
@@ -21,37 +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
|
-
.padding(style.padding)
|
|
29
|
-
.margin(style.margin)
|
|
30
|
-
.width(style.width)
|
|
31
|
-
.height(style.height)
|
|
32
|
-
.constraintSize(style.constraintSize)
|
|
33
|
-
.flexGrow(style.flexGrow)
|
|
34
|
-
.flexShrink(style.flexShrink)
|
|
35
|
-
.flexBasis(style.flexBasis)
|
|
36
|
-
.alignSelf(style.alignSelf)
|
|
37
|
-
.backgroundColor(style.backgroundColor)
|
|
38
|
-
.backgroundImage(style.backgroundImage, style.backgroundRepeat)
|
|
39
|
-
.backgroundImageSize(style.backgroundImageSize)
|
|
40
|
-
.backgroundImagePosition(style.backgroundImagePosition)
|
|
41
|
-
.rotate(style.rotate)
|
|
42
|
-
.scale(style.scale)
|
|
43
|
-
.translate(style.translate)
|
|
44
|
-
.transform(style.transform)
|
|
45
|
-
.borderStyle(style.borderStyle)
|
|
46
|
-
.borderWidth(style.borderWidth)
|
|
47
|
-
.borderColor(style.borderColor)
|
|
48
|
-
.borderRadius(style.borderRadius)
|
|
49
|
-
.linearGradient(style.linearGradient)
|
|
50
|
-
.zIndex(style.zIndex)
|
|
51
|
-
.opacity(style.opacity)
|
|
52
|
-
.clip(style.clip)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
25
|
@Extend(Video)
|
|
56
26
|
function props(attr: VideoAttrs) {
|
|
57
27
|
.muted(attr.muted)
|
|
@@ -103,30 +73,43 @@ function getVideoProps (node: TaroVideoElement): VideoAttrs {
|
|
|
103
73
|
}
|
|
104
74
|
|
|
105
75
|
function handleUpdate (node: TaroVideoElement, e: VideoUpdateEvent) {
|
|
106
|
-
node._currentTime = e.time
|
|
76
|
+
node._nodeInfo._currentTime = e.time
|
|
107
77
|
|
|
108
78
|
emitEvent(node, 'timeUpdate', { currentTime: e.time})
|
|
109
79
|
}
|
|
110
80
|
|
|
111
|
-
@
|
|
112
|
-
export default
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
.
|
|
127
|
-
.
|
|
128
|
-
.
|
|
129
|
-
|
|
81
|
+
@Component
|
|
82
|
+
export default struct TaroVideo {
|
|
83
|
+
@Builder customBuilder() {}
|
|
84
|
+
@BuilderParam createLazyChildren: (node: TaroVideoElement) => 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]
|
|
130
111
|
}))
|
|
131
|
-
.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
|
+
|
|
132
115
|
}
|