@tarojs/plugin-platform-harmony-cpp 4.1.0 → 4.1.1-alpha.1
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/README.md +0 -7
- package/dist/index.js +1236 -0
- package/dist/runtime/apis/apis.ts +20 -0
- package/dist/runtime/apis/base/crypto.ts +4 -0
- package/dist/runtime/apis/base/debug.ts +5 -0
- package/dist/runtime/apis/base/index.ts +13 -0
- package/dist/runtime/apis/base/performance.ts +8 -0
- package/dist/runtime/apis/base/system.ts +181 -0
- package/dist/runtime/apis/base/update.ts +5 -0
- package/dist/runtime/apis/base/weapp/app-event.ts +75 -0
- package/dist/runtime/apis/base/weapp/life-cycle.ts +21 -0
- package/dist/runtime/apis/canvas/index.ts +27 -0
- package/dist/runtime/apis/data-analysis/index.ts +6 -0
- package/dist/runtime/apis/device/accelerometer.ts +79 -0
- package/dist/runtime/apis/device/accessibility.ts +4 -0
- package/dist/runtime/apis/device/battery.ts +24 -0
- package/dist/runtime/apis/device/bluetooth-ble.ts +19 -0
- package/dist/runtime/apis/device/bluetooth-peripheral.ts +6 -0
- package/dist/runtime/apis/device/bluetooth.ts +16 -0
- package/dist/runtime/apis/device/calendar.ts +5 -0
- package/dist/runtime/apis/device/clipboard.ts +85 -0
- package/dist/runtime/apis/device/compass.ts +21 -0
- package/dist/runtime/apis/device/contact.ts +5 -0
- package/dist/runtime/apis/device/crypto.ts +4 -0
- package/dist/runtime/apis/device/gyroscope.ts +77 -0
- package/dist/runtime/apis/device/iBeacon.ts +10 -0
- package/dist/runtime/apis/device/index.ts +24 -0
- package/dist/runtime/apis/device/keyboard.ts +63 -0
- package/dist/runtime/apis/device/memory.ts +11 -0
- package/dist/runtime/apis/device/motion.ts +6 -0
- package/dist/runtime/apis/device/network.ts +123 -0
- package/dist/runtime/apis/device/nfc.ts +10 -0
- package/dist/runtime/apis/device/phone.ts +44 -0
- package/dist/runtime/apis/device/scan.ts +4 -0
- package/dist/runtime/apis/device/screen.ts +80 -0
- package/dist/runtime/apis/device/sms.ts +4 -0
- package/dist/runtime/apis/device/vibrate.ts +32 -0
- package/dist/runtime/apis/device/wifi.ts +15 -0
- package/dist/runtime/apis/ext/index.ts +5 -0
- package/dist/runtime/apis/files/index.ts +136 -0
- package/dist/runtime/apis/files/manager.ts +942 -0
- package/dist/runtime/apis/framework/index.ts +48 -0
- package/dist/runtime/apis/harmony/task-pool.ts +39 -0
- package/dist/runtime/apis/index.ts +61 -0
- package/dist/runtime/apis/location/index.ts +133 -0
- package/dist/runtime/apis/media/EditorContext.ts +32 -0
- package/dist/runtime/apis/media/audio/index.ts +36 -0
- package/dist/runtime/apis/media/background-audio/index.ts +16 -0
- package/dist/runtime/apis/media/camera.ts +16 -0
- package/dist/runtime/apis/media/common.ts +58 -0
- package/dist/runtime/apis/media/image/index.ts +291 -0
- package/dist/runtime/apis/media/index.ts +13 -0
- package/dist/runtime/apis/media/live.ts +5 -0
- package/dist/runtime/apis/media/map.ts +4 -0
- package/dist/runtime/apis/media/media-recorder.ts +4 -0
- package/dist/runtime/apis/media/recorder.ts +6 -0
- package/dist/runtime/apis/media/video/VideoContext.ts +67 -0
- package/dist/runtime/apis/media/video/index.ts +45 -0
- package/dist/runtime/apis/media/video-decoder.ts +4 -0
- package/dist/runtime/apis/media/video-processing.ts +4 -0
- package/dist/runtime/apis/media/voip.ts +19 -0
- package/dist/runtime/apis/navigate/index.ts +8 -0
- package/dist/runtime/apis/network/downloadFile.ts +85 -0
- package/dist/runtime/apis/network/index.ts +7 -0
- package/dist/runtime/apis/network/mdns.ts +13 -0
- package/dist/runtime/apis/network/request.ts +140 -0
- package/dist/runtime/apis/network/tcp.ts +4 -0
- package/dist/runtime/apis/network/udp.ts +4 -0
- package/dist/runtime/apis/network/uploadFile.ts +105 -0
- package/dist/runtime/apis/network/webSocket.ts +126 -0
- package/dist/runtime/apis/open-api/account.ts +4 -0
- package/dist/runtime/apis/open-api/address.ts +4 -0
- package/dist/runtime/apis/open-api/authorize.ts +5 -0
- package/dist/runtime/apis/open-api/card.ts +5 -0
- package/dist/runtime/apis/open-api/channels-live.ts +11 -0
- package/dist/runtime/apis/open-api/customer-service.ts +4 -0
- package/dist/runtime/apis/open-api/device-voip.ts +5 -0
- package/dist/runtime/apis/open-api/facial.ts +7 -0
- package/dist/runtime/apis/open-api/favorites.ts +5 -0
- package/dist/runtime/apis/open-api/group.ts +4 -0
- package/dist/runtime/apis/open-api/index.ts +21 -0
- package/dist/runtime/apis/open-api/invoice.ts +5 -0
- package/dist/runtime/apis/open-api/license-plate.ts +4 -0
- package/dist/runtime/apis/open-api/login.ts +6 -0
- package/dist/runtime/apis/open-api/my-miniprogram.ts +4 -0
- package/dist/runtime/apis/open-api/privacy.ts +7 -0
- package/dist/runtime/apis/open-api/red-package.ts +4 -0
- package/dist/runtime/apis/open-api/settings.ts +5 -0
- package/dist/runtime/apis/open-api/soter.ts +6 -0
- package/dist/runtime/apis/open-api/subscribe-message.ts +6 -0
- package/dist/runtime/apis/open-api/user-info.ts +70 -0
- package/dist/runtime/apis/open-api/werun.ts +5 -0
- package/dist/runtime/apis/payment/index.ts +6 -0
- package/dist/runtime/apis/route/index.ts +88 -0
- package/dist/runtime/apis/share/index.ts +33 -0
- package/dist/runtime/apis/storage/background-fetch.ts +7 -0
- package/dist/runtime/apis/storage/cache-manager.ts +4 -0
- package/dist/runtime/apis/storage/index.ts +203 -0
- package/dist/runtime/apis/ui/animation/animation.ts +264 -0
- package/dist/runtime/apis/ui/animation/index.ts +7 -0
- package/dist/runtime/apis/ui/background.ts +20 -0
- package/dist/runtime/apis/ui/custom-component.ts +1 -0
- package/dist/runtime/apis/ui/fonts.ts +4 -0
- package/dist/runtime/apis/ui/index.ts +12 -0
- package/dist/runtime/apis/ui/interaction/index.ts +198 -0
- package/dist/runtime/apis/ui/menu.ts +4 -0
- package/dist/runtime/apis/ui/navigation-bar/index.ts +72 -0
- package/dist/runtime/apis/ui/pull-down-refresh.ts +47 -0
- package/dist/runtime/apis/ui/scroll/index.ts +82 -0
- package/dist/runtime/apis/ui/sticky.ts +4 -0
- package/dist/runtime/apis/ui/tab-bar.ts +144 -0
- package/dist/runtime/apis/ui/window.ts +20 -0
- package/dist/runtime/apis/utils/constant.ts +1 -0
- package/dist/runtime/apis/utils/handler.ts +117 -0
- package/dist/runtime/apis/utils/index.ts +105 -0
- package/dist/runtime/apis/utils/permissions.ts +6 -0
- package/dist/runtime/apis/utils/types.ts +12 -0
- package/dist/runtime/apis/utils/unit.ts +104 -0
- package/dist/runtime/apis/utils/validate.ts +87 -0
- package/dist/runtime/apis/worker/index.ts +4 -0
- package/dist/runtime/apis/wxml/index.ts +17 -0
- package/dist/runtime/apis/wxml/intersectionObserver.ts +100 -0
- package/dist/runtime/apis/wxml/nodesRef.ts +58 -0
- package/dist/runtime/apis/wxml/selectorQuery.ts +221 -0
- package/dist/runtime/apischunk/index.d.ts +802 -0
- package/dist/runtime/apischunk/index.js +5054 -0
- package/dist/runtime/components/deprecated.ets +43 -0
- package/dist/runtime/components/index.ets +49 -0
- package/dist/runtime/components/innerHtml.ets +16 -0
- package/dist/runtime/components/navigationBar.ets +65 -0
- package/dist/runtime/components/pageMeta.ets +94 -0
- package/dist/runtime/components/richText.ets +24 -0
- package/dist/runtime/components/slider.ets +119 -0
- package/dist/runtime/components/style.ets +286 -0
- package/dist/runtime/components/switch.ets +73 -0
- package/dist/runtime/components/tag.ts +58 -0
- package/dist/runtime/components/utils/AttributeManager.ets +252 -0
- package/dist/runtime/components/utils/DynamicCenter.ts +41 -0
- package/dist/runtime/components/utils/constant/event.ets +25 -0
- package/dist/runtime/components/utils/constant/style.ets +91 -0
- package/dist/runtime/components/utils/events.ts +26 -0
- package/dist/runtime/components/utils/flexManager.ets +49 -0
- package/dist/runtime/components/utils/helper.ets +51 -0
- package/dist/runtime/components/utils/htmlParser/HarmonyHTMLParser.ts +100 -0
- package/dist/runtime/components/utils/htmlParser/index.ts +58 -0
- package/dist/runtime/components/utils/index.ts +77 -0
- package/dist/runtime/components/utils/styles.ets +41 -0
- package/dist/runtime/components/video.ets +119 -0
- package/dist/runtime/components/webView.ets +55 -0
- package/dist/runtime/components/xComponent.ets +89 -0
- package/dist/runtime/framework/app.ts +248 -0
- package/dist/runtime/framework/connect.ts +24 -0
- package/dist/runtime/framework/constant.ts +3 -0
- package/dist/runtime/framework/hooks.ts +99 -0
- package/dist/runtime/framework/index.ts +15 -0
- package/dist/runtime/framework/native-page.ts +511 -0
- package/dist/runtime/framework/page.ts +256 -0
- package/dist/runtime/framework/utils/index.ts +17 -0
- package/dist/runtime/framework/utils/is.ts +26 -0
- package/dist/runtime/framework-reconciler/componentTree.ts +81 -0
- package/dist/runtime/framework-reconciler/constant.ts +86 -0
- package/dist/runtime/framework-reconciler/domInput.ts +90 -0
- package/dist/runtime/framework-reconciler/event.ts +108 -0
- package/dist/runtime/framework-reconciler/index.ts +99 -0
- package/dist/runtime/framework-reconciler/inputValueTracking.ts +106 -0
- package/dist/runtime/framework-reconciler/props.ts +132 -0
- package/dist/runtime/framework-reconciler/reconciler.ts +202 -0
- package/dist/runtime/framework-reconciler/render.ts +139 -0
- package/dist/runtime/framework-reconciler/workTags.ts +53 -0
- package/dist/runtime/runtime-cpp/bom/URL.ts +2 -0
- package/dist/runtime/runtime-cpp/bom/document.ts +45 -0
- package/dist/runtime/runtime-cpp/bom/history.ts +1 -0
- package/dist/runtime/runtime-cpp/bom/location.ts +1 -0
- package/dist/runtime/runtime-cpp/bom/navigator.ts +1 -0
- package/dist/runtime/runtime-cpp/bom/raf.ts +1 -0
- package/dist/runtime/runtime-cpp/bom/window.ts +57 -0
- package/dist/runtime/runtime-cpp/constant.ts +29 -0
- package/dist/runtime/runtime-cpp/current.ts +48 -0
- package/dist/runtime/runtime-cpp/dom/class-list.ts +41 -0
- package/dist/runtime/runtime-cpp/dom/comment.ts +9 -0
- package/dist/runtime/runtime-cpp/dom/dataSource.ts +87 -0
- package/dist/runtime/runtime-cpp/dom/document.ts +113 -0
- package/dist/runtime/runtime-cpp/dom/element/canvas.ts +285 -0
- package/dist/runtime/runtime-cpp/dom/element/element.ts +262 -0
- package/dist/runtime/runtime-cpp/dom/element/form.ts +371 -0
- package/dist/runtime/runtime-cpp/dom/element/index.ts +129 -0
- package/dist/runtime/runtime-cpp/dom/element/movable.ts +250 -0
- package/dist/runtime/runtime-cpp/dom/element/normal.ts +123 -0
- package/dist/runtime/runtime-cpp/dom/element/scroll_view.ts +32 -0
- package/dist/runtime/runtime-cpp/dom/element/text.ts +9 -0
- package/dist/runtime/runtime-cpp/dom/element/video.ts +66 -0
- package/dist/runtime/runtime-cpp/dom/element/web_view.ts +72 -0
- package/dist/runtime/runtime-cpp/dom/event-source.ts +1 -0
- package/dist/runtime/runtime-cpp/dom/event.ts +187 -0
- package/dist/runtime/runtime-cpp/dom/eventTarget.ts +81 -0
- package/dist/runtime/runtime-cpp/dom/node.ts +307 -0
- package/dist/runtime/runtime-cpp/dom/style.ts +44 -0
- package/dist/runtime/runtime-cpp/dom/stylesheet/index.ts +379 -0
- package/dist/runtime/runtime-cpp/dom/stylesheet/type.ts +212 -0
- package/dist/runtime/runtime-cpp/dom/stylesheet/util.ts +186 -0
- package/dist/runtime/runtime-cpp/emitter/emitter.ts +29 -0
- package/dist/runtime/runtime-cpp/env.ts +1 -0
- package/dist/runtime/runtime-cpp/harmony-library.ts +1 -0
- package/dist/runtime/runtime-cpp/index.ts +79 -0
- package/dist/runtime/runtime-cpp/interface/event.ts +10 -0
- package/dist/runtime/runtime-cpp/interface/index.ts +7 -0
- package/dist/runtime/runtime-cpp/next-tick.ts +14 -0
- package/dist/runtime/runtime-cpp/system.ts +213 -0
- package/dist/runtime/runtime-cpp/utils/index.ts +63 -0
- package/dist/runtime/runtime-cpp/utils/info.ts +123 -0
- package/dist/runtime/runtime-cpp/utils/page.ts +12 -0
- package/dist/runtime/runtime-cpp/utils/router.ts +1 -0
- package/dist/runtime/runtime-harmony/apis/helper.ets +33 -0
- package/dist/runtime/runtime-harmony/apis/network/common.ets +41 -0
- package/dist/runtime/runtime-harmony/apis/network/downloadFile.ets +327 -0
- package/dist/runtime/runtime-harmony/apis/network/index.ets +58 -0
- package/dist/runtime/runtime-harmony/apis/network/request.ets +206 -0
- package/dist/runtime/runtime-harmony/apis/network/uploadFile.ets +190 -0
- package/dist/runtime/runtime-harmony/apis/route.ets +110 -0
- package/dist/runtime/runtime-harmony/apis/taskpool.ets +149 -0
- package/dist/runtime/runtime-harmony/index.ets +41 -0
- package/dist/runtime/runtime-harmony/utils.ts +53 -0
- package/package.json +25 -23
- package/static/@taro-oh/library-4.1.1-alpha.0.har +0 -0
- package/LICENSE +0 -174
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
export type TTreeNode = {
|
|
2
|
+
type: string
|
|
3
|
+
name?: string
|
|
4
|
+
content?: string
|
|
5
|
+
attributes?: Record<string, string>
|
|
6
|
+
children?: TTreeNode[]
|
|
7
|
+
endIndex?: number
|
|
8
|
+
selfClosing?: boolean
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function parseHTML(htmlString: string): TTreeNode[] {
|
|
12
|
+
const stack: TTreeNode[] = []
|
|
13
|
+
let current: TTreeNode
|
|
14
|
+
let index = 0
|
|
15
|
+
const jsonTree: TTreeNode[] = []
|
|
16
|
+
|
|
17
|
+
while (index < htmlString.length) {
|
|
18
|
+
const char = htmlString[index]
|
|
19
|
+
|
|
20
|
+
if (char === '<') {
|
|
21
|
+
const tag = parseTag(htmlString, index)
|
|
22
|
+
if (tag.type === 'open') {
|
|
23
|
+
const element: TTreeNode = {
|
|
24
|
+
type: 'element',
|
|
25
|
+
name: tag.name,
|
|
26
|
+
attributes: tag.attributes,
|
|
27
|
+
children: [],
|
|
28
|
+
}
|
|
29
|
+
if (!current!) {
|
|
30
|
+
jsonTree.push(element)
|
|
31
|
+
} else {
|
|
32
|
+
current.children?.push(element)
|
|
33
|
+
}
|
|
34
|
+
if (!tag.selfClosing) {
|
|
35
|
+
stack.push(current!)
|
|
36
|
+
current = element
|
|
37
|
+
}
|
|
38
|
+
} else if (tag.type === 'close') {
|
|
39
|
+
if (stack.length > 0) {
|
|
40
|
+
current = stack.pop()!
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
index = tag.endIndex! + 1
|
|
44
|
+
} else {
|
|
45
|
+
const endIndex = htmlString.indexOf('<', index)
|
|
46
|
+
const text = htmlString.slice(index, endIndex !== -1 ? endIndex : undefined)
|
|
47
|
+
if (text.trim() !== '') {
|
|
48
|
+
current!.children?.push({ type: 'text', content: text })
|
|
49
|
+
}
|
|
50
|
+
index = endIndex !== -1 ? endIndex : htmlString.length
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return jsonTree
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function parseTag(htmlString, startIndex) {
|
|
58
|
+
let index = startIndex
|
|
59
|
+
const tag: TTreeNode = {
|
|
60
|
+
type: '',
|
|
61
|
+
name: '',
|
|
62
|
+
attributes: {},
|
|
63
|
+
selfClosing: false,
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Skip '<'
|
|
67
|
+
index++
|
|
68
|
+
|
|
69
|
+
if (htmlString[index] === '/') {
|
|
70
|
+
tag.type = 'close'
|
|
71
|
+
index++
|
|
72
|
+
} else {
|
|
73
|
+
tag.type = 'open'
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Parse tag name
|
|
77
|
+
tag.name = htmlString.slice(index).match(/^\s*([^/\s>]+)/)[1] || ''
|
|
78
|
+
index += tag.name!.length
|
|
79
|
+
|
|
80
|
+
// Parse attributes
|
|
81
|
+
let attrMatch
|
|
82
|
+
while ((attrMatch = htmlString.slice(index).match(/^\s+([^=]+)="([^"]*)"/))) {
|
|
83
|
+
const [, attr, value] = attrMatch
|
|
84
|
+
tag.attributes![attr] = value
|
|
85
|
+
index += attrMatch[0].length
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (htmlString[index] === '/' || htmlString[index + 1] === '/') {
|
|
89
|
+
tag.selfClosing = true
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Skip '>'
|
|
93
|
+
index = htmlString.indexOf('>', index) + 1
|
|
94
|
+
|
|
95
|
+
tag.endIndex = index - 1
|
|
96
|
+
|
|
97
|
+
return tag
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export default parseHTML
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { document } from '@tarojs/runtime'
|
|
2
|
+
|
|
3
|
+
import parseHTML, { TTreeNode } from './HarmonyHTMLParser'
|
|
4
|
+
|
|
5
|
+
import type { TaroElement } from '@tarojs/runtime'
|
|
6
|
+
|
|
7
|
+
// 构建harmony的dom树
|
|
8
|
+
function buildDomTree(dom: TTreeNode) {
|
|
9
|
+
const { name, attributes, children } = dom
|
|
10
|
+
let tagName = ''
|
|
11
|
+
// TODO: 仍需补充更多节点解析和它默认样式行为的转换,比如h1\h2
|
|
12
|
+
switch (name) {
|
|
13
|
+
case 'root': tagName = 'view'; break
|
|
14
|
+
case 'img': tagName = 'image'; break
|
|
15
|
+
case 'div': tagName = 'view'; break
|
|
16
|
+
case 'p': tagName = 'text'; break
|
|
17
|
+
case 'span': tagName = 'text'; break
|
|
18
|
+
}
|
|
19
|
+
if (!tagName) return null
|
|
20
|
+
|
|
21
|
+
const ele = document.createElement(tagName)
|
|
22
|
+
attributes && Object.keys(attributes).forEach(key => {
|
|
23
|
+
if (key === 'style') {
|
|
24
|
+
ele.style.cssText = attributes[key]
|
|
25
|
+
} else {
|
|
26
|
+
ele.setAttribute(key, attributes[key])
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
if (children && children.length) {
|
|
31
|
+
children.forEach(child => {
|
|
32
|
+
let childEle
|
|
33
|
+
if (child.type === 'element') {
|
|
34
|
+
childEle = buildDomTree(child)
|
|
35
|
+
} else if (child.type === 'text') {
|
|
36
|
+
childEle = document.createTextNode(child.content!)
|
|
37
|
+
}
|
|
38
|
+
childEle && ele.appendChild(childEle)
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
return ele
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// 净化常见错别标签如:<br> <hr>
|
|
45
|
+
function fixBrokenTags(htmlString) {
|
|
46
|
+
const selfClosingTags = ['br', 'hr']
|
|
47
|
+
// 匹配容易忘记闭合的标签
|
|
48
|
+
const pattern = new RegExp(`<(${selfClosingTags.join('|')})\\b[^>]*>`, 'gi')
|
|
49
|
+
// 修复匹配到的标签
|
|
50
|
+
const fixedHTML = htmlString.replace(pattern, '<$1/>')
|
|
51
|
+
return fixedHTML
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default function htmlParser(htmlString: string): TaroElement | null {
|
|
55
|
+
htmlString = fixBrokenTags(htmlString)
|
|
56
|
+
const trees = parseHTML(`<root>${htmlString}</root>`)
|
|
57
|
+
return buildDomTree(trees[0])
|
|
58
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { isUndefined } from '@tarojs/shared'
|
|
2
|
+
|
|
3
|
+
import type { RichTextProps } from '@tarojs/components/types/RichText'
|
|
4
|
+
import type { TaroRichTextElement } from '@tarojs/runtime'
|
|
5
|
+
|
|
6
|
+
export function getSingleSelector(range, rangeKey): any[] {
|
|
7
|
+
return range.map((data) => data[rangeKey])
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function getMultiSelector(ctx, range, rangeKey, value) {
|
|
11
|
+
return range.map((arr, arrIndex) => arr.map((data, i) => {
|
|
12
|
+
const columnValue = value[arrIndex]
|
|
13
|
+
if (columnValue === data) {
|
|
14
|
+
ctx.showSelector[arrIndex] = i
|
|
15
|
+
}
|
|
16
|
+
if (rangeKey && typeof range[0][0] === 'object') {
|
|
17
|
+
return data[rangeKey]
|
|
18
|
+
}
|
|
19
|
+
return data
|
|
20
|
+
}))
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function generateText (node: TaroRichTextElement): string {
|
|
24
|
+
return parseHtmlNode(node._attrs.nodes || '')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// 将nodeTree转换成harmony需要的string结构
|
|
28
|
+
function nodeToHtml(node: RichTextProps.Text | RichTextProps.HTMLElement): string {
|
|
29
|
+
if (node.type === 'text') {
|
|
30
|
+
return node.text
|
|
31
|
+
}
|
|
32
|
+
if (node.attrs) {
|
|
33
|
+
const attributes = Object.entries(node.attrs)
|
|
34
|
+
.map((item: [string, string]) => `${item[0]}="${item[1]}"`)
|
|
35
|
+
.join(' ')
|
|
36
|
+
const childrenHtml: string = typeof node.children === 'string' ? node.children : (node.children || []).map((child: RichTextProps.Text | RichTextProps.HTMLElement) => nodeToHtml(child)).join('')
|
|
37
|
+
return `<${node.name}${attributes ? ' ' + attributes : ''}>${childrenHtml}</${node.name}>`
|
|
38
|
+
}
|
|
39
|
+
return ''
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function parseHtmlNode (nodes: Array<RichTextProps.Text | RichTextProps.HTMLElement> | string) {
|
|
43
|
+
return typeof nodes === 'string' ? nodes : `<div>${nodes.map(node => nodeToHtml(node)).join('')}</div>`
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 背景偏移算法:https://developer.mozilla.org/zh-CN/docs/Web/CSS/background-position
|
|
47
|
+
export function computeBackgroundPosition(style) {
|
|
48
|
+
let offsetX = style.backgroundPosition?.x || 0
|
|
49
|
+
let offsetY = style.backgroundPosition?.y || 0
|
|
50
|
+
if (style.backgroundSize && typeof style.backgroundSize !== 'number') {
|
|
51
|
+
if (!isUndefined(style.backgroundSize.width) && style.width) {
|
|
52
|
+
if (typeof style.backgroundPosition.x === 'string' && style.backgroundPosition.x.indexOf('%') > 0) {
|
|
53
|
+
// (container width - image width) * (position x%) = (x offset value)
|
|
54
|
+
const width = parseFloat(style.width)
|
|
55
|
+
const bgWidth = parseFloat(style.backgroundSize.width)
|
|
56
|
+
const bgOffsetX = parseFloat(style.backgroundPosition.x)
|
|
57
|
+
offsetX = Number((width - bgWidth) * (bgOffsetX) / 100) || 0
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (!isUndefined(style.backgroundSize.height) && style.height) {
|
|
61
|
+
if (typeof style.backgroundPosition.y === 'string' && style.backgroundPosition.y.indexOf('%') > 0) {
|
|
62
|
+
// (container height - image height) * (position y%) = (y offset value)
|
|
63
|
+
const height = parseFloat(style.height)
|
|
64
|
+
const bgHeight = parseFloat(style.backgroundSize.height)
|
|
65
|
+
const bgOffsetY = parseFloat(style.backgroundPosition.y)
|
|
66
|
+
offsetY = Number((height - bgHeight) * (bgOffsetY) / 100) || 0
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return { offsetX, offsetY }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function convertVp2Px(val: string | number) {
|
|
75
|
+
const vp = parseFloat(`${val}`)
|
|
76
|
+
return vp2px(vp)
|
|
77
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { isUndefined } from '@tarojs/shared'
|
|
2
|
+
import { ObjectAssign } from '@tarojs/runtime'
|
|
3
|
+
|
|
4
|
+
import { FlexManager } from './flexManager'
|
|
5
|
+
|
|
6
|
+
import type { StandardProps, TextProps } from '@tarojs/components/types'
|
|
7
|
+
import type { TaroAny, TaroElement, TaroTextStyleType, HarmonyStyle } from '@tarojs/runtime'
|
|
8
|
+
|
|
9
|
+
export function getFontAttributes (node: TaroElement): TaroAny {
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// 模拟 div 自动撑满父元素的情况
|
|
13
|
+
export function isMaxWidthView (node: TaroElement) {
|
|
14
|
+
const parentNode: TaroElement = node.parentNode as TaroElement
|
|
15
|
+
|
|
16
|
+
return node.tagName === 'VIEW' && parentNode && parentNode.tagName === 'VIEW' && !FlexManager.isFlexNode(parentNode)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getNormalAttributes (node: TaroElement, initStyle?: HarmonyStyle): HarmonyStyle {
|
|
20
|
+
if (!node) return {}
|
|
21
|
+
|
|
22
|
+
const hmStyle: TaroAny = node.hmStyle
|
|
23
|
+
if (!hmStyle) return {}
|
|
24
|
+
|
|
25
|
+
const _nid = node._nid
|
|
26
|
+
const _attrs: StandardProps = node._attrs || {}
|
|
27
|
+
|
|
28
|
+
let normalAttributes: TaroAny = hmStyle
|
|
29
|
+
|
|
30
|
+
// 覆盖属性
|
|
31
|
+
normalAttributes.id = _attrs.id || _nid.toString()
|
|
32
|
+
|
|
33
|
+
// 初始化默认的值
|
|
34
|
+
if (initStyle) {
|
|
35
|
+
normalAttributes = ObjectAssign({}, initStyle, normalAttributes)
|
|
36
|
+
}
|
|
37
|
+
return normalAttributes
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function getStyleAttr(node: TaroElement | null, key: string): TaroAny {
|
|
41
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { audio } from '@kit.AudioKit'
|
|
2
|
+
import { AREA_CHANGE_EVENT_NAME, Current, createTaroEvent, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME } from '@tarojs/runtime'
|
|
3
|
+
|
|
4
|
+
import commonStyleModify from './style'
|
|
5
|
+
import { shouldBindEvent, getNodeThresholds } from './utils/helper'
|
|
6
|
+
|
|
7
|
+
import type { TaroAny, TaroEvent, TaroVideoElement } from '@tarojs/runtime'
|
|
8
|
+
|
|
9
|
+
export interface VideoUpdateEvent {
|
|
10
|
+
time: number
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function emitEvent (node: TaroVideoElement, type: string, detail?: TaroAny) {
|
|
14
|
+
const event: TaroEvent = createTaroEvent(type, { detail }, node)
|
|
15
|
+
|
|
16
|
+
event.stopPropagation()
|
|
17
|
+
eventHandler(event, type, node)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function handleUpdate (node: TaroVideoElement, e: VideoUpdateEvent) {
|
|
21
|
+
node._nodeInfo._currentTime = e.time
|
|
22
|
+
|
|
23
|
+
emitEvent(node, 'timeUpdate', { currentTime: e.time})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@ComponentV2
|
|
27
|
+
export default struct TaroVideo {
|
|
28
|
+
@Builder customBuilder() {}
|
|
29
|
+
@BuilderParam createLazyChildren: (node: TaroVideoElement) => void = this.customBuilder
|
|
30
|
+
@Param @Require node: TaroVideoElement
|
|
31
|
+
controller: VideoController = new VideoController()
|
|
32
|
+
|
|
33
|
+
@Local attrSrc: string = ''
|
|
34
|
+
@Local attrPoster: string = ''
|
|
35
|
+
@Local attrAutoplay: boolean = false
|
|
36
|
+
@Local attrControls: boolean = false
|
|
37
|
+
@Local attrLoop: boolean = false
|
|
38
|
+
@Local attrMuted: boolean = false
|
|
39
|
+
@Local attrObjectFit: string = ''
|
|
40
|
+
|
|
41
|
+
@Computed get computedObjectFit () {
|
|
42
|
+
switch (this.attrObjectFit) {
|
|
43
|
+
case 'contain': return ImageFit.Contain
|
|
44
|
+
case 'cover': return ImageFit.Cover
|
|
45
|
+
case 'fill': return ImageFit.Fill
|
|
46
|
+
default: return ImageFit.Contain
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
aboutToAppear(): void {
|
|
51
|
+
if (this.node) {
|
|
52
|
+
this.node._instance = this
|
|
53
|
+
this.node.controller = this.controller
|
|
54
|
+
this.attrSrc = this.node._attrs.src ?? this.attrSrc
|
|
55
|
+
this.attrPoster = this.node._attrs.poster ?? this.attrPoster
|
|
56
|
+
this.attrAutoplay = this.node._attrs.autoplay ?? this.attrAutoplay
|
|
57
|
+
this.attrControls = this.node._attrs.controls ?? this.attrControls
|
|
58
|
+
this.attrLoop = this.node._attrs.loop ?? this.attrLoop
|
|
59
|
+
this.attrMuted = this.node._attrs.muted ?? this.attrMuted
|
|
60
|
+
this.attrObjectFit = this.node._attrs.objectFit ?? this.attrObjectFit
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
refreshAudioSession() {
|
|
65
|
+
if (Current.audioSessionManager) {
|
|
66
|
+
const manager: audio.AudioSessionManager = Current.audioSessionManager
|
|
67
|
+
if (manager.isAudioSessionActivated()) {
|
|
68
|
+
manager.deactivateAudioSession().then(() => {
|
|
69
|
+
let strategy: audio.AudioSessionStrategy = {
|
|
70
|
+
concurrencyMode: audio.AudioConcurrencyMode.CONCURRENCY_PAUSE_OTHERS
|
|
71
|
+
}
|
|
72
|
+
manager.activateAudioSession(strategy)
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
aboutToDisappear(): void {
|
|
79
|
+
setTimeout(() => {
|
|
80
|
+
this.refreshAudioSession()
|
|
81
|
+
}, 200)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
build () {
|
|
85
|
+
Video({
|
|
86
|
+
src: this.attrSrc,
|
|
87
|
+
previewUri: this.attrPoster,
|
|
88
|
+
controller: this.node.controller
|
|
89
|
+
})
|
|
90
|
+
.attributeModifier(commonStyleModify.setNode(this.node))
|
|
91
|
+
.muted(this.attrMuted || false)
|
|
92
|
+
.autoPlay(this.attrAutoplay || false)
|
|
93
|
+
.controls(this.attrControls || false)
|
|
94
|
+
.objectFit(this.computedObjectFit)
|
|
95
|
+
.loop(this.attrLoop || false)
|
|
96
|
+
.onStart(shouldBindEvent(() => { emitEvent(this.node, 'play') }, this.node, ['play']))
|
|
97
|
+
.onPause(() => {
|
|
98
|
+
shouldBindEvent(() => { emitEvent(this.node, 'pause') }, this.node, ['pause'])?.()
|
|
99
|
+
this.refreshAudioSession()
|
|
100
|
+
})
|
|
101
|
+
.onStop(() => {
|
|
102
|
+
this.refreshAudioSession()
|
|
103
|
+
})
|
|
104
|
+
.onFinish(() => {
|
|
105
|
+
shouldBindEvent(() => { emitEvent(this.node, 'ended') }, this.node, ['ended'])?.()
|
|
106
|
+
this.refreshAudioSession()
|
|
107
|
+
})
|
|
108
|
+
.onError(shouldBindEvent(() => { emitEvent(this.node, 'error') }, this.node, ['error']))
|
|
109
|
+
.onUpdate((e) => { handleUpdate(this.node, e) })
|
|
110
|
+
.onPrepared(shouldBindEvent((e: TaroAny) => { emitEvent(this.node, 'loadedMetaData', { duration: e.duration }) }, this.node, ['loadedmetadata']))
|
|
111
|
+
.onSeeking(shouldBindEvent((e: TaroAny) => { emitEvent(this.node, 'seeking', { duration: e.time }) }, this.node, ['seeking']))
|
|
112
|
+
.onSeeked(shouldBindEvent(() => { emitEvent(this.node, 'seeked') }, this.node, ['seeked']))
|
|
113
|
+
.onFullscreenChange(shouldBindEvent((e: TaroAny) => { emitEvent(this.node, 'fullScreenChange', { fullScreen: e.fullscreen}) }, this.node, ['fullscreenchange']))
|
|
114
|
+
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
115
|
+
this.node._nodeInfo.areaInfo = res[1]
|
|
116
|
+
}))
|
|
117
|
+
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { AREA_CHANGE_EVENT_NAME, createTaroEvent, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME } from '@tarojs/runtime'
|
|
2
|
+
|
|
3
|
+
import commonStyleModify from './style'
|
|
4
|
+
import { shouldBindEvent, getNodeThresholds } from './utils/helper'
|
|
5
|
+
|
|
6
|
+
import type { TaroAny, TaroWebViewElement, TaroEvent } from '@tarojs/runtime'
|
|
7
|
+
|
|
8
|
+
interface IPageLoad {
|
|
9
|
+
url: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface IError {
|
|
13
|
+
request: WebResourceRequest
|
|
14
|
+
error: WebResourceError
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@Component
|
|
18
|
+
export default struct TaroWebView {
|
|
19
|
+
@Builder customBuilder() {}
|
|
20
|
+
@BuilderParam createLazyChildren: (node: TaroWebViewElement, layer?: number) => void = this.customBuilder
|
|
21
|
+
@ObjectLink node: TaroWebViewElement
|
|
22
|
+
|
|
23
|
+
build () {
|
|
24
|
+
Web({ src: this.node._attrs.src, controller: this.node.controller })
|
|
25
|
+
.attributeModifier(commonStyleModify.setNode(this.node))
|
|
26
|
+
.onPageEnd((e: IPageLoad) => {
|
|
27
|
+
// 1. 创建消息端口
|
|
28
|
+
this.node.ports = this.node.controller.createWebMessagePorts(true)
|
|
29
|
+
// 2. 发送端口1到HTML5
|
|
30
|
+
this.node.controller.postMessage('init_web_messageport', [this.node.ports[1]], '*');
|
|
31
|
+
// 3. 保存端口0到本地
|
|
32
|
+
this.node.nativePort = this.node.ports[0]
|
|
33
|
+
// 4. 设置回调函数
|
|
34
|
+
this.node.nativePort.onMessageEventExt((result) => {
|
|
35
|
+
const message: TaroAny = this.node.handleMessageFromWeb(result)
|
|
36
|
+
const messageEvent: TaroEvent = createTaroEvent('message', { detail: { data: message } }, this.node)
|
|
37
|
+
|
|
38
|
+
eventHandler(messageEvent, 'message', this.node)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const onLoadEvent: TaroEvent = createTaroEvent('load', { detail: { src: this.node._attrs.src } }, this.node)
|
|
42
|
+
|
|
43
|
+
eventHandler(onLoadEvent, 'load', this.node)
|
|
44
|
+
})
|
|
45
|
+
.onErrorReceive(shouldBindEvent((e: IError) => {
|
|
46
|
+
const event: TaroEvent = createTaroEvent('error', { detail: { url: this.node._attrs.src, fullUrl: e.request.getRequestUrl() } }, this.node)
|
|
47
|
+
|
|
48
|
+
eventHandler(event, 'error', this.node)
|
|
49
|
+
}, this.node, ['error']))
|
|
50
|
+
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
51
|
+
this.node._nodeInfo.areaInfo = res[1]
|
|
52
|
+
}))
|
|
53
|
+
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Current, createEvent, createTaroEvent, eventCenter, eventHandler } from '@tarojs/runtime'
|
|
2
|
+
import { getDeviceInfo } from '@tarojs/taro'
|
|
3
|
+
|
|
4
|
+
import type { TaroAny } from '@tarojs/runtime'
|
|
5
|
+
|
|
6
|
+
const X_COMPONENT_ID_PREFIX = 'taro_x_'
|
|
7
|
+
|
|
8
|
+
Current.nativeModule.initJSCAPIBridge("js_capi_bridge", {
|
|
9
|
+
createEvent,
|
|
10
|
+
createTaroEvent,
|
|
11
|
+
eventHandler,
|
|
12
|
+
deviceInfo: getDeviceInfo(),
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
interface ILocation {
|
|
16
|
+
path: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface IRouterChangeEventFeedback {
|
|
20
|
+
toLocation?: ILocation
|
|
21
|
+
stage: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const ROUTER_STAGE = new Map<string, number>([
|
|
25
|
+
['load', 0],
|
|
26
|
+
['show', 1],
|
|
27
|
+
['hide', 2],
|
|
28
|
+
['unload', 3],
|
|
29
|
+
])
|
|
30
|
+
|
|
31
|
+
@Component
|
|
32
|
+
export struct TaroXComponent {
|
|
33
|
+
@Prop pageId: number = 0
|
|
34
|
+
@Prop path: string = ''
|
|
35
|
+
@State stage: number = 0
|
|
36
|
+
data: TaroAny = null
|
|
37
|
+
|
|
38
|
+
aboutToAppear(): void {
|
|
39
|
+
if (Current.isDebug) {
|
|
40
|
+
console.log("C-Component onAppear 使用 NAPI 调用 C++ 侧的方法", `taro_x_${this.pageId}`)
|
|
41
|
+
}
|
|
42
|
+
// FIXME Current.router 为空会导致页面切换和卸载出现问题,后续修复
|
|
43
|
+
this.path = Current.router?.path?.replace(/^\//, '')
|
|
44
|
+
eventCenter.on('__taroRouterChange', this.handleRouterChange)
|
|
45
|
+
if (Current.page?.config?.isHome) {
|
|
46
|
+
Current.taro.updatePageSync()
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
aboutToDisappear(): void {
|
|
51
|
+
if (Current.isDebug) {
|
|
52
|
+
console.log("C-Component onDisAppear 使用 NAPI 调用 C++ 侧的方法", `taro_x_${this.pageId}`)
|
|
53
|
+
}
|
|
54
|
+
if (this.stage !== ROUTER_STAGE.get('unload')) {
|
|
55
|
+
eventCenter.off('__taroRouterChange', this.handleRouterChange)
|
|
56
|
+
this.handleRouterChange({ stage: 'unload' })
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
handleRouterChange = (params: IRouterChangeEventFeedback) => {
|
|
61
|
+
if (!this.pageId || !this.path) return
|
|
62
|
+
|
|
63
|
+
if (this.path === params.toLocation?.path || (params.stage && !params.toLocation)) {
|
|
64
|
+
this.stage = ROUTER_STAGE.get(params.stage) || 0
|
|
65
|
+
Current.nativeModule.onXComponentStateChange(this.pageId, this.stage)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
build() {
|
|
70
|
+
if (this.pageId > 0) {
|
|
71
|
+
Stack() {
|
|
72
|
+
ContentSlot(this.data)
|
|
73
|
+
}
|
|
74
|
+
.id(`${X_COMPONENT_ID_PREFIX}${this.pageId}`)
|
|
75
|
+
.align(Alignment.TopStart)
|
|
76
|
+
.height('100%')
|
|
77
|
+
.width('100%')
|
|
78
|
+
.onDetach(() => {
|
|
79
|
+
if (Current.isDebug) {
|
|
80
|
+
console.log("C-Component onDetach 使用 NAPI 调用 C++ 侧的方法", `taro_x_${this.pageId}`)
|
|
81
|
+
}
|
|
82
|
+
if (this.stage !== ROUTER_STAGE.get('unload')) {
|
|
83
|
+
eventCenter.off('__taroRouterChange', this.handleRouterChange)
|
|
84
|
+
this.handleRouterChange({ stage: 'unload' })
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|