@tarojs/plugin-platform-harmony-ets 3.7.0-alpha.27
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/LICENSE +160 -0
- package/dist/apis/apis.ts +15 -0
- package/dist/apis/base/index.ts +5 -0
- package/dist/apis/base/system.ts +77 -0
- package/dist/apis/device/accelerometer.ts +76 -0
- package/dist/apis/device/battery.ts +24 -0
- package/dist/apis/device/clipboard.ts +70 -0
- package/dist/apis/device/index.ts +9 -0
- package/dist/apis/device/keyboard.ts +62 -0
- package/dist/apis/device/memory.ts +4 -0
- package/dist/apis/device/network.ts +72 -0
- package/dist/apis/device/phone.ts +43 -0
- package/dist/apis/device/screen.ts +79 -0
- package/dist/apis/device/vibrate.ts +24 -0
- package/dist/apis/files/index.ts +135 -0
- package/dist/apis/files/manager.ts +941 -0
- package/dist/apis/framework/index.ts +32 -0
- package/dist/apis/index.ts +124 -0
- package/dist/apis/location/index.ts +133 -0
- package/dist/apis/media/common.ts +74 -0
- package/dist/apis/media/image.ts +122 -0
- package/dist/apis/media/index.ts +3 -0
- package/dist/apis/media/video.ts +86 -0
- package/dist/apis/navigate/index.ts +8 -0
- package/dist/apis/network/downloadFile.ts +113 -0
- package/dist/apis/network/index.ts +4 -0
- package/dist/apis/network/request.ts +113 -0
- package/dist/apis/network/uploadFile.ts +158 -0
- package/dist/apis/network/webSocket.ts +130 -0
- package/dist/apis/open-api/index.ts +7 -0
- package/dist/apis/open-api/user-info/index.ts +85 -0
- package/dist/apis/page/index.ts +92 -0
- package/dist/apis/route/index.ts +138 -0
- package/dist/apis/storage/index.ts +133 -0
- package/dist/apis/tabbar/index.ts +147 -0
- package/dist/apis/ui/animation.ts +222 -0
- package/dist/apis/ui/background.ts +35 -0
- package/dist/apis/ui/index.ts +14 -0
- package/dist/apis/ui/interaction/index.ts +195 -0
- package/dist/apis/ui/navigation-bar/index.ts +33 -0
- package/dist/apis/ui/pull-down-refresh.ts +41 -0
- package/dist/apis/utils/handler.ts +116 -0
- package/dist/apis/utils/index.ts +85 -0
- package/dist/apis/utils/types.ts +12 -0
- package/dist/apis/utils/validate.ts +87 -0
- package/dist/apis/wxml/IntersectionObserver.ts +119 -0
- package/dist/apis/wxml/index.ts +12 -0
- package/dist/apis/wxml/nodesRef.ts +56 -0
- package/dist/apis/wxml/selectorQuery.ts +287 -0
- package/dist/components/components-react.js +51 -0
- package/dist/components/components-react.js.map +1 -0
- package/dist/components-harmony/button/index.css +109 -0
- package/dist/components-harmony/button/index.hml +31 -0
- package/dist/components-harmony/button/index.js +105 -0
- package/dist/components-harmony/camera/index.hml +6 -0
- package/dist/components-harmony/camera/index.js +12 -0
- package/dist/components-harmony/checkbox/index.hml +11 -0
- package/dist/components-harmony/checkbox/index.js +60 -0
- package/dist/components-harmony/checkbox-group/index.hml +3 -0
- package/dist/components-harmony/checkbox-group/index.js +22 -0
- package/dist/components-harmony/cover-image/index.css +4 -0
- package/dist/components-harmony/cover-image/index.hml +9 -0
- package/dist/components-harmony/cover-image/index.js +15 -0
- package/dist/components-harmony/form/index.hml +10 -0
- package/dist/components-harmony/form/index.js +11 -0
- package/dist/components-harmony/icon/index.css +27 -0
- package/dist/components-harmony/icon/index.hml +54 -0
- package/dist/components-harmony/icon/index.js +17 -0
- package/dist/components-harmony/image/index.css +5 -0
- package/dist/components-harmony/image/index.hml +11 -0
- package/dist/components-harmony/image/index.js +28 -0
- package/dist/components-harmony/input/index.hml +21 -0
- package/dist/components-harmony/input/index.js +98 -0
- package/dist/components-harmony/label/index.hml +3 -0
- package/dist/components-harmony/label/index.js +6 -0
- package/dist/components-harmony/navbar/index.css +56 -0
- package/dist/components-harmony/navbar/index.hml +9 -0
- package/dist/components-harmony/navbar/index.js +30 -0
- package/dist/components-harmony/navigator/index.css +8 -0
- package/dist/components-harmony/navigator/index.hml +9 -0
- package/dist/components-harmony/navigator/index.js +104 -0
- package/dist/components-harmony/picker/index.hml +25 -0
- package/dist/components-harmony/picker/index.js +132 -0
- package/dist/components-harmony/picker-view/index.hml +23 -0
- package/dist/components-harmony/picker-view/index.js +161 -0
- package/dist/components-harmony/picker-view-column/index.hml +3 -0
- package/dist/components-harmony/picker-view-column/index.js +3 -0
- package/dist/components-harmony/progress/index.css +4 -0
- package/dist/components-harmony/progress/index.hml +28 -0
- package/dist/components-harmony/progress/index.js +23 -0
- package/dist/components-harmony/radio/index.hml +11 -0
- package/dist/components-harmony/radio/index.js +41 -0
- package/dist/components-harmony/radio-group/index.hml +3 -0
- package/dist/components-harmony/radio-group/index.js +11 -0
- package/dist/components-harmony/rich-text/index.hml +5 -0
- package/dist/components-harmony/rich-text/index.js +16 -0
- package/dist/components-harmony/scroll-view/index.css +5 -0
- package/dist/components-harmony/scroll-view/index.hml +12 -0
- package/dist/components-harmony/scroll-view/index.js +65 -0
- package/dist/components-harmony/slider/index.hml +16 -0
- package/dist/components-harmony/slider/index.js +53 -0
- package/dist/components-harmony/swiper/index.css +3 -0
- package/dist/components-harmony/swiper/index.hml +14 -0
- package/dist/components-harmony/swiper/index.js +19 -0
- package/dist/components-harmony/switch/index.hml +7 -0
- package/dist/components-harmony/switch/index.js +16 -0
- package/dist/components-harmony/tabbar/index.css +7 -0
- package/dist/components-harmony/tabbar/index.hml +26 -0
- package/dist/components-harmony/tabbar/index.js +42 -0
- package/dist/components-harmony/textarea/index.hml +24 -0
- package/dist/components-harmony/textarea/index.js +92 -0
- package/dist/components-harmony/utils/index.js +41 -0
- package/dist/components-harmony/video/index.hml +7 -0
- package/dist/components-harmony/video/index.js +73 -0
- package/dist/components-harmony/web-view/index.hml +8 -0
- package/dist/components-harmony/web-view/index.js +22 -0
- package/dist/components-harmony-ets/base.ets +63 -0
- package/dist/components-harmony-ets/button.ets +119 -0
- package/dist/components-harmony-ets/checkbox.ets +219 -0
- package/dist/components-harmony-ets/element.ets +223 -0
- package/dist/components-harmony-ets/form.ets +149 -0
- package/dist/components-harmony-ets/icon.ets +84 -0
- package/dist/components-harmony-ets/image.ets +85 -0
- package/dist/components-harmony-ets/index.ts +49 -0
- package/dist/components-harmony-ets/innerHtml.ets +79 -0
- package/dist/components-harmony-ets/input.ets +195 -0
- package/dist/components-harmony-ets/label.ets +111 -0
- package/dist/components-harmony-ets/picker.ets +370 -0
- package/dist/components-harmony-ets/radio.ets +225 -0
- package/dist/components-harmony-ets/richText.ets +97 -0
- package/dist/components-harmony-ets/scrollView.ets +199 -0
- package/dist/components-harmony-ets/slider.ets +159 -0
- package/dist/components-harmony-ets/swiper.ets +204 -0
- package/dist/components-harmony-ets/switch.ets +113 -0
- package/dist/components-harmony-ets/text.ets +97 -0
- package/dist/components-harmony-ets/textArea.ets +169 -0
- package/dist/components-harmony-ets/utils/AttributeManager.ets +250 -0
- package/dist/components-harmony-ets/utils/DynamicCenter.ts +48 -0
- package/dist/components-harmony-ets/utils/constant/event.ets +25 -0
- package/dist/components-harmony-ets/utils/constant/icon.ts +19 -0
- package/dist/components-harmony-ets/utils/constant/style.ets +88 -0
- package/dist/components-harmony-ets/utils/events.ts +24 -0
- package/dist/components-harmony-ets/utils/flexManager.ets +107 -0
- package/dist/components-harmony-ets/utils/helper.ets +99 -0
- package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +103 -0
- package/dist/components-harmony-ets/utils/htmlParser/index.ts +56 -0
- package/dist/components-harmony-ets/utils/index.ts +83 -0
- package/dist/components-harmony-ets/utils/styles.ets +91 -0
- package/dist/components-harmony-ets/video.ets +161 -0
- package/dist/components-harmony-ets/view.ets +79 -0
- package/dist/index.js +1183 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime-ets/bom/document.ts +38 -0
- package/dist/runtime-ets/bom/getComputedStyle.ts +5 -0
- package/dist/runtime-ets/bom/navigator.ts +21 -0
- package/dist/runtime-ets/bom/raf.ts +37 -0
- package/dist/runtime-ets/bom/window.ts +44 -0
- package/dist/runtime-ets/constant.ts +29 -0
- package/dist/runtime-ets/current.ts +16 -0
- package/dist/runtime-ets/dom/class-list.ts +117 -0
- package/dist/runtime-ets/dom/comment.ts +10 -0
- package/dist/runtime-ets/dom/cssStyleDeclaration.ts +105 -0
- package/dist/runtime-ets/dom/document.ts +108 -0
- package/dist/runtime-ets/dom/element.ts +457 -0
- package/dist/runtime-ets/dom/event.ts +164 -0
- package/dist/runtime-ets/dom/eventTarget.ts +98 -0
- package/dist/runtime-ets/dom/node.ts +215 -0
- package/dist/runtime-ets/dom/stylesheet/index.ts +687 -0
- package/dist/runtime-ets/dom/stylesheet/type.ts +136 -0
- package/dist/runtime-ets/dom/stylesheet/util.ts +134 -0
- package/dist/runtime-ets/dom/text.ts +19 -0
- package/dist/runtime-ets/index.ts +19 -0
- package/dist/runtime-ets/interface/event.ts +9 -0
- package/dist/runtime-ets/interface/index.ts +1 -0
- package/dist/runtime-ets/utils/bind.ts +35 -0
- package/dist/runtime-ets/utils/index.ts +135 -0
- package/dist/runtime-ets/utils/info.ts +128 -0
- package/dist/runtime-framework/react/app.ts +256 -0
- package/dist/runtime-framework/react/connect.ts +24 -0
- package/dist/runtime-framework/react/constant.ts +5 -0
- package/dist/runtime-framework/react/hooks.ts +101 -0
- package/dist/runtime-framework/react/index.ts +16 -0
- package/dist/runtime-framework/react/page.ts +263 -0
- package/dist/runtime-framework/react/utils/index.ts +25 -0
- package/dist/runtime-framework/react/utils/is.ts +46 -0
- package/dist/runtime-framework/solid/README.md +99 -0
- package/dist/runtime-framework/solid/app.ts +200 -0
- package/dist/runtime-framework/solid/connect.ts +11 -0
- package/dist/runtime-framework/solid/contant.ts +5 -0
- package/dist/runtime-framework/solid/hooks.ts +88 -0
- package/dist/runtime-framework/solid/index.ts +10 -0
- package/dist/runtime-framework/solid/page.ts +202 -0
- package/dist/runtime-framework/solid/reconciler/h.ts +132 -0
- package/dist/runtime-framework/solid/reconciler/index.ts +3 -0
- package/dist/runtime-framework/solid/reconciler/props.ts +151 -0
- package/dist/runtime-framework/solid/reconciler/render.ts +61 -0
- package/dist/runtime-framework/solid/reconciler/use.ts +8 -0
- package/dist/runtime-framework/solid/utils/index.ts +49 -0
- package/dist/runtime-framework/solid/utils/is.ts +46 -0
- package/dist/runtime-utils.js +4149 -0
- package/dist/runtime-utils.js.map +1 -0
- package/dist/runtime.js +4150 -0
- package/dist/runtime.js.map +1 -0
- package/dist/template/container.js +7 -0
- package/index.js +4 -0
- package/package.json +54 -0
- package/types/api.d.ts +4 -0
- package/types/component.d.ts +4 -0
- package/types/harmony.d.ts +11 -0
- package/types/runtime.d.ts +15 -0
- package/types/taro.d.ts +7 -0
- package/types/webpack-sources.d.ts +108 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
|
|
3
|
+
export type TTreeNode = {
|
|
4
|
+
type: string
|
|
5
|
+
name?: string
|
|
6
|
+
content?: string
|
|
7
|
+
attributes?: Record<string, string>
|
|
8
|
+
children?: TTreeNode[]
|
|
9
|
+
endIndex?: number
|
|
10
|
+
selfClosing?: boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function parseHTML(htmlString: string): TTreeNode[] {
|
|
14
|
+
const stack: TTreeNode[] = []
|
|
15
|
+
let current: TTreeNode
|
|
16
|
+
let index = 0
|
|
17
|
+
const jsonTree: TTreeNode[] = []
|
|
18
|
+
|
|
19
|
+
while (index < htmlString.length) {
|
|
20
|
+
const char = htmlString[index]
|
|
21
|
+
|
|
22
|
+
if (char === '<') {
|
|
23
|
+
const tag = parseTag(htmlString, index)
|
|
24
|
+
if (tag.type === 'open') {
|
|
25
|
+
const element: TTreeNode = {
|
|
26
|
+
type: 'element',
|
|
27
|
+
name: tag.name,
|
|
28
|
+
attributes: tag.attributes,
|
|
29
|
+
children: [],
|
|
30
|
+
}
|
|
31
|
+
if (!current) {
|
|
32
|
+
jsonTree.push(element)
|
|
33
|
+
} else {
|
|
34
|
+
current.children?.push(element)
|
|
35
|
+
}
|
|
36
|
+
if (!tag.selfClosing) {
|
|
37
|
+
stack.push(current!)
|
|
38
|
+
current = element
|
|
39
|
+
}
|
|
40
|
+
} else if (tag.type === 'close') {
|
|
41
|
+
if (stack.length > 0) {
|
|
42
|
+
current = stack.pop()
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
index = tag.endIndex + 1
|
|
46
|
+
} else {
|
|
47
|
+
const endIndex = htmlString.indexOf('<', index)
|
|
48
|
+
const text = htmlString.slice(index, endIndex !== -1 ? endIndex : undefined)
|
|
49
|
+
if (text.trim() !== '') {
|
|
50
|
+
current.children?.push({ type: 'text', content: text })
|
|
51
|
+
}
|
|
52
|
+
index = endIndex !== -1 ? endIndex : htmlString.length
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return jsonTree
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function parseTag(htmlString, startIndex) {
|
|
60
|
+
let index = startIndex
|
|
61
|
+
const tag: TTreeNode = {
|
|
62
|
+
type: '',
|
|
63
|
+
name: '',
|
|
64
|
+
attributes: {},
|
|
65
|
+
selfClosing: false,
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Skip '<'
|
|
69
|
+
index++
|
|
70
|
+
|
|
71
|
+
if (htmlString[index] === '/') {
|
|
72
|
+
tag.type = 'close'
|
|
73
|
+
index++
|
|
74
|
+
} else {
|
|
75
|
+
tag.type = 'open'
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Parse tag name
|
|
79
|
+
tag.name = htmlString.slice(index).match(/^\s*([^/\s>]+)/)[1]
|
|
80
|
+
index += tag.name.length
|
|
81
|
+
|
|
82
|
+
// Parse attributes
|
|
83
|
+
let attrMatch
|
|
84
|
+
while ((attrMatch = htmlString.slice(index).match(/^\s+([^=]+)="([^"]*)"/))) {
|
|
85
|
+
const [, attr, value] = attrMatch
|
|
86
|
+
tag.attributes[attr] = value
|
|
87
|
+
index += attrMatch[0].length
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (htmlString[index] === '/' || htmlString[index + 1] === '/') {
|
|
91
|
+
tag.selfClosing = true
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Skip '>'
|
|
95
|
+
index = htmlString.indexOf('>', index) + 1
|
|
96
|
+
|
|
97
|
+
tag.endIndex = index - 1
|
|
98
|
+
|
|
99
|
+
return tag
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
export default parseHTML
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { document, TaroElement } from '@tarojs/runtime'
|
|
2
|
+
|
|
3
|
+
import parseHTML, { TTreeNode } from './HarmonyHTMLParser'
|
|
4
|
+
|
|
5
|
+
// 构建harmony的dom树
|
|
6
|
+
function buildDomTree(dom: TTreeNode) {
|
|
7
|
+
const { name, attributes, children } = dom
|
|
8
|
+
let tagName = ''
|
|
9
|
+
// TODO: 仍需补充更多节点解析和它默认样式行为的转换,比如h1\h2
|
|
10
|
+
switch (name) {
|
|
11
|
+
case 'root': tagName = 'view'; break
|
|
12
|
+
case 'img': tagName = 'image'; break
|
|
13
|
+
case 'div': tagName = 'view'; break
|
|
14
|
+
case 'p': tagName = 'text'; break
|
|
15
|
+
case 'span': tagName = 'text'; break
|
|
16
|
+
}
|
|
17
|
+
if (!tagName) return null
|
|
18
|
+
|
|
19
|
+
const ele = document.createElement(tagName)
|
|
20
|
+
attributes && Object.keys(attributes).forEach(key => {
|
|
21
|
+
if (key === 'style') {
|
|
22
|
+
ele.style.cssText = attributes[key]
|
|
23
|
+
} else {
|
|
24
|
+
ele.setAttribute(key, attributes[key])
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
if (children && children.length) {
|
|
29
|
+
children.forEach(child => {
|
|
30
|
+
let childEle
|
|
31
|
+
if (child.type === 'element') {
|
|
32
|
+
childEle = buildDomTree(child)
|
|
33
|
+
} else if (child.type === 'text') {
|
|
34
|
+
childEle = document.createTextNode(child.content)
|
|
35
|
+
}
|
|
36
|
+
childEle && ele.appendChild(childEle)
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
return ele
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 净化常见错别标签如:<br> <hr>
|
|
43
|
+
function fixBrokenTags(htmlString) {
|
|
44
|
+
const selfClosingTags = ['br', 'hr']
|
|
45
|
+
// 匹配容易忘记闭合的标签
|
|
46
|
+
const pattern = new RegExp(`<(${selfClosingTags.join('|')})\\b[^>]*>`, 'gi')
|
|
47
|
+
// 修复匹配到的标签
|
|
48
|
+
const fixedHTML = htmlString.replace(pattern, '<$1/>')
|
|
49
|
+
return fixedHTML
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export default function htmlParser(htmlString: string): TaroElement {
|
|
53
|
+
htmlString = fixBrokenTags(htmlString)
|
|
54
|
+
const trees = parseHTML(`<root>${htmlString}</root>`)
|
|
55
|
+
return buildDomTree(trees[0])
|
|
56
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { convertNumber2VP } from '@tarojs/runtime'
|
|
2
|
+
import { isNumber } from '@tarojs/shared'
|
|
3
|
+
|
|
4
|
+
export function getSingleSelector(ctx, range, rangeKey): any[] {
|
|
5
|
+
return range.map((data) => data[rangeKey])
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function getMultiSelector(ctx, range, rangeKey, value) {
|
|
9
|
+
return range.map((arr, arrIndex) => arr.map((data, i) => {
|
|
10
|
+
const columnValue = value[arrIndex]
|
|
11
|
+
if (columnValue === data) {
|
|
12
|
+
ctx.showSelector[arrIndex] = i
|
|
13
|
+
}
|
|
14
|
+
if (rangeKey && typeof range[0][0] === 'object') {
|
|
15
|
+
return data[rangeKey]
|
|
16
|
+
}
|
|
17
|
+
return data
|
|
18
|
+
}))
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function getUnit (val) {
|
|
22
|
+
if (/\d+(vp)$/.test(val)) {
|
|
23
|
+
return val
|
|
24
|
+
} else if (isNumber(val) || /\d+px$/.test(val)) {
|
|
25
|
+
return convertNumber2VP(parseFloat(val))
|
|
26
|
+
}
|
|
27
|
+
return val
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function handleNodeStyleData (dataValue: string, handler: (values: string[]) => { [key: string]: string } | void) {
|
|
31
|
+
let res: any = {}
|
|
32
|
+
if (dataValue) {
|
|
33
|
+
const values = dataValue.trim().split(/\s+/)
|
|
34
|
+
const data = handler(values)
|
|
35
|
+
|
|
36
|
+
if (!data) return res
|
|
37
|
+
|
|
38
|
+
res = data
|
|
39
|
+
|
|
40
|
+
Object.keys(res).forEach(key => {
|
|
41
|
+
const exec = `${res[key]}`.match(/(\d+)(px)$/)
|
|
42
|
+
if (exec && values.length > 1) {
|
|
43
|
+
res[key] = getUnit(+exec[1])
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return res
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function getNodeBorderRadiusData (dataValue: string) {
|
|
52
|
+
return handleNodeStyleData(dataValue, values => {
|
|
53
|
+
switch (values.length) {
|
|
54
|
+
case 1:
|
|
55
|
+
return { topLeft: values[0], topRight: values[0], bottomRight: values[0], bottomLeft: values[0] }
|
|
56
|
+
case 2:
|
|
57
|
+
return { topLeft: values[0], topRight: values[1], bottomRight: values[0], bottomLeft: values[1] }
|
|
58
|
+
case 3:
|
|
59
|
+
return { topLeft: values[0], topRight: values[1], bottomRight: values[2], bottomLeft: values[1] }
|
|
60
|
+
case 4:
|
|
61
|
+
return { topLeft: values[0], topRight: values[1], bottomRight: values[2], bottomLeft: values[3] }
|
|
62
|
+
default:
|
|
63
|
+
break
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function getNodeMarginOrPaddingData (dataValue: string) {
|
|
69
|
+
return handleNodeStyleData(dataValue, values => {
|
|
70
|
+
switch (values.length) {
|
|
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
|
+
})
|
|
83
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ObjectAssign } from '@tarojs/runtime'
|
|
2
|
+
|
|
3
|
+
import { AttributeManager } from './AttributeManager'
|
|
4
|
+
import { TEXT_DEFAULT_STYLE } from './constant/style'
|
|
5
|
+
|
|
6
|
+
import type { TaroAny, TaroElement, TaroStyleType, TaroTextStyleType, HarmonyType, HarmonyStyle } from '@tarojs/runtime'
|
|
7
|
+
import type { StandardProps } from '@tarojs/components/types'
|
|
8
|
+
|
|
9
|
+
export function getFontAttributes (node: TaroElement): TaroTextStyleType {
|
|
10
|
+
const hmStyle = node.hmStyle
|
|
11
|
+
|
|
12
|
+
const attributes: TaroAny = {
|
|
13
|
+
maxLines: hmStyle.maxLines || Infinity,
|
|
14
|
+
// 已做处理的属性
|
|
15
|
+
letterSpacing: hmStyle.letterSpacing,
|
|
16
|
+
textAlign: hmStyle.textAlign,
|
|
17
|
+
textOverflow: hmStyle.textOverflow
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return attributes
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getNormalAttributes (node: TaroElement): TaroStyleType {
|
|
24
|
+
const hmStyle = node.hmStyle
|
|
25
|
+
|
|
26
|
+
const _nid = node._nid
|
|
27
|
+
const _attrs: StandardProps = node._attrs || {}
|
|
28
|
+
|
|
29
|
+
const transform: TaroAny = hmStyle.transform
|
|
30
|
+
const transformRotate: HarmonyType.Transform.Rotate = transform?.rotate?.[0]
|
|
31
|
+
const transformTranslate: HarmonyType.Transform.Translate = transform?.translate?.[0]
|
|
32
|
+
const transformScale: HarmonyType.Transform.Scale = transform?.scale?.[0]
|
|
33
|
+
const transformTransform: HarmonyType.Transform.Transform = transform?.transform?.[0]
|
|
34
|
+
|
|
35
|
+
let normalAttributes: HarmonyStyle = {
|
|
36
|
+
// Flex相关
|
|
37
|
+
flexBasis: hmStyle.flexBasis,
|
|
38
|
+
flexGrow: hmStyle.flexGrow,
|
|
39
|
+
flexShrink: hmStyle.flexShrink,
|
|
40
|
+
alignSelf: hmStyle.alignSelf,
|
|
41
|
+
// 尺寸相关
|
|
42
|
+
width: hmStyle.width,
|
|
43
|
+
height: hmStyle.height,
|
|
44
|
+
constraintSize: hmStyle.constraintSize,
|
|
45
|
+
margin: hmStyle.margin,
|
|
46
|
+
padding: hmStyle.padding,
|
|
47
|
+
// 边框相关
|
|
48
|
+
borderStyle: hmStyle.borderStyle,
|
|
49
|
+
borderWidth: hmStyle.borderWidth,
|
|
50
|
+
borderColor: hmStyle.borderColor,
|
|
51
|
+
borderRadius: hmStyle.borderRadius,
|
|
52
|
+
// 背景相关
|
|
53
|
+
backgroundColor: hmStyle.backgroundColor,
|
|
54
|
+
backgroundImage: hmStyle.backgroundImage,
|
|
55
|
+
backgroundImageSize: hmStyle.backgroundImageSize,
|
|
56
|
+
backgroundRepeat: hmStyle.backgroundRepeat,
|
|
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
|
+
// focus: _attrs.focus || false,
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
const id = node._nid
|
|
79
|
+
const component: TaroAny = node._instance
|
|
80
|
+
|
|
81
|
+
// taro_page 等写死在运行时里的节点,没有 _instance
|
|
82
|
+
if (component) {
|
|
83
|
+
const overwriteStyle: TaroStyleType = component.nodeInfoMap[id].overwriteStyle
|
|
84
|
+
|
|
85
|
+
// 处理覆盖属性:如动画的覆盖
|
|
86
|
+
if (overwriteStyle) {
|
|
87
|
+
normalAttributes = ObjectAssign(normalAttributes, overwriteStyle)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return normalAttributes
|
|
91
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { bindInstanceToNode, AREA_CHANGE_EVENT_NAME, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME, initComponentNodeInfo, getPageScrollerOrNode,
|
|
2
|
+
TaroEvent, TaroAny } from '@tarojs/runtime'
|
|
3
|
+
|
|
4
|
+
import TaroComponentWrapper from './base'
|
|
5
|
+
import { TOUCH_EVENT_MAP } from './utils/constant/event'
|
|
6
|
+
import { createTaroEvent } from './utils/events'
|
|
7
|
+
import { getNormalAttributes, shouldBindEvent, getNodeThresholds, bindAnimation } from './utils/helper'
|
|
8
|
+
|
|
9
|
+
import type { TaroVideoElement } from './element'
|
|
10
|
+
import type { TaroStyleType } from '@tarojs/runtime'
|
|
11
|
+
|
|
12
|
+
export interface VideoOptions {
|
|
13
|
+
src?: string | Resource
|
|
14
|
+
previewUri?: string |PixelMap | Resource
|
|
15
|
+
controller?: VideoController
|
|
16
|
+
}
|
|
17
|
+
export interface VideoAttrs {
|
|
18
|
+
muted?: boolean
|
|
19
|
+
controls?: boolean
|
|
20
|
+
autoPlay?: boolean
|
|
21
|
+
loop?: boolean
|
|
22
|
+
objectFit?: ImageFit
|
|
23
|
+
}
|
|
24
|
+
export interface VideoUpdateEvent {
|
|
25
|
+
time: number
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@Extend(Video)
|
|
29
|
+
function attrs (style: TaroStyleType) {
|
|
30
|
+
.id(style.id)
|
|
31
|
+
.key(style.id)
|
|
32
|
+
.padding(style.padding)
|
|
33
|
+
.margin(style.margin)
|
|
34
|
+
.width(style.width)
|
|
35
|
+
.height(style.height)
|
|
36
|
+
.constraintSize(style.constraintSize)
|
|
37
|
+
.flexGrow(style.flexGrow)
|
|
38
|
+
.flexShrink(style.flexShrink)
|
|
39
|
+
.flexBasis(style.flexBasis)
|
|
40
|
+
.alignSelf(style.alignSelf)
|
|
41
|
+
.backgroundColor(style.backgroundColor)
|
|
42
|
+
.backgroundImage(style.backgroundImage, style.backgroundRepeat)
|
|
43
|
+
.backgroundImageSize(style.backgroundImageSize)
|
|
44
|
+
.rotate(style.rotate)
|
|
45
|
+
.scale(style.scale)
|
|
46
|
+
.translate(style.translate)
|
|
47
|
+
.transform(style.transform)
|
|
48
|
+
.borderStyle(style.borderStyle)
|
|
49
|
+
.borderWidth(style.borderWidth)
|
|
50
|
+
.borderColor(style.borderColor)
|
|
51
|
+
.borderRadius(style.borderRadius)
|
|
52
|
+
.linearGradient(style.linearGradient)
|
|
53
|
+
.zIndex(style.zIndex)
|
|
54
|
+
.opacity(style.opacity)
|
|
55
|
+
.clip(style.clip)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@Extend(Video)
|
|
59
|
+
function props(attr: VideoAttrs) {
|
|
60
|
+
.muted(attr.muted)
|
|
61
|
+
.autoPlay(attr.autoPlay)
|
|
62
|
+
.controls(attr.controls)
|
|
63
|
+
.objectFit(attr.objectFit)
|
|
64
|
+
.loop(attr.loop)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@Component
|
|
68
|
+
export default struct TaroVideo {
|
|
69
|
+
nodeInfoMap: TaroAny = {}
|
|
70
|
+
|
|
71
|
+
@Styles visibleChangeEvent () {
|
|
72
|
+
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@ObjectLink node: TaroVideoElement
|
|
76
|
+
|
|
77
|
+
controller: VideoController = new VideoController()
|
|
78
|
+
|
|
79
|
+
aboutToAppear () {
|
|
80
|
+
initComponentNodeInfo(this, this.node)
|
|
81
|
+
bindInstanceToNode(this.node, this)
|
|
82
|
+
// 绑定动画
|
|
83
|
+
bindAnimation(this.node)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@Styles defaultEvent () {
|
|
87
|
+
.onClick((e: ClickEvent) => {
|
|
88
|
+
eventHandler(e, 'click', this.node)
|
|
89
|
+
})
|
|
90
|
+
.onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
|
|
91
|
+
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, res => {
|
|
92
|
+
const eventResult: TaroAny = res.eventResult
|
|
93
|
+
this.nodeInfoMap[this.node._nid].areaInfo = eventResult[1]
|
|
94
|
+
}))
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
emitEvent = (type: string, detail?: TaroAny) => {
|
|
98
|
+
const event: TaroEvent = createTaroEvent(type, { detail }, this.node)
|
|
99
|
+
event.stopPropagation()
|
|
100
|
+
eventHandler(event, type, this.node)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
getVideoData (): VideoOptions {
|
|
105
|
+
const src = this.node._attrs.src
|
|
106
|
+
const poster = this.node._attrs.poster
|
|
107
|
+
return {
|
|
108
|
+
src,
|
|
109
|
+
previewUri: poster,
|
|
110
|
+
controller: this.controller
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
getObjectFit () {
|
|
115
|
+
switch (this.node._attrs.objectFit) {
|
|
116
|
+
case 'contain': return ImageFit.Contain
|
|
117
|
+
case 'cover': return ImageFit.Cover
|
|
118
|
+
case 'fill': return ImageFit.Fill
|
|
119
|
+
default: return ImageFit.Contain
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
getVideoProps (): VideoAttrs {
|
|
124
|
+
const muted: boolean = this.node._attrs.muted || false
|
|
125
|
+
const autoPlay: boolean = this.node._attrs.autoplay || false
|
|
126
|
+
const controls: boolean = this.node._attrs.controls || false
|
|
127
|
+
const objectFit: ImageFit = this.getObjectFit()
|
|
128
|
+
const loop: boolean = this.node._attrs.loop || false
|
|
129
|
+
return {
|
|
130
|
+
muted,
|
|
131
|
+
controls,
|
|
132
|
+
objectFit,
|
|
133
|
+
loop,
|
|
134
|
+
autoPlay
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
handleUpdate (e: VideoUpdateEvent) {
|
|
139
|
+
this.nodeInfoMap[this.node._nid].currentTime = e.time
|
|
140
|
+
this.emitEvent('timeUpdate', { currentTime: e.time})
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
build() {
|
|
144
|
+
TaroComponentWrapper({ node: this.node }) {
|
|
145
|
+
Video(this.getVideoData())
|
|
146
|
+
.attrs(getNormalAttributes(this.node))
|
|
147
|
+
.props(this.getVideoProps())
|
|
148
|
+
.defaultEvent()
|
|
149
|
+
.visibleChangeEvent()
|
|
150
|
+
.onStart(shouldBindEvent(() => { this.emitEvent('play') }, this.node, ['play']))
|
|
151
|
+
.onPause(shouldBindEvent(() => { this.emitEvent('pause') }, this.node, ['pause']))
|
|
152
|
+
.onFinish(shouldBindEvent(() => { this.emitEvent('ended') }, this.node, ['ended']))
|
|
153
|
+
.onError(shouldBindEvent(() => { this.emitEvent('error') }, this.node, ['error']))
|
|
154
|
+
.onUpdate((e) => { this.handleUpdate(e) })
|
|
155
|
+
.onPrepared(shouldBindEvent((e: TaroAny) => { this.emitEvent('loadedMetaData', { duration: e.duration }) }, this.node, ['loadedmetadata']))
|
|
156
|
+
.onSeeking(shouldBindEvent((e: TaroAny) => { this.emitEvent('seeking', { duration: e.time }) }, this.node, ['seeking']))
|
|
157
|
+
.onSeeked(shouldBindEvent(() => { this.emitEvent('seeked') }, this.node, ['seeked']))
|
|
158
|
+
.onFullscreenChange(shouldBindEvent((e: TaroAny) => { this.emitEvent('fullScreenChange', { fullScreen: e.fullscreen}) }, this.node, ['fullscreenchange']))
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { bindInstanceToNode, eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, initComponentNodeInfo, TaroAny } from '@tarojs/runtime'
|
|
2
|
+
|
|
3
|
+
import { createNode } from './render'
|
|
4
|
+
import TaroComponentWrapper from './base'
|
|
5
|
+
import { TOUCH_EVENT_MAP } from './utils/constant/event'
|
|
6
|
+
import { FlexManager } from './utils/FlexManager'
|
|
7
|
+
import { getNodeThresholds, getNormalAttributes, shouldBindEvent, bindAnimation } from './utils/helper'
|
|
8
|
+
|
|
9
|
+
import type { TaroViewElement, TaroElement } from './element'
|
|
10
|
+
import type { TaroStyleType } from '@tarojs/runtime'
|
|
11
|
+
|
|
12
|
+
@Extend(Flex)
|
|
13
|
+
function attrs (style: TaroStyleType) {
|
|
14
|
+
.id(style.id)
|
|
15
|
+
.key(style.id)
|
|
16
|
+
.padding(style.padding)
|
|
17
|
+
.margin(style.margin)
|
|
18
|
+
.width(style.width)
|
|
19
|
+
.height(style.height)
|
|
20
|
+
.constraintSize(style.constraintSize)
|
|
21
|
+
.flexGrow(style.flexGrow)
|
|
22
|
+
.flexShrink(style.flexShrink)
|
|
23
|
+
.flexBasis(style.flexBasis)
|
|
24
|
+
.alignSelf(style.alignSelf)
|
|
25
|
+
.backgroundColor(style.backgroundColor)
|
|
26
|
+
.backgroundImage(style.backgroundImage, style.backgroundRepeat)
|
|
27
|
+
.backgroundImageSize(style.backgroundImageSize)
|
|
28
|
+
.rotate(style.rotate)
|
|
29
|
+
.scale(style.scale)
|
|
30
|
+
.translate(style.translate)
|
|
31
|
+
.transform(style.transform)
|
|
32
|
+
.borderStyle(style.borderStyle)
|
|
33
|
+
.borderWidth(style.borderWidth)
|
|
34
|
+
.borderColor(style.borderColor)
|
|
35
|
+
.borderRadius(style.borderRadius)
|
|
36
|
+
.linearGradient(style.linearGradient)
|
|
37
|
+
.zIndex(style.zIndex)
|
|
38
|
+
.opacity(style.opacity)
|
|
39
|
+
.clip(style.clip)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Component
|
|
43
|
+
export default struct TaroView {
|
|
44
|
+
nodeInfoMap: TaroAny = {}
|
|
45
|
+
|
|
46
|
+
@Styles visibleChangeEvent () {
|
|
47
|
+
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@ObjectLink node: TaroViewElement
|
|
51
|
+
|
|
52
|
+
aboutToAppear () {
|
|
53
|
+
initComponentNodeInfo(this, this.node)
|
|
54
|
+
bindInstanceToNode(this.node, this)
|
|
55
|
+
// 绑定动画
|
|
56
|
+
bindAnimation(this.node)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@Styles defaultEvent () {
|
|
60
|
+
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
|
|
61
|
+
.onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
|
|
62
|
+
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, res => {
|
|
63
|
+
const eventResult: TaroAny = res.eventResult
|
|
64
|
+
this.nodeInfoMap[this.node._nid].areaInfo = eventResult[1]
|
|
65
|
+
}))
|
|
66
|
+
}
|
|
67
|
+
build() {
|
|
68
|
+
TaroComponentWrapper({ node: this.node }) {
|
|
69
|
+
Flex(FlexManager.flexOptions(this.node)) {
|
|
70
|
+
ForEach(this.node.childNodes, (item: TaroElement) => {
|
|
71
|
+
createNode(item)
|
|
72
|
+
}, (item: TaroElement) => item._nid)
|
|
73
|
+
}
|
|
74
|
+
.attrs(getNormalAttributes(this.node))
|
|
75
|
+
.defaultEvent()
|
|
76
|
+
.visibleChangeEvent()
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|