@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,187 @@
|
|
|
1
|
+
import { hooks } from '@tarojs/shared'
|
|
2
|
+
|
|
3
|
+
import { CONFIRM, CURRENT_TARGET, INPUT, KEY_CODE, TARGET, TIME_STAMP, TYPE } from '../constant'
|
|
4
|
+
import { TaroElement } from './element/element'
|
|
5
|
+
|
|
6
|
+
import type { EventOptions } from '../interface'
|
|
7
|
+
|
|
8
|
+
// Taro 事件对象。以 Web 标准的事件对象为基础,加入小程序事件对象中携带的部分信息,并模拟实现事件冒泡。
|
|
9
|
+
export class TaroEvent<T = any> {
|
|
10
|
+
public type: string
|
|
11
|
+
|
|
12
|
+
public bubbles: boolean
|
|
13
|
+
|
|
14
|
+
public cancelable: boolean
|
|
15
|
+
|
|
16
|
+
public _stop = false
|
|
17
|
+
|
|
18
|
+
public _end = false
|
|
19
|
+
|
|
20
|
+
public defaultPrevented = false
|
|
21
|
+
|
|
22
|
+
public target: TaroElement
|
|
23
|
+
|
|
24
|
+
public currentTarget: TaroElement
|
|
25
|
+
|
|
26
|
+
/** 额外的信息 */
|
|
27
|
+
public detail: T
|
|
28
|
+
|
|
29
|
+
// Mouse Event botton property, it's used in 3rd lib, like react-router. default 0 in general
|
|
30
|
+
public button = 0
|
|
31
|
+
|
|
32
|
+
// timestamp can either be hi-res ( relative to page load) or low-res (relative to UNIX epoch)
|
|
33
|
+
// here use hi-res timestamp
|
|
34
|
+
public timeStamp = Date.now()
|
|
35
|
+
|
|
36
|
+
public mpEvent: TaroEvent | undefined
|
|
37
|
+
|
|
38
|
+
public constructor (type: string, opts: EventOptions, event?: TaroEvent) {
|
|
39
|
+
this.type = type.toLowerCase()
|
|
40
|
+
this.mpEvent = event
|
|
41
|
+
this.bubbles = Boolean(opts && opts.bubbles)
|
|
42
|
+
this.cancelable = Boolean(opts && opts.cancelable)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public stopPropagation () {
|
|
46
|
+
this._stop = true
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public stopImmediatePropagation () {
|
|
50
|
+
this._end = this._stop = true
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public preventDefault () {
|
|
54
|
+
this.defaultPrevented = true
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function createEvent (event: TaroEvent | string, type?: string, node?: TaroElement) {
|
|
59
|
+
if (typeof event === 'string') {
|
|
60
|
+
// For Vue3 using document.createEvent
|
|
61
|
+
return new TaroEvent(event, { bubbles: true, cancelable: true })
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (!type) return
|
|
65
|
+
|
|
66
|
+
const domEv = new TaroEvent(type, { bubbles: true, cancelable: true }, event)
|
|
67
|
+
|
|
68
|
+
for (const key in event) {
|
|
69
|
+
if (key === CURRENT_TARGET || key === TARGET || key === TYPE || key === TIME_STAMP) {
|
|
70
|
+
continue
|
|
71
|
+
} else {
|
|
72
|
+
domEv[key] = event[key]
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (domEv.type === CONFIRM && node?.nodeName === INPUT) {
|
|
77
|
+
// eslint-disable-next-line dot-notation
|
|
78
|
+
domEv[KEY_CODE] = 13
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return domEv
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// function stopOrTriggerPropagation (event: TaroEvent, node: TaroElement) {
|
|
85
|
+
// let target = node
|
|
86
|
+
|
|
87
|
+
// // eslint-disable-next-line no-unmodified-loop-condition
|
|
88
|
+
// while ((target = target.parentNode as TaroElement)) {
|
|
89
|
+
// const listeners = target.__listeners[event.type]
|
|
90
|
+
|
|
91
|
+
// if (!Array.isArray(listeners) || target._attrs?.disabled) {
|
|
92
|
+
// continue
|
|
93
|
+
// }
|
|
94
|
+
|
|
95
|
+
// const _target = target
|
|
96
|
+
// collectBatchFunction(event.type, () => {
|
|
97
|
+
// hooks.call('dispatchTaroEvent', event, _target)
|
|
98
|
+
// })
|
|
99
|
+
// }
|
|
100
|
+
// }
|
|
101
|
+
|
|
102
|
+
// const eventsBatch = {}
|
|
103
|
+
// const BUBBLE_EVENTS = new Set([
|
|
104
|
+
// // 'touchstart', // Note: CAPI 目前没有事件捕获,暂时禁用
|
|
105
|
+
// // 'touchmove', // Note: CAPI 目前没有事件捕获,暂时禁用
|
|
106
|
+
// // 'touchend', // Note: CAPI 目前没有事件捕获,暂时禁用
|
|
107
|
+
// // 'touchcancel', // Note: CAPI 目前没有事件捕获,暂时禁用
|
|
108
|
+
// // Note: 鸿蒙当前不支持以下事件冒泡
|
|
109
|
+
// 'click',
|
|
110
|
+
// 'longtap',
|
|
111
|
+
// 'change',
|
|
112
|
+
// 'submit',
|
|
113
|
+
// 'submit-btn',
|
|
114
|
+
// 'reset-btn'
|
|
115
|
+
// ])
|
|
116
|
+
|
|
117
|
+
// function collectBatchFunction (type: string, dispatch: () => void) {
|
|
118
|
+
// if (hooks.isExist('batchedEventUpdates')) {
|
|
119
|
+
// (eventsBatch[type] ||= []).push(dispatch)
|
|
120
|
+
// } else {
|
|
121
|
+
// dispatch()
|
|
122
|
+
// }
|
|
123
|
+
// }
|
|
124
|
+
|
|
125
|
+
export function eventHandler (event, _type: string, node: TaroElement): void {
|
|
126
|
+
if (!node) return
|
|
127
|
+
|
|
128
|
+
hooks.call('dispatchTaroEvent', event, node)
|
|
129
|
+
// const isBatchUpdates = hooks.isExist('batchedEventUpdates')
|
|
130
|
+
// const e = createEvent(event, type, node)
|
|
131
|
+
|
|
132
|
+
// if (!e) return
|
|
133
|
+
|
|
134
|
+
// const dispatch = () => {
|
|
135
|
+
// e.target = e.currentTarget = node
|
|
136
|
+
|
|
137
|
+
// // hooks.call('modifyTaroEvent', e, node)
|
|
138
|
+
// hooks.call('dispatchTaroEvent', e, node)
|
|
139
|
+
|
|
140
|
+
// // BatchUpdates 时冒泡环节需要提前,因为需要收集父节点事件
|
|
141
|
+
// if (!isBatchUpdates) {
|
|
142
|
+
// stopOrTriggerPropagation(e, node)
|
|
143
|
+
// }
|
|
144
|
+
|
|
145
|
+
// // hooks.call('dispatchTaroEventFinish', e, node)
|
|
146
|
+
// }
|
|
147
|
+
|
|
148
|
+
// dispatch()
|
|
149
|
+
// if (isBatchUpdates) {
|
|
150
|
+
// // collectBatchFunction(type, dispatch)
|
|
151
|
+
|
|
152
|
+
// // 如果需要触发冒泡,则执行 stopOrTriggerPropagation
|
|
153
|
+
// if (BUBBLE_EVENTS.has(type)) {
|
|
154
|
+
// stopOrTriggerPropagation(e, node)
|
|
155
|
+
// }
|
|
156
|
+
|
|
157
|
+
// hooks.call('batchedEventUpdates', () => {
|
|
158
|
+
// if (eventsBatch[type]) {
|
|
159
|
+
// eventsBatch[type].forEach(fn => fn())
|
|
160
|
+
// delete eventsBatch[type]
|
|
161
|
+
// }
|
|
162
|
+
// })
|
|
163
|
+
// }
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function createTaroEvent(type: string, opts: Partial<EventOptions> = {}, node?: TaroElement) {
|
|
167
|
+
opts.bubbles ||= true
|
|
168
|
+
opts.cancelable ||= true
|
|
169
|
+
const e = new TaroEvent(type, opts as Required<EventOptions>)
|
|
170
|
+
|
|
171
|
+
if (node) {
|
|
172
|
+
const properties: Record<string, PropertyDescriptor> = {}
|
|
173
|
+
properties.target = properties.currentTarget = {
|
|
174
|
+
get() {
|
|
175
|
+
return node
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
Object.defineProperties(e, properties)
|
|
179
|
+
}
|
|
180
|
+
for (const key in opts) {
|
|
181
|
+
if (['bubbles', 'cancelable'].includes(key)) {
|
|
182
|
+
continue
|
|
183
|
+
}
|
|
184
|
+
e[key] = opts[key]
|
|
185
|
+
}
|
|
186
|
+
return e
|
|
187
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Events } from '../emitter/emitter'
|
|
2
|
+
import { TaroNativeModule } from '../harmony-library'
|
|
3
|
+
import { TaroEvent } from './event'
|
|
4
|
+
|
|
5
|
+
import type { EventHandler } from '../interface'
|
|
6
|
+
|
|
7
|
+
interface IOptions {
|
|
8
|
+
capture?: boolean
|
|
9
|
+
once?: boolean
|
|
10
|
+
passive?: boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type fn = (...args: any[]) => any
|
|
14
|
+
|
|
15
|
+
class TaroEventTarget extends Events {
|
|
16
|
+
__listeners: Record<string, EventHandler[]> = {}
|
|
17
|
+
|
|
18
|
+
public addEventListener (type: string, listener: fn, options?: IOptions) {
|
|
19
|
+
const once = options?.once ?? false
|
|
20
|
+
|
|
21
|
+
if (once) {
|
|
22
|
+
const wrapper = () => {
|
|
23
|
+
listener.apply(this, arguments)
|
|
24
|
+
this.removeEventListener(type, wrapper)
|
|
25
|
+
}
|
|
26
|
+
this.addEventListener(type, wrapper)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const listeners = this.__listeners[type]
|
|
30
|
+
if (Array.isArray(listeners)) {
|
|
31
|
+
listeners.push(listener)
|
|
32
|
+
} else {
|
|
33
|
+
this.__listeners[type] = [listener]
|
|
34
|
+
}
|
|
35
|
+
TaroNativeModule.registerNodeEvent(this, type, listener)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public removeEventListener (type: string, listener: fn) {
|
|
39
|
+
const listeners = this.__listeners[type]
|
|
40
|
+
if (listeners?.length) {
|
|
41
|
+
this.__listeners[type] = listeners.filter(item => item !== listener)
|
|
42
|
+
|
|
43
|
+
if (this.__listeners[type].length === 0) {
|
|
44
|
+
delete this.__listeners[type]
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
TaroNativeModule.unRegisterNodeEvent(this, type, listener)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// TODO 转成 C++ 实现
|
|
51
|
+
public dispatchEvent (event: TaroEvent) {
|
|
52
|
+
const cancelable = event.cancelable
|
|
53
|
+
const listeners = this.__listeners[event.type]
|
|
54
|
+
|
|
55
|
+
if (!Array.isArray(listeners)) {
|
|
56
|
+
return false
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
for (let i = listeners.length; i--;) {
|
|
60
|
+
const listener = listeners[i]
|
|
61
|
+
let result: unknown
|
|
62
|
+
if (listener._stop) {
|
|
63
|
+
listener._stop = false
|
|
64
|
+
} else {
|
|
65
|
+
result = listener.call(this, event)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if ((result === false || event._end) && cancelable) {
|
|
69
|
+
event.defaultPrevented = true
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (event._end && event._stop) {
|
|
73
|
+
break
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return listeners != null
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export { TaroEventTarget }
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { isString } from '@tarojs/shared'
|
|
2
|
+
|
|
3
|
+
import { TaroNativeModule } from '../harmony-library'
|
|
4
|
+
import { printInfo, runInDebug } from '../utils/info'
|
|
5
|
+
import { TaroEventTarget } from './eventTarget'
|
|
6
|
+
|
|
7
|
+
import type { TaroAny } from '../interface'
|
|
8
|
+
import type { TaroDocument } from './document'
|
|
9
|
+
import type { TaroElement } from './element/element'
|
|
10
|
+
|
|
11
|
+
const registry = new FinalizationRegistry((val) => {
|
|
12
|
+
runInDebug(() => {
|
|
13
|
+
printInfo('FinalizationRegistry', val)
|
|
14
|
+
})
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
export enum NodeType {
|
|
18
|
+
ELEMENT_NODE = 1,
|
|
19
|
+
ATTRIBUTE_NODE = 2,
|
|
20
|
+
TEXT_NODE = 3,
|
|
21
|
+
CDATA_SECTION_NODE = 4,
|
|
22
|
+
ENTITY_REFERENCE_NODE = 5,
|
|
23
|
+
PROCESSING_INSTRUCTION_NODE = 7,
|
|
24
|
+
COMMENT_NODE = 8,
|
|
25
|
+
DOCUMENT_NODE = 9,
|
|
26
|
+
DOCUMENT_TYPE_NODE = 10,
|
|
27
|
+
DOCUMENT_FRAGMENT_NODE = 11
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let _id = 0
|
|
31
|
+
function genId (): number {
|
|
32
|
+
return ++_id
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class TaroNode extends TaroEventTarget {
|
|
36
|
+
public readonly nodeName: string
|
|
37
|
+
public readonly nodeType: NodeType
|
|
38
|
+
public _nid: number = genId()
|
|
39
|
+
public _doc: TaroDocument | null = null
|
|
40
|
+
public get _instance (): TaroAny {
|
|
41
|
+
return null
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public set _instance (_) {}
|
|
45
|
+
|
|
46
|
+
private _textContent = ''
|
|
47
|
+
private _childNodes: TaroNode[] | null = null
|
|
48
|
+
private _parentNode: TaroNode | null = null
|
|
49
|
+
|
|
50
|
+
// 以下属性为原生混写组件才有意义的属性
|
|
51
|
+
public _nativeUpdateTrigger = 0
|
|
52
|
+
|
|
53
|
+
constructor(nodeName: string, nodeType = NodeType.ELEMENT_NODE) {
|
|
54
|
+
super()
|
|
55
|
+
|
|
56
|
+
this.nodeType = nodeType
|
|
57
|
+
this.nodeName = nodeName
|
|
58
|
+
registry.register(this, `nodeName: ${nodeName}; nid: ${this._nid}; nodeType: ${nodeType};`)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public getStrNid() {
|
|
62
|
+
return `n_${this._nid}`
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public getNumNid(id) {
|
|
66
|
+
return +id.slice(2)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// 提供唯一标识,方便与小程序一致,能根据uid获取到对应的节点
|
|
70
|
+
public get uid (): string {
|
|
71
|
+
return `${this._nid}`
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public get firstChild (): TaroNode | null {
|
|
75
|
+
return TaroNativeModule.getTaroNodeProperty(this, 'firstChild') || null
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public get firstElementChild (): TaroElement | null {
|
|
79
|
+
return TaroNativeModule.getTaroNodeProperty(this, 'firstElementChild') || null
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public get lastChild (): TaroNode | null {
|
|
83
|
+
return TaroNativeModule.getTaroNodeProperty(this, 'lastChild') || null
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public get lastElementChild (): TaroElement | null {
|
|
87
|
+
return TaroNativeModule.getTaroNodeProperty(this, 'lastElementChild') || null
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public get nextSibling (): TaroNode | null {
|
|
91
|
+
return TaroNativeModule.getTaroNodeProperty(this, 'nextSibling') || null
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public get previousSibling (): TaroNode | null {
|
|
95
|
+
return TaroNativeModule.getTaroNodeProperty(this, 'previousSibling') || null
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public get parentElement (): TaroElement | null {
|
|
99
|
+
return TaroNativeModule.getTaroNodeProperty(this, 'parentElement') || null
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public get textContent (): string {
|
|
103
|
+
return this._textContent || ''
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
public set textContent (value: string) {
|
|
107
|
+
// APP 节点在缓存的情况下会被手动 append 到页面上,因此 APP 不能清空内容,否则会导致页面 crash
|
|
108
|
+
if (this.nodeName === 'APP') return
|
|
109
|
+
|
|
110
|
+
if (this.nodeType === NodeType.TEXT_NODE) {
|
|
111
|
+
this._textContent = value
|
|
112
|
+
runInDebug(() => {
|
|
113
|
+
printInfo('setAttribute', 'textContent', this._nid, this.parentNode?.nodeName, this.nodeName, this._textContent)
|
|
114
|
+
})
|
|
115
|
+
TaroNativeModule.setTaroNodeAttribute(this, 'textContent', this._textContent)
|
|
116
|
+
} else if (this.nodeType === NodeType.ELEMENT_NODE) {
|
|
117
|
+
const node = new TaroTextNode(value)
|
|
118
|
+
node._doc = this.ownerDocument
|
|
119
|
+
runInDebug(() => {
|
|
120
|
+
printInfo('appendChild', 'textContent', this._nid, node._nid, this.parentNode?.nodeName, this.nodeName, value)
|
|
121
|
+
})
|
|
122
|
+
TaroNativeModule.appendTaroNode(this, node)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public get childNodes (): TaroNode[] {
|
|
127
|
+
if (this._childNodes) {
|
|
128
|
+
return this._childNodes!
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
this._childNodes = TaroNativeModule.getTaroNodeProperty(this, 'childNodes')
|
|
132
|
+
|
|
133
|
+
return this._childNodes! || []
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
public get parentNode (): TaroNode | null {
|
|
137
|
+
if (this._parentNode) {
|
|
138
|
+
return this._parentNode
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
this._parentNode = TaroNativeModule.getTaroNodeProperty(this, 'parentNode')
|
|
142
|
+
|
|
143
|
+
return this._parentNode
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
public get nodeValue (): string | null {
|
|
147
|
+
switch (this.nodeType) {
|
|
148
|
+
case NodeType.TEXT_NODE:
|
|
149
|
+
return this.textContent
|
|
150
|
+
case NodeType.COMMENT_NODE:
|
|
151
|
+
return 'comment'
|
|
152
|
+
default:
|
|
153
|
+
return null
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
public set nodeValue (value: string | null) {
|
|
158
|
+
if (this.nodeType === NodeType.TEXT_NODE && value) {
|
|
159
|
+
this.textContent = value
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
public get ownerDocument (): TaroDocument | null {
|
|
164
|
+
return this._doc
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
public hasChildNodes (): boolean {
|
|
168
|
+
return this.childNodes.length > 0
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// TODO cloneNode()、contains()
|
|
172
|
+
|
|
173
|
+
public appendChild (child: TaroElement): TaroNode {
|
|
174
|
+
// FIXME: 后续移除
|
|
175
|
+
if ((this as any).isETS) {
|
|
176
|
+
(this as any).notifyDataAdd?.(this.childNodes.length - 1)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
runInDebug(() => {
|
|
180
|
+
printInfo('appendChild', this._nid, child._nid, this.parentNode?.nodeName, this.nodeName, child.nodeName)
|
|
181
|
+
})
|
|
182
|
+
TaroNativeModule.appendTaroNode(this, child)
|
|
183
|
+
|
|
184
|
+
child._parentNode = this
|
|
185
|
+
this._childNodes = null
|
|
186
|
+
return child
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
public insertBefore (newNode: TaroElement, referenceNode?: TaroNode): TaroNode {
|
|
190
|
+
if (!referenceNode) {
|
|
191
|
+
this.appendChild(newNode)
|
|
192
|
+
} else {
|
|
193
|
+
// FIXME: 后续移除
|
|
194
|
+
if ((this as any).isETS) {
|
|
195
|
+
(this as any).notifyDataReload?.()
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
runInDebug(() => {
|
|
199
|
+
printInfo('insertBefore', this.parentNode?.nodeName, this._nid, referenceNode._nid, this.nodeName)
|
|
200
|
+
})
|
|
201
|
+
TaroNativeModule.insertBeforeTaroNode(this, newNode, referenceNode)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
newNode._parentNode = this
|
|
205
|
+
this._childNodes = null
|
|
206
|
+
return newNode
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
public replaceChild (newChild: TaroNode, oldChild: TaroNode): TaroNode {
|
|
210
|
+
// FIXME: 后续移除
|
|
211
|
+
if ((this as any).isETS) {
|
|
212
|
+
(this as any).notifyDataChange?.((this as any).findIndex(oldChild))
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
runInDebug(() => {
|
|
216
|
+
printInfo('replaceChild', this.parentNode?.nodeName, this._nid, newChild._nid, this.nodeName)
|
|
217
|
+
})
|
|
218
|
+
TaroNativeModule.replaceTaroNode(this, newChild, oldChild)
|
|
219
|
+
newChild._parentNode = this
|
|
220
|
+
oldChild._parentNode = null
|
|
221
|
+
this._childNodes = null
|
|
222
|
+
return oldChild
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
public removeChild (child: TaroNode): TaroNode {
|
|
226
|
+
// FIXME: 后续移除
|
|
227
|
+
if ((this as any).isETS) {
|
|
228
|
+
(this as any).notifyDataChange?.((this as any).findIndex(child))
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
runInDebug(() => {
|
|
232
|
+
// @ts-ignore
|
|
233
|
+
printInfo('removeChild', this.parentNode?.nodeName, this._nid, child._nid, this.nodeName, '-', this.className, '-', child.className)
|
|
234
|
+
})
|
|
235
|
+
TaroNativeModule.removeTaroNode(this, child)
|
|
236
|
+
child._parentNode = this
|
|
237
|
+
this._childNodes = null
|
|
238
|
+
return child
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
public getElementById<T extends TaroNode = TaroElement> (id?: string): T | null {
|
|
242
|
+
runInDebug(() => {
|
|
243
|
+
printInfo('getElementById', this._nid, this.nodeName, 'id:', id)
|
|
244
|
+
})
|
|
245
|
+
return isString(id) ? TaroNativeModule.getTaroNodeById(this, id) : null
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
public getElementsByTagName<T extends TaroNode = TaroElement>(tagName: string): T[] {
|
|
249
|
+
runInDebug(() => {
|
|
250
|
+
printInfo('getElementsByTagName', this._nid, this.nodeName, 'tagName:', tagName)
|
|
251
|
+
})
|
|
252
|
+
return (isString(tagName) ? TaroNativeModule.getTaroNodesByTagName(this, tagName) : null) || []
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
public getElementsByClassName<T extends TaroNode = TaroElement>(className: string): T[] {
|
|
256
|
+
runInDebug(() => {
|
|
257
|
+
printInfo('getElementsByClassName', this._nid, this.nodeName, 'className:', className)
|
|
258
|
+
})
|
|
259
|
+
return (isString(className) ? TaroNativeModule.getTaroNodesByClassName(this, className) : null) || []
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
public querySelector (selectors: string): TaroElement | null {
|
|
263
|
+
runInDebug(() => {
|
|
264
|
+
printInfo('querySelector', this._nid, this.nodeName, 'selectors:', selectors)
|
|
265
|
+
})
|
|
266
|
+
const result = isString(selectors) ? TaroNativeModule.querySelectDOMSync(this, selectors, false) : null
|
|
267
|
+
|
|
268
|
+
return !result || !result.length ? null : result[0]
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
public querySelectorAll (selectors: string): TaroElement[] {
|
|
272
|
+
runInDebug(() => {
|
|
273
|
+
printInfo('querySelectorAll', this._nid, this.nodeName, 'selectors:', selectors)
|
|
274
|
+
})
|
|
275
|
+
const result = isString(selectors) ? TaroNativeModule.querySelectDOMSync(this, selectors, true) : null
|
|
276
|
+
|
|
277
|
+
return !result || !result.length ? [] : result
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
public getComputedStyle () {
|
|
281
|
+
// Note: HiLog 直接输出 Proxy 对象会崩溃,后续切换到 JSVM 如果还存在这个问题可以再做优化
|
|
282
|
+
return new Proxy({}, {
|
|
283
|
+
get: (_, name = '') => {
|
|
284
|
+
runInDebug(() => {
|
|
285
|
+
printInfo('getComputedStyle', this._nid, this.nodeName, 'name:', name)
|
|
286
|
+
})
|
|
287
|
+
return isString(name) ? TaroNativeModule.getComputedStyle(this, name) : null
|
|
288
|
+
}
|
|
289
|
+
})
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export class TaroTextNode extends TaroNode {
|
|
294
|
+
constructor(value = '', nodeName = '#text', nodeType: NodeType = NodeType.TEXT_NODE) {
|
|
295
|
+
super(nodeName, nodeType)
|
|
296
|
+
TaroNativeModule.createTaroNode(this)
|
|
297
|
+
this.textContent = value
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
public get data (): string {
|
|
301
|
+
return this.textContent
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
public set data (value: string) {
|
|
305
|
+
this.textContent = value
|
|
306
|
+
}
|
|
307
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { isNull, isUndefined } from '@tarojs/shared'
|
|
2
|
+
|
|
3
|
+
import type { TaroAny } from '../interface'
|
|
4
|
+
|
|
5
|
+
export class Style {
|
|
6
|
+
public _pending: boolean
|
|
7
|
+
|
|
8
|
+
public _value: TaroAny
|
|
9
|
+
|
|
10
|
+
public constructor (_) {
|
|
11
|
+
this._value = {}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public get cssText () {
|
|
15
|
+
return ''
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public set cssText (_str: string) {
|
|
19
|
+
// TODO
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public setProperty (propertyName: string, value?: string | null) {
|
|
23
|
+
if (propertyName[0] === '-') {
|
|
24
|
+
// Note: 暂不支持 webkit 属性或 css 变量
|
|
25
|
+
return
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (isNull(value) || isUndefined(value)) {
|
|
29
|
+
this.removeProperty(propertyName)
|
|
30
|
+
} else {
|
|
31
|
+
// TODO setProperty
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public removeProperty (_propertyName: string): string {
|
|
36
|
+
// TODO: removeProperty
|
|
37
|
+
return ''
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public getPropertyValue (_propertyName: string) {
|
|
41
|
+
// TODO: getPropertyValue
|
|
42
|
+
return ''
|
|
43
|
+
}
|
|
44
|
+
}
|