@tarojs/plugin-platform-harmony-cpp 4.1.0 → 4.1.1-alpha.0

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.
Files changed (223) hide show
  1. package/dist/index.js +1237 -0
  2. package/dist/runtime/apis/apis.ts +20 -0
  3. package/dist/runtime/apis/base/crypto.ts +4 -0
  4. package/dist/runtime/apis/base/debug.ts +5 -0
  5. package/dist/runtime/apis/base/index.ts +13 -0
  6. package/dist/runtime/apis/base/performance.ts +8 -0
  7. package/dist/runtime/apis/base/system.ts +181 -0
  8. package/dist/runtime/apis/base/update.ts +5 -0
  9. package/dist/runtime/apis/base/weapp/app-event.ts +75 -0
  10. package/dist/runtime/apis/base/weapp/life-cycle.ts +21 -0
  11. package/dist/runtime/apis/canvas/index.ts +27 -0
  12. package/dist/runtime/apis/data-analysis/index.ts +6 -0
  13. package/dist/runtime/apis/device/accelerometer.ts +79 -0
  14. package/dist/runtime/apis/device/accessibility.ts +4 -0
  15. package/dist/runtime/apis/device/battery.ts +24 -0
  16. package/dist/runtime/apis/device/bluetooth-ble.ts +19 -0
  17. package/dist/runtime/apis/device/bluetooth-peripheral.ts +6 -0
  18. package/dist/runtime/apis/device/bluetooth.ts +16 -0
  19. package/dist/runtime/apis/device/calendar.ts +5 -0
  20. package/dist/runtime/apis/device/clipboard.ts +85 -0
  21. package/dist/runtime/apis/device/compass.ts +21 -0
  22. package/dist/runtime/apis/device/contact.ts +5 -0
  23. package/dist/runtime/apis/device/crypto.ts +4 -0
  24. package/dist/runtime/apis/device/gyroscope.ts +77 -0
  25. package/dist/runtime/apis/device/iBeacon.ts +10 -0
  26. package/dist/runtime/apis/device/index.ts +24 -0
  27. package/dist/runtime/apis/device/keyboard.ts +63 -0
  28. package/dist/runtime/apis/device/memory.ts +11 -0
  29. package/dist/runtime/apis/device/motion.ts +6 -0
  30. package/dist/runtime/apis/device/network.ts +123 -0
  31. package/dist/runtime/apis/device/nfc.ts +10 -0
  32. package/dist/runtime/apis/device/phone.ts +44 -0
  33. package/dist/runtime/apis/device/scan.ts +4 -0
  34. package/dist/runtime/apis/device/screen.ts +80 -0
  35. package/dist/runtime/apis/device/sms.ts +4 -0
  36. package/dist/runtime/apis/device/vibrate.ts +32 -0
  37. package/dist/runtime/apis/device/wifi.ts +15 -0
  38. package/dist/runtime/apis/ext/index.ts +5 -0
  39. package/dist/runtime/apis/files/index.ts +136 -0
  40. package/dist/runtime/apis/files/manager.ts +942 -0
  41. package/dist/runtime/apis/framework/index.ts +48 -0
  42. package/dist/runtime/apis/harmony/task-pool.ts +39 -0
  43. package/dist/runtime/apis/index.ts +61 -0
  44. package/dist/runtime/apis/location/index.ts +133 -0
  45. package/dist/runtime/apis/media/EditorContext.ts +32 -0
  46. package/dist/runtime/apis/media/audio/index.ts +36 -0
  47. package/dist/runtime/apis/media/background-audio/index.ts +16 -0
  48. package/dist/runtime/apis/media/camera.ts +16 -0
  49. package/dist/runtime/apis/media/common.ts +58 -0
  50. package/dist/runtime/apis/media/image/index.ts +291 -0
  51. package/dist/runtime/apis/media/index.ts +13 -0
  52. package/dist/runtime/apis/media/live.ts +5 -0
  53. package/dist/runtime/apis/media/map.ts +4 -0
  54. package/dist/runtime/apis/media/media-recorder.ts +4 -0
  55. package/dist/runtime/apis/media/recorder.ts +6 -0
  56. package/dist/runtime/apis/media/video/VideoContext.ts +67 -0
  57. package/dist/runtime/apis/media/video/index.ts +45 -0
  58. package/dist/runtime/apis/media/video-decoder.ts +4 -0
  59. package/dist/runtime/apis/media/video-processing.ts +4 -0
  60. package/dist/runtime/apis/media/voip.ts +19 -0
  61. package/dist/runtime/apis/navigate/index.ts +8 -0
  62. package/dist/runtime/apis/network/downloadFile.ts +85 -0
  63. package/dist/runtime/apis/network/index.ts +7 -0
  64. package/dist/runtime/apis/network/mdns.ts +13 -0
  65. package/dist/runtime/apis/network/request.ts +140 -0
  66. package/dist/runtime/apis/network/tcp.ts +4 -0
  67. package/dist/runtime/apis/network/udp.ts +4 -0
  68. package/dist/runtime/apis/network/uploadFile.ts +105 -0
  69. package/dist/runtime/apis/network/webSocket.ts +126 -0
  70. package/dist/runtime/apis/open-api/account.ts +4 -0
  71. package/dist/runtime/apis/open-api/address.ts +4 -0
  72. package/dist/runtime/apis/open-api/authorize.ts +5 -0
  73. package/dist/runtime/apis/open-api/card.ts +5 -0
  74. package/dist/runtime/apis/open-api/channels-live.ts +11 -0
  75. package/dist/runtime/apis/open-api/customer-service.ts +4 -0
  76. package/dist/runtime/apis/open-api/device-voip.ts +5 -0
  77. package/dist/runtime/apis/open-api/facial.ts +7 -0
  78. package/dist/runtime/apis/open-api/favorites.ts +5 -0
  79. package/dist/runtime/apis/open-api/group.ts +4 -0
  80. package/dist/runtime/apis/open-api/index.ts +21 -0
  81. package/dist/runtime/apis/open-api/invoice.ts +5 -0
  82. package/dist/runtime/apis/open-api/license-plate.ts +4 -0
  83. package/dist/runtime/apis/open-api/login.ts +6 -0
  84. package/dist/runtime/apis/open-api/my-miniprogram.ts +4 -0
  85. package/dist/runtime/apis/open-api/privacy.ts +7 -0
  86. package/dist/runtime/apis/open-api/red-package.ts +4 -0
  87. package/dist/runtime/apis/open-api/settings.ts +5 -0
  88. package/dist/runtime/apis/open-api/soter.ts +6 -0
  89. package/dist/runtime/apis/open-api/subscribe-message.ts +6 -0
  90. package/dist/runtime/apis/open-api/user-info.ts +70 -0
  91. package/dist/runtime/apis/open-api/werun.ts +5 -0
  92. package/dist/runtime/apis/payment/index.ts +6 -0
  93. package/dist/runtime/apis/route/index.ts +88 -0
  94. package/dist/runtime/apis/share/index.ts +33 -0
  95. package/dist/runtime/apis/storage/background-fetch.ts +7 -0
  96. package/dist/runtime/apis/storage/cache-manager.ts +4 -0
  97. package/dist/runtime/apis/storage/index.ts +203 -0
  98. package/dist/runtime/apis/ui/animation/animation.ts +264 -0
  99. package/dist/runtime/apis/ui/animation/index.ts +7 -0
  100. package/dist/runtime/apis/ui/background.ts +20 -0
  101. package/dist/runtime/apis/ui/custom-component.ts +1 -0
  102. package/dist/runtime/apis/ui/fonts.ts +4 -0
  103. package/dist/runtime/apis/ui/index.ts +12 -0
  104. package/dist/runtime/apis/ui/interaction/index.ts +198 -0
  105. package/dist/runtime/apis/ui/menu.ts +4 -0
  106. package/dist/runtime/apis/ui/navigation-bar/index.ts +72 -0
  107. package/dist/runtime/apis/ui/pull-down-refresh.ts +47 -0
  108. package/dist/runtime/apis/ui/scroll/index.ts +82 -0
  109. package/dist/runtime/apis/ui/sticky.ts +4 -0
  110. package/dist/runtime/apis/ui/tab-bar.ts +144 -0
  111. package/dist/runtime/apis/ui/window.ts +20 -0
  112. package/dist/runtime/apis/utils/constant.ts +1 -0
  113. package/dist/runtime/apis/utils/handler.ts +117 -0
  114. package/dist/runtime/apis/utils/index.ts +105 -0
  115. package/dist/runtime/apis/utils/permissions.ts +6 -0
  116. package/dist/runtime/apis/utils/types.ts +12 -0
  117. package/dist/runtime/apis/utils/unit.ts +104 -0
  118. package/dist/runtime/apis/utils/validate.ts +87 -0
  119. package/dist/runtime/apis/worker/index.ts +4 -0
  120. package/dist/runtime/apis/wxml/index.ts +17 -0
  121. package/dist/runtime/apis/wxml/intersectionObserver.ts +100 -0
  122. package/dist/runtime/apis/wxml/nodesRef.ts +58 -0
  123. package/dist/runtime/apis/wxml/selectorQuery.ts +221 -0
  124. package/dist/runtime/apischunk/index.d.ts +802 -0
  125. package/dist/runtime/apischunk/index.js +5054 -0
  126. package/dist/runtime/components/deprecated.ets +43 -0
  127. package/dist/runtime/components/index.ets +49 -0
  128. package/dist/runtime/components/innerHtml.ets +16 -0
  129. package/dist/runtime/components/navigationBar.ets +65 -0
  130. package/dist/runtime/components/pageMeta.ets +94 -0
  131. package/dist/runtime/components/richText.ets +24 -0
  132. package/dist/runtime/components/slider.ets +119 -0
  133. package/dist/runtime/components/style.ets +286 -0
  134. package/dist/runtime/components/switch.ets +73 -0
  135. package/dist/runtime/components/tag.ts +58 -0
  136. package/dist/runtime/components/utils/AttributeManager.ets +252 -0
  137. package/dist/runtime/components/utils/DynamicCenter.ts +41 -0
  138. package/dist/runtime/components/utils/constant/event.ets +25 -0
  139. package/dist/runtime/components/utils/constant/style.ets +91 -0
  140. package/dist/runtime/components/utils/events.ts +26 -0
  141. package/dist/runtime/components/utils/flexManager.ets +49 -0
  142. package/dist/runtime/components/utils/helper.ets +51 -0
  143. package/dist/runtime/components/utils/htmlParser/HarmonyHTMLParser.ts +100 -0
  144. package/dist/runtime/components/utils/htmlParser/index.ts +58 -0
  145. package/dist/runtime/components/utils/index.ts +77 -0
  146. package/dist/runtime/components/utils/styles.ets +41 -0
  147. package/dist/runtime/components/video.ets +119 -0
  148. package/dist/runtime/components/webView.ets +55 -0
  149. package/dist/runtime/components/xComponent.ets +89 -0
  150. package/dist/runtime/framework/app.ts +248 -0
  151. package/dist/runtime/framework/connect.ts +24 -0
  152. package/dist/runtime/framework/constant.ts +3 -0
  153. package/dist/runtime/framework/hooks.ts +99 -0
  154. package/dist/runtime/framework/index.ts +15 -0
  155. package/dist/runtime/framework/native-page.ts +511 -0
  156. package/dist/runtime/framework/page.ts +256 -0
  157. package/dist/runtime/framework/utils/index.ts +17 -0
  158. package/dist/runtime/framework/utils/is.ts +26 -0
  159. package/dist/runtime/framework-reconciler/componentTree.ts +81 -0
  160. package/dist/runtime/framework-reconciler/constant.ts +86 -0
  161. package/dist/runtime/framework-reconciler/domInput.ts +90 -0
  162. package/dist/runtime/framework-reconciler/event.ts +108 -0
  163. package/dist/runtime/framework-reconciler/index.ts +99 -0
  164. package/dist/runtime/framework-reconciler/inputValueTracking.ts +106 -0
  165. package/dist/runtime/framework-reconciler/props.ts +132 -0
  166. package/dist/runtime/framework-reconciler/reconciler.ts +202 -0
  167. package/dist/runtime/framework-reconciler/render.ts +139 -0
  168. package/dist/runtime/framework-reconciler/workTags.ts +53 -0
  169. package/dist/runtime/runtime-cpp/bom/URL.ts +2 -0
  170. package/dist/runtime/runtime-cpp/bom/document.ts +45 -0
  171. package/dist/runtime/runtime-cpp/bom/history.ts +1 -0
  172. package/dist/runtime/runtime-cpp/bom/location.ts +1 -0
  173. package/dist/runtime/runtime-cpp/bom/navigator.ts +1 -0
  174. package/dist/runtime/runtime-cpp/bom/raf.ts +1 -0
  175. package/dist/runtime/runtime-cpp/bom/window.ts +57 -0
  176. package/dist/runtime/runtime-cpp/constant.ts +29 -0
  177. package/dist/runtime/runtime-cpp/current.ts +48 -0
  178. package/dist/runtime/runtime-cpp/dom/class-list.ts +41 -0
  179. package/dist/runtime/runtime-cpp/dom/comment.ts +9 -0
  180. package/dist/runtime/runtime-cpp/dom/dataSource.ts +87 -0
  181. package/dist/runtime/runtime-cpp/dom/document.ts +113 -0
  182. package/dist/runtime/runtime-cpp/dom/element/canvas.ts +285 -0
  183. package/dist/runtime/runtime-cpp/dom/element/element.ts +262 -0
  184. package/dist/runtime/runtime-cpp/dom/element/form.ts +371 -0
  185. package/dist/runtime/runtime-cpp/dom/element/index.ts +129 -0
  186. package/dist/runtime/runtime-cpp/dom/element/movable.ts +250 -0
  187. package/dist/runtime/runtime-cpp/dom/element/normal.ts +123 -0
  188. package/dist/runtime/runtime-cpp/dom/element/scroll_view.ts +32 -0
  189. package/dist/runtime/runtime-cpp/dom/element/text.ts +9 -0
  190. package/dist/runtime/runtime-cpp/dom/element/video.ts +66 -0
  191. package/dist/runtime/runtime-cpp/dom/element/web_view.ts +72 -0
  192. package/dist/runtime/runtime-cpp/dom/event-source.ts +1 -0
  193. package/dist/runtime/runtime-cpp/dom/event.ts +187 -0
  194. package/dist/runtime/runtime-cpp/dom/eventTarget.ts +81 -0
  195. package/dist/runtime/runtime-cpp/dom/node.ts +307 -0
  196. package/dist/runtime/runtime-cpp/dom/style.ts +44 -0
  197. package/dist/runtime/runtime-cpp/dom/stylesheet/index.ts +379 -0
  198. package/dist/runtime/runtime-cpp/dom/stylesheet/type.ts +212 -0
  199. package/dist/runtime/runtime-cpp/dom/stylesheet/util.ts +186 -0
  200. package/dist/runtime/runtime-cpp/emitter/emitter.ts +29 -0
  201. package/dist/runtime/runtime-cpp/env.ts +1 -0
  202. package/dist/runtime/runtime-cpp/harmony-library.ts +1 -0
  203. package/dist/runtime/runtime-cpp/index.ts +79 -0
  204. package/dist/runtime/runtime-cpp/interface/event.ts +10 -0
  205. package/dist/runtime/runtime-cpp/interface/index.ts +7 -0
  206. package/dist/runtime/runtime-cpp/next-tick.ts +14 -0
  207. package/dist/runtime/runtime-cpp/system.ts +213 -0
  208. package/dist/runtime/runtime-cpp/utils/index.ts +63 -0
  209. package/dist/runtime/runtime-cpp/utils/info.ts +123 -0
  210. package/dist/runtime/runtime-cpp/utils/page.ts +12 -0
  211. package/dist/runtime/runtime-cpp/utils/router.ts +1 -0
  212. package/dist/runtime/runtime-harmony/apis/helper.ets +33 -0
  213. package/dist/runtime/runtime-harmony/apis/network/common.ets +41 -0
  214. package/dist/runtime/runtime-harmony/apis/network/downloadFile.ets +327 -0
  215. package/dist/runtime/runtime-harmony/apis/network/index.ets +58 -0
  216. package/dist/runtime/runtime-harmony/apis/network/request.ets +206 -0
  217. package/dist/runtime/runtime-harmony/apis/network/uploadFile.ets +190 -0
  218. package/dist/runtime/runtime-harmony/apis/route.ets +110 -0
  219. package/dist/runtime/runtime-harmony/apis/taskpool.ets +149 -0
  220. package/dist/runtime/runtime-harmony/index.ets +41 -0
  221. package/dist/runtime/runtime-harmony/utils.ts +53 -0
  222. package/package.json +24 -23
  223. package/LICENSE +0 -174
@@ -0,0 +1,53 @@
1
+ export type WorkTag =
2
+ | 0
3
+ | 1
4
+ | 2
5
+ | 3
6
+ | 4
7
+ | 5
8
+ | 6
9
+ | 7
10
+ | 8
11
+ | 9
12
+ | 10
13
+ | 11
14
+ | 12
15
+ | 13
16
+ | 14
17
+ | 15
18
+ | 16
19
+ | 17
20
+ | 18
21
+ | 19
22
+ | 20
23
+ | 21
24
+ | 22
25
+ | 23
26
+ | 24
27
+ | 25
28
+
29
+ export const FunctionComponent = 0
30
+ export const ClassComponent = 1
31
+ export const IndeterminateComponent = 2 // Before we know whether it is function or class
32
+ export const HostRoot = 3 // Root of a host tree. Could be nested inside another node.
33
+ export const HostPortal = 4 // A subtree. Could be an entry point to a different renderer.
34
+ export const HostComponent = 5
35
+ export const HostText = 6
36
+ export const Fragment = 7
37
+ export const Mode = 8
38
+ export const ContextConsumer = 9
39
+ export const ContextProvider = 10
40
+ export const ForwardRef = 11
41
+ export const Profiler = 12
42
+ export const SuspenseComponent = 13
43
+ export const MemoComponent = 14
44
+ export const SimpleMemoComponent = 15
45
+ export const LazyComponent = 16
46
+ export const IncompleteClassComponent = 17
47
+ export const DehydratedFragment = 18
48
+ export const SuspenseListComponent = 19
49
+ export const ScopeComponent = 21
50
+ export const OffscreenComponent = 22
51
+ export const LegacyHiddenComponent = 23
52
+ export const CacheComponent = 24
53
+ export const TracingMarkerComponent = 25
@@ -0,0 +1,2 @@
1
+ export { parseUrl, URL } from '@tarojs/runtime/dist/runtime.esm'
2
+ export { URLSearchParams } from '@tarojs/runtime/dist/runtime.esm'
@@ -0,0 +1,45 @@
1
+ import { APP, BODY, HEAD, HTML } from '../constant'
2
+ import { TaroDocument } from '../dom/document'
3
+ import { window } from './window'
4
+
5
+ function createDocument (): TaroDocument {
6
+ /**
7
+ * <html> <--- document.documentElement
8
+ * <head></head> <--- document.head
9
+ * <body> <--- document.body
10
+ * <container>
11
+ * <app id="app" />
12
+ * </container>
13
+ * </body>
14
+ * </html>
15
+ */
16
+
17
+ const doc = new TaroDocument(window)
18
+ const documentCreateElement = doc.createElement.bind(doc)
19
+ const html = documentCreateElement(HTML)
20
+ const head = documentCreateElement(HEAD)
21
+ const body = documentCreateElement(BODY)
22
+ const container = documentCreateElement('container') // 多包一层主要为了兼容 vue
23
+ const app = documentCreateElement(APP)
24
+ const entryAsync = documentCreateElement('entryAsync')
25
+ app.id = 'app'
26
+ entryAsync.id = 'entryAsync'
27
+
28
+ doc.appendChild(html)
29
+ html.appendChild(head)
30
+ html.appendChild(body)
31
+ body.appendChild(container)
32
+ container.appendChild(app)
33
+ container.appendChild(entryAsync)
34
+
35
+ doc.documentElement = html
36
+ doc.head = head
37
+ doc.body = body
38
+ doc.container = container
39
+ doc.app = app
40
+ doc.entryAsync = entryAsync
41
+
42
+ return doc
43
+ }
44
+
45
+ export const document = createDocument()
@@ -0,0 +1 @@
1
+ export { History } from '@tarojs/runtime/dist/runtime.esm'
@@ -0,0 +1 @@
1
+ export { Location } from '@tarojs/runtime/dist/runtime.esm'
@@ -0,0 +1 @@
1
+ export { navigator } from '@tarojs/runtime/dist/runtime.esm'
@@ -0,0 +1 @@
1
+ export { cancelAnimationFrame, now, requestAnimationFrame } from '@tarojs/runtime/dist/runtime.esm'
@@ -0,0 +1,57 @@
1
+ import _display from '@ohos.display'
2
+ import ohosWindow from '@ohos.window'
3
+
4
+ import { TaroEventTarget } from '../dom/eventTarget'
5
+ import { History } from './history'
6
+ import { Location } from './location'
7
+ import { navigator as nav } from './navigator'
8
+
9
+ import type { TaroDocument } from '../dom/document'
10
+ import type { TaroElement } from '../dom/element/element'
11
+
12
+ export class Window extends TaroEventTarget {
13
+ public _doc: TaroDocument
14
+ public __taroAppConfig: any
15
+ public __ohos = ohosWindow
16
+ public __oh_display: typeof _display
17
+
18
+ public location: any
19
+ public history: any
20
+ public navigator = nav
21
+
22
+ constructor () {
23
+ super()
24
+
25
+ this.location = new Location({ window: this })
26
+ this.history = new History(this.location, { window: this })
27
+ this.__oh_display = _display.getDefaultDisplaySync()
28
+ }
29
+
30
+ get document (): TaroDocument {
31
+ return this._doc
32
+ }
33
+
34
+ get devicePixelRatio () {
35
+ return this.__oh_display.densityPixels
36
+ }
37
+
38
+ get getComputedStyle () {
39
+ return this.document.getComputedStyle
40
+ }
41
+
42
+ setTimeout (...args: Parameters<typeof setTimeout>) {
43
+ setTimeout(...args)
44
+ }
45
+
46
+ clearTimeout (...args: Parameters<typeof clearTimeout>) {
47
+ clearTimeout(...args)
48
+ }
49
+ }
50
+
51
+ export const getComputedStyle = (element: TaroElement) => {
52
+ return element.getComputedStyle()
53
+ }
54
+
55
+ export const window = new Window()
56
+ export const location = window.location
57
+ export const history = window.history
@@ -0,0 +1,29 @@
1
+ export {
2
+ A, APP, BEHAVIORS, BODY,
3
+ CATCH_VIEW, CATCHMOVE, CHANGE,
4
+ CLASS, COMMENT, COMPILE_MODE,
5
+ CONFIRM, CONTAINER, CONTEXT_ACTIONS,
6
+ CURRENT_TARGET, CUSTOM_WRAPPER,
7
+ DATASET, DATE, DOCUMENT_ELEMENT_NAME,
8
+ DOCUMENT_FRAGMENT, EVENT_CALLBACK_RESULT,
9
+ EXTERNAL_CLASSES, FOCUS, HEAD,
10
+ HOOKS_APP_ID, HTML, ID, INPUT,
11
+ KEY_CODE, OBJECT, ON_HIDE, ON_LOAD,
12
+ ON_READY, ON_SHOW, OPTIONS, PAGE_INIT,
13
+ PROPERTY_THRESHOLD, PROPS, PURE_VIEW, ROOT_STR,
14
+ SET_DATA, SET_TIMEOUT, STATIC_VIEW, STYLE,
15
+ TARGET, TARO_RUNTIME, TIME_STAMP,
16
+ TOUCHMOVE, TYPE, UID, VALUE, VIEW
17
+ } from '@tarojs/runtime/dist/runtime.esm'
18
+
19
+ export const ATTRIBUTES_CALLBACK_TRIGGER_MAP = {
20
+ focus: {
21
+ triggerName: 'focus',
22
+ },
23
+ animation: {
24
+ triggerName: 'animation',
25
+ }
26
+ }
27
+
28
+ // 折叠屏分割临界宽度, 大于1500视为折叠屏
29
+ export const FOLD_SPLIT_MAX_WIDTH = 600
@@ -0,0 +1,48 @@
1
+ import { TaroNativeModule } from './harmony-library'
2
+
3
+ export const context: any = {
4
+ resolver: null,
5
+ value: null
6
+ }
7
+
8
+ export const uiContext: any = {
9
+ resolver: null,
10
+ value: null
11
+ }
12
+
13
+ export const Current: any = {
14
+ app: null,
15
+ entryAsync: null,
16
+ isDebug: false,
17
+ get uiContext () {
18
+ return uiContext.value
19
+ },
20
+ set uiContext (e) {
21
+ uiContext.resolver(e)
22
+ },
23
+ router: {},
24
+ taro: {},
25
+ contextPromise: new Promise(resolve => {
26
+ context.resolver = resolve
27
+
28
+ return resolve
29
+ }).then(e => {
30
+ context.value = e
31
+
32
+ return e
33
+ }),
34
+ uiContextPromise: new Promise(resolve => {
35
+ uiContext.resolver = resolve
36
+
37
+ return resolve
38
+ }).then((e) => {
39
+ uiContext.value = e
40
+
41
+ return e
42
+ }),
43
+ nativeModule: TaroNativeModule,
44
+ createHarmonyElement: null,
45
+ audioSessionManager: null
46
+ }
47
+
48
+ export const getCurrentInstance = () => Current
@@ -0,0 +1,41 @@
1
+ import { TaroNativeModule } from '../harmony-library'
2
+
3
+ export class ClassList {
4
+ private el: any
5
+
6
+ constructor (el: any) {
7
+ this.el = el
8
+ }
9
+
10
+ public get value () {
11
+ return this.toString()
12
+ }
13
+
14
+ public get length () {
15
+ return TaroNativeModule.executeNodeFunc(this.el, 'classList.length', [])
16
+ }
17
+
18
+ add (...tokens: string[]) {
19
+ return TaroNativeModule.executeNodeFunc(this.el, 'classList.add', tokens)
20
+ }
21
+
22
+ remove (...tokens: string[]) {
23
+ return TaroNativeModule.executeNodeFunc(this.el, 'classList.remove', tokens)
24
+ }
25
+
26
+ contains (token: string) {
27
+ return TaroNativeModule.executeNodeFunc(this.el, 'classList.contains', token)
28
+ }
29
+
30
+ toggle (token: string, force: boolean) {
31
+ return TaroNativeModule.executeNodeFunc(this.el, 'classList.toggle', [token, force])
32
+ }
33
+
34
+ replace (token: string, replacement_token: string) {
35
+ return TaroNativeModule.executeNodeFunc(this.el, 'classList.replace', [token, replacement_token])
36
+ }
37
+
38
+ toString () {
39
+ return TaroNativeModule.executeNodeFunc(this.el, 'classList.toString', [])
40
+ }
41
+ }
@@ -0,0 +1,9 @@
1
+ import { NodeType, TaroTextNode } from './node'
2
+
3
+ class TaroComment extends TaroTextNode {
4
+ constructor(data: string) {
5
+ super(data || '', '#comment', NodeType.COMMENT_NODE)
6
+ }
7
+ }
8
+
9
+ export { TaroComment }
@@ -0,0 +1,87 @@
1
+ import { TaroNode } from './node'
2
+
3
+ /** FIXME 后续删除 */
4
+ export class TaroDataSourceElement extends TaroNode implements IDataSource {
5
+ protected listeners: DataChangeListener[] = []
6
+
7
+ // 以下属性为半编译模式下才会赋值和使用的属性
8
+ // 半编译节点更新触发器
9
+ public _updateTrigger = 0
10
+ // 是否为半编译模板下的节点
11
+ public _isCompileMode = false
12
+ // 是否为半编译模板下拥有自主更新权的节点
13
+ public _isDynamicNode = false
14
+
15
+ public findIndex (refChild?: TaroNode): number {
16
+ return this.childNodes.findIndex(node => node._nid === refChild?._nid)
17
+ }
18
+
19
+ totalCount(): number {
20
+ return this.childNodes?.length || 0
21
+ }
22
+
23
+ // 更新对应的 ArkUI 组件
24
+ public updateComponent () {
25
+ // 非半编译模式或者半编译模式下拥有自主更新权力的节点走 @State 的更新模式
26
+ if (this._isDynamicNode || (!this._isCompileMode && this._instance)) {
27
+ this._updateTrigger++
28
+ } else {
29
+ (this.parentNode as TaroDataSourceElement)?.updateComponent?.()
30
+ }
31
+ }
32
+
33
+ getData(index: number) {
34
+ return this.childNodes[index] as TaroNode
35
+ }
36
+
37
+ // 该方法为框架侧调用,为 LazyForEach 组件向其数据源处添加 listener 监听
38
+ registerDataChangeListener(listener: DataChangeListener): void {
39
+ if (this.listeners.indexOf(listener) < 0) {
40
+ this.listeners.push(listener)
41
+ }
42
+ }
43
+
44
+ // 该方法为框架侧调用,为对应的 LazyForEach 组件在数据源处去除 listener 监听
45
+ unregisterDataChangeListener(listener: DataChangeListener): void {
46
+ const pos = this.listeners.indexOf(listener)
47
+
48
+ if (pos >= 0) {
49
+ this.listeners.splice(pos, 1)
50
+ }
51
+ }
52
+
53
+ // 通知 LazyForEach 组件需要重载所有子组件
54
+ notifyDataReload(): void {
55
+ this.listeners.forEach(listener => {
56
+ listener.onDataReloaded()
57
+ })
58
+ }
59
+
60
+ // 通知 LazyForEach 组件需要将 from 对应索引处的子组件移动到 to 索引处
61
+ notifyDataMove(from: number, to: number): void {
62
+ this.listeners.forEach(listener => {
63
+ listener.onDataMove(from, to)
64
+ })
65
+ }
66
+
67
+ // 通知 LazyForEach 组件需要在 index 对应索引处添加子组件
68
+ notifyDataAdd(index: number): void {
69
+ this.listeners.forEach(listener => {
70
+ listener.onDataAdd(index)
71
+ })
72
+ }
73
+
74
+ // 通知 LazyForEach 组件在 index 对应索引处数据有变化,需要重建该子组件
75
+ notifyDataChange(index: number): void {
76
+ this.listeners.forEach(listener => {
77
+ listener.onDataChange(index)
78
+ })
79
+ }
80
+
81
+ // 通知 LazyForEach 组件需要在 index 对应索引处删除该子组件
82
+ notifyDataDelete(index: number): void {
83
+ this.listeners.forEach(listener => {
84
+ listener.onDataDelete(index)
85
+ })
86
+ }
87
+ }
@@ -0,0 +1,113 @@
1
+ import { Current } from '../current'
2
+ import { TaroNativeModule } from '../harmony-library'
3
+ import { getPageScrollerOrNode } from '../utils'
4
+ import { TaroComment } from './comment'
5
+ import { TaroElement } from './element/element'
6
+ import { NodeType, TaroNode, TaroTextNode } from './node'
7
+
8
+ import type { Window } from '../bom/window'
9
+
10
+ class TaroDocument extends TaroNode {
11
+ public documentElement: TaroElement
12
+ public head: TaroElement
13
+ public body: TaroElement
14
+ public container: TaroElement
15
+ public app: TaroElement
16
+ public entryAsync: TaroElement
17
+ public cookie = ''
18
+ private _win: Window
19
+
20
+ constructor(window: Window) {
21
+ super('#document', NodeType.DOCUMENT_NODE)
22
+ this._win = window
23
+ window._doc = this
24
+ TaroNativeModule.createTaroNode(this)
25
+ }
26
+
27
+ get defaultView (): Window {
28
+ return this._win
29
+ }
30
+
31
+ get currentPageNode (): TaroElement {
32
+ const taro = Current.taro
33
+ const page = taro.getCurrentInstance().page
34
+ return getPageScrollerOrNode(page?.node, page)
35
+ }
36
+
37
+ public createElement (tagName: string): TaroElement {
38
+ let node: TaroElement
39
+ // TODO: 仍需补充更多节点解析和它默认样式行为的转换,比如h1\h2
40
+ switch (tagName) {
41
+ case 'root': tagName = 'view'; break
42
+ case 'img': tagName = 'image'; break
43
+ case 'div': tagName = 'view'; break
44
+ case 'p': tagName = 'text'; break
45
+ case 'span': tagName = 'text'; break
46
+ case 'a': tagName = 'text'; break
47
+ }
48
+ if (Current?.createHarmonyElement) {
49
+ node = Current.createHarmonyElement(tagName)
50
+ } else {
51
+ node = new TaroElement(tagName)
52
+ }
53
+ node._doc = this
54
+ return node
55
+ }
56
+
57
+ public createTextNode (value: string): TaroTextNode | void {
58
+ if (!Current?.createTextNode) return
59
+
60
+ const node = Current.createTextNode(value)
61
+ node._doc = this
62
+ return node
63
+ }
64
+
65
+ public createComment (data: string): TaroComment {
66
+ return new TaroComment(data)
67
+ }
68
+
69
+ public getElementById<T extends TaroNode = TaroElement> (id?: string): T | null {
70
+ // FIXME 使用页面实例,将会导致组件模式注入的节点无法获取
71
+ console.warn('getElementById: 在 document 上查询所有元素性能较差,请谨慎使用!')
72
+ return super.getElementById.call(this, id)
73
+ }
74
+
75
+ public getElementsByTagName<T extends TaroNode = TaroElement>(tagName: string): T[] {
76
+ console.error('getElementsByTagName: 不支持在 document 上查询所有元素,自动降级到当前页面内查询!')
77
+ if (!this.currentPageNode) {
78
+ console.error('getElementsByTagName: 当前页面不存在!')
79
+ return []
80
+ }
81
+ return super.getElementsByTagName.call(this.currentPageNode, tagName)
82
+ }
83
+
84
+ public getElementsByClassName<T extends TaroNode = TaroElement>(className: string): T[] {
85
+ console.error('getElementsByClassName: 不支持在 document 上查询所有元素,自动降级到当前页面内查询!')
86
+ if (!this.currentPageNode) {
87
+ console.error('getElementsByClassName: 当前页面不存在!')
88
+ return []
89
+ }
90
+ return super.getElementsByClassName.call(this.currentPageNode, className)
91
+ }
92
+
93
+ public querySelector (selectors: string): TaroElement | null {
94
+ console.warn('querySelector: 在 document 上查询所有元素性能较差,请谨慎使用!')
95
+ return super.querySelector.call(this, selectors)
96
+ }
97
+
98
+ public querySelectorAll (selectors: string): TaroElement[] {
99
+ console.error('querySelectorAll: 不支持在 document 上查询所有元素,自动降级到当前页面内查询!')
100
+ if (!this.currentPageNode) {
101
+ console.error('querySelectorAll: 当前页面不存在!')
102
+ return []
103
+ }
104
+ return super.querySelectorAll.call(this.currentPageNode, selectors)
105
+ }
106
+
107
+ // TODO public createElementNS
108
+ public getComputedStyle (): any {
109
+ return super.getComputedStyle.call(this)
110
+ }
111
+ }
112
+
113
+ export { TaroDocument }