@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.
Files changed (225) hide show
  1. package/README.md +0 -7
  2. package/dist/index.js +1236 -0
  3. package/dist/runtime/apis/apis.ts +20 -0
  4. package/dist/runtime/apis/base/crypto.ts +4 -0
  5. package/dist/runtime/apis/base/debug.ts +5 -0
  6. package/dist/runtime/apis/base/index.ts +13 -0
  7. package/dist/runtime/apis/base/performance.ts +8 -0
  8. package/dist/runtime/apis/base/system.ts +181 -0
  9. package/dist/runtime/apis/base/update.ts +5 -0
  10. package/dist/runtime/apis/base/weapp/app-event.ts +75 -0
  11. package/dist/runtime/apis/base/weapp/life-cycle.ts +21 -0
  12. package/dist/runtime/apis/canvas/index.ts +27 -0
  13. package/dist/runtime/apis/data-analysis/index.ts +6 -0
  14. package/dist/runtime/apis/device/accelerometer.ts +79 -0
  15. package/dist/runtime/apis/device/accessibility.ts +4 -0
  16. package/dist/runtime/apis/device/battery.ts +24 -0
  17. package/dist/runtime/apis/device/bluetooth-ble.ts +19 -0
  18. package/dist/runtime/apis/device/bluetooth-peripheral.ts +6 -0
  19. package/dist/runtime/apis/device/bluetooth.ts +16 -0
  20. package/dist/runtime/apis/device/calendar.ts +5 -0
  21. package/dist/runtime/apis/device/clipboard.ts +85 -0
  22. package/dist/runtime/apis/device/compass.ts +21 -0
  23. package/dist/runtime/apis/device/contact.ts +5 -0
  24. package/dist/runtime/apis/device/crypto.ts +4 -0
  25. package/dist/runtime/apis/device/gyroscope.ts +77 -0
  26. package/dist/runtime/apis/device/iBeacon.ts +10 -0
  27. package/dist/runtime/apis/device/index.ts +24 -0
  28. package/dist/runtime/apis/device/keyboard.ts +63 -0
  29. package/dist/runtime/apis/device/memory.ts +11 -0
  30. package/dist/runtime/apis/device/motion.ts +6 -0
  31. package/dist/runtime/apis/device/network.ts +123 -0
  32. package/dist/runtime/apis/device/nfc.ts +10 -0
  33. package/dist/runtime/apis/device/phone.ts +44 -0
  34. package/dist/runtime/apis/device/scan.ts +4 -0
  35. package/dist/runtime/apis/device/screen.ts +80 -0
  36. package/dist/runtime/apis/device/sms.ts +4 -0
  37. package/dist/runtime/apis/device/vibrate.ts +32 -0
  38. package/dist/runtime/apis/device/wifi.ts +15 -0
  39. package/dist/runtime/apis/ext/index.ts +5 -0
  40. package/dist/runtime/apis/files/index.ts +136 -0
  41. package/dist/runtime/apis/files/manager.ts +942 -0
  42. package/dist/runtime/apis/framework/index.ts +48 -0
  43. package/dist/runtime/apis/harmony/task-pool.ts +39 -0
  44. package/dist/runtime/apis/index.ts +61 -0
  45. package/dist/runtime/apis/location/index.ts +133 -0
  46. package/dist/runtime/apis/media/EditorContext.ts +32 -0
  47. package/dist/runtime/apis/media/audio/index.ts +36 -0
  48. package/dist/runtime/apis/media/background-audio/index.ts +16 -0
  49. package/dist/runtime/apis/media/camera.ts +16 -0
  50. package/dist/runtime/apis/media/common.ts +58 -0
  51. package/dist/runtime/apis/media/image/index.ts +291 -0
  52. package/dist/runtime/apis/media/index.ts +13 -0
  53. package/dist/runtime/apis/media/live.ts +5 -0
  54. package/dist/runtime/apis/media/map.ts +4 -0
  55. package/dist/runtime/apis/media/media-recorder.ts +4 -0
  56. package/dist/runtime/apis/media/recorder.ts +6 -0
  57. package/dist/runtime/apis/media/video/VideoContext.ts +67 -0
  58. package/dist/runtime/apis/media/video/index.ts +45 -0
  59. package/dist/runtime/apis/media/video-decoder.ts +4 -0
  60. package/dist/runtime/apis/media/video-processing.ts +4 -0
  61. package/dist/runtime/apis/media/voip.ts +19 -0
  62. package/dist/runtime/apis/navigate/index.ts +8 -0
  63. package/dist/runtime/apis/network/downloadFile.ts +85 -0
  64. package/dist/runtime/apis/network/index.ts +7 -0
  65. package/dist/runtime/apis/network/mdns.ts +13 -0
  66. package/dist/runtime/apis/network/request.ts +140 -0
  67. package/dist/runtime/apis/network/tcp.ts +4 -0
  68. package/dist/runtime/apis/network/udp.ts +4 -0
  69. package/dist/runtime/apis/network/uploadFile.ts +105 -0
  70. package/dist/runtime/apis/network/webSocket.ts +126 -0
  71. package/dist/runtime/apis/open-api/account.ts +4 -0
  72. package/dist/runtime/apis/open-api/address.ts +4 -0
  73. package/dist/runtime/apis/open-api/authorize.ts +5 -0
  74. package/dist/runtime/apis/open-api/card.ts +5 -0
  75. package/dist/runtime/apis/open-api/channels-live.ts +11 -0
  76. package/dist/runtime/apis/open-api/customer-service.ts +4 -0
  77. package/dist/runtime/apis/open-api/device-voip.ts +5 -0
  78. package/dist/runtime/apis/open-api/facial.ts +7 -0
  79. package/dist/runtime/apis/open-api/favorites.ts +5 -0
  80. package/dist/runtime/apis/open-api/group.ts +4 -0
  81. package/dist/runtime/apis/open-api/index.ts +21 -0
  82. package/dist/runtime/apis/open-api/invoice.ts +5 -0
  83. package/dist/runtime/apis/open-api/license-plate.ts +4 -0
  84. package/dist/runtime/apis/open-api/login.ts +6 -0
  85. package/dist/runtime/apis/open-api/my-miniprogram.ts +4 -0
  86. package/dist/runtime/apis/open-api/privacy.ts +7 -0
  87. package/dist/runtime/apis/open-api/red-package.ts +4 -0
  88. package/dist/runtime/apis/open-api/settings.ts +5 -0
  89. package/dist/runtime/apis/open-api/soter.ts +6 -0
  90. package/dist/runtime/apis/open-api/subscribe-message.ts +6 -0
  91. package/dist/runtime/apis/open-api/user-info.ts +70 -0
  92. package/dist/runtime/apis/open-api/werun.ts +5 -0
  93. package/dist/runtime/apis/payment/index.ts +6 -0
  94. package/dist/runtime/apis/route/index.ts +88 -0
  95. package/dist/runtime/apis/share/index.ts +33 -0
  96. package/dist/runtime/apis/storage/background-fetch.ts +7 -0
  97. package/dist/runtime/apis/storage/cache-manager.ts +4 -0
  98. package/dist/runtime/apis/storage/index.ts +203 -0
  99. package/dist/runtime/apis/ui/animation/animation.ts +264 -0
  100. package/dist/runtime/apis/ui/animation/index.ts +7 -0
  101. package/dist/runtime/apis/ui/background.ts +20 -0
  102. package/dist/runtime/apis/ui/custom-component.ts +1 -0
  103. package/dist/runtime/apis/ui/fonts.ts +4 -0
  104. package/dist/runtime/apis/ui/index.ts +12 -0
  105. package/dist/runtime/apis/ui/interaction/index.ts +198 -0
  106. package/dist/runtime/apis/ui/menu.ts +4 -0
  107. package/dist/runtime/apis/ui/navigation-bar/index.ts +72 -0
  108. package/dist/runtime/apis/ui/pull-down-refresh.ts +47 -0
  109. package/dist/runtime/apis/ui/scroll/index.ts +82 -0
  110. package/dist/runtime/apis/ui/sticky.ts +4 -0
  111. package/dist/runtime/apis/ui/tab-bar.ts +144 -0
  112. package/dist/runtime/apis/ui/window.ts +20 -0
  113. package/dist/runtime/apis/utils/constant.ts +1 -0
  114. package/dist/runtime/apis/utils/handler.ts +117 -0
  115. package/dist/runtime/apis/utils/index.ts +105 -0
  116. package/dist/runtime/apis/utils/permissions.ts +6 -0
  117. package/dist/runtime/apis/utils/types.ts +12 -0
  118. package/dist/runtime/apis/utils/unit.ts +104 -0
  119. package/dist/runtime/apis/utils/validate.ts +87 -0
  120. package/dist/runtime/apis/worker/index.ts +4 -0
  121. package/dist/runtime/apis/wxml/index.ts +17 -0
  122. package/dist/runtime/apis/wxml/intersectionObserver.ts +100 -0
  123. package/dist/runtime/apis/wxml/nodesRef.ts +58 -0
  124. package/dist/runtime/apis/wxml/selectorQuery.ts +221 -0
  125. package/dist/runtime/apischunk/index.d.ts +802 -0
  126. package/dist/runtime/apischunk/index.js +5054 -0
  127. package/dist/runtime/components/deprecated.ets +43 -0
  128. package/dist/runtime/components/index.ets +49 -0
  129. package/dist/runtime/components/innerHtml.ets +16 -0
  130. package/dist/runtime/components/navigationBar.ets +65 -0
  131. package/dist/runtime/components/pageMeta.ets +94 -0
  132. package/dist/runtime/components/richText.ets +24 -0
  133. package/dist/runtime/components/slider.ets +119 -0
  134. package/dist/runtime/components/style.ets +286 -0
  135. package/dist/runtime/components/switch.ets +73 -0
  136. package/dist/runtime/components/tag.ts +58 -0
  137. package/dist/runtime/components/utils/AttributeManager.ets +252 -0
  138. package/dist/runtime/components/utils/DynamicCenter.ts +41 -0
  139. package/dist/runtime/components/utils/constant/event.ets +25 -0
  140. package/dist/runtime/components/utils/constant/style.ets +91 -0
  141. package/dist/runtime/components/utils/events.ts +26 -0
  142. package/dist/runtime/components/utils/flexManager.ets +49 -0
  143. package/dist/runtime/components/utils/helper.ets +51 -0
  144. package/dist/runtime/components/utils/htmlParser/HarmonyHTMLParser.ts +100 -0
  145. package/dist/runtime/components/utils/htmlParser/index.ts +58 -0
  146. package/dist/runtime/components/utils/index.ts +77 -0
  147. package/dist/runtime/components/utils/styles.ets +41 -0
  148. package/dist/runtime/components/video.ets +119 -0
  149. package/dist/runtime/components/webView.ets +55 -0
  150. package/dist/runtime/components/xComponent.ets +89 -0
  151. package/dist/runtime/framework/app.ts +248 -0
  152. package/dist/runtime/framework/connect.ts +24 -0
  153. package/dist/runtime/framework/constant.ts +3 -0
  154. package/dist/runtime/framework/hooks.ts +99 -0
  155. package/dist/runtime/framework/index.ts +15 -0
  156. package/dist/runtime/framework/native-page.ts +511 -0
  157. package/dist/runtime/framework/page.ts +256 -0
  158. package/dist/runtime/framework/utils/index.ts +17 -0
  159. package/dist/runtime/framework/utils/is.ts +26 -0
  160. package/dist/runtime/framework-reconciler/componentTree.ts +81 -0
  161. package/dist/runtime/framework-reconciler/constant.ts +86 -0
  162. package/dist/runtime/framework-reconciler/domInput.ts +90 -0
  163. package/dist/runtime/framework-reconciler/event.ts +108 -0
  164. package/dist/runtime/framework-reconciler/index.ts +99 -0
  165. package/dist/runtime/framework-reconciler/inputValueTracking.ts +106 -0
  166. package/dist/runtime/framework-reconciler/props.ts +132 -0
  167. package/dist/runtime/framework-reconciler/reconciler.ts +202 -0
  168. package/dist/runtime/framework-reconciler/render.ts +139 -0
  169. package/dist/runtime/framework-reconciler/workTags.ts +53 -0
  170. package/dist/runtime/runtime-cpp/bom/URL.ts +2 -0
  171. package/dist/runtime/runtime-cpp/bom/document.ts +45 -0
  172. package/dist/runtime/runtime-cpp/bom/history.ts +1 -0
  173. package/dist/runtime/runtime-cpp/bom/location.ts +1 -0
  174. package/dist/runtime/runtime-cpp/bom/navigator.ts +1 -0
  175. package/dist/runtime/runtime-cpp/bom/raf.ts +1 -0
  176. package/dist/runtime/runtime-cpp/bom/window.ts +57 -0
  177. package/dist/runtime/runtime-cpp/constant.ts +29 -0
  178. package/dist/runtime/runtime-cpp/current.ts +48 -0
  179. package/dist/runtime/runtime-cpp/dom/class-list.ts +41 -0
  180. package/dist/runtime/runtime-cpp/dom/comment.ts +9 -0
  181. package/dist/runtime/runtime-cpp/dom/dataSource.ts +87 -0
  182. package/dist/runtime/runtime-cpp/dom/document.ts +113 -0
  183. package/dist/runtime/runtime-cpp/dom/element/canvas.ts +285 -0
  184. package/dist/runtime/runtime-cpp/dom/element/element.ts +262 -0
  185. package/dist/runtime/runtime-cpp/dom/element/form.ts +371 -0
  186. package/dist/runtime/runtime-cpp/dom/element/index.ts +129 -0
  187. package/dist/runtime/runtime-cpp/dom/element/movable.ts +250 -0
  188. package/dist/runtime/runtime-cpp/dom/element/normal.ts +123 -0
  189. package/dist/runtime/runtime-cpp/dom/element/scroll_view.ts +32 -0
  190. package/dist/runtime/runtime-cpp/dom/element/text.ts +9 -0
  191. package/dist/runtime/runtime-cpp/dom/element/video.ts +66 -0
  192. package/dist/runtime/runtime-cpp/dom/element/web_view.ts +72 -0
  193. package/dist/runtime/runtime-cpp/dom/event-source.ts +1 -0
  194. package/dist/runtime/runtime-cpp/dom/event.ts +187 -0
  195. package/dist/runtime/runtime-cpp/dom/eventTarget.ts +81 -0
  196. package/dist/runtime/runtime-cpp/dom/node.ts +307 -0
  197. package/dist/runtime/runtime-cpp/dom/style.ts +44 -0
  198. package/dist/runtime/runtime-cpp/dom/stylesheet/index.ts +379 -0
  199. package/dist/runtime/runtime-cpp/dom/stylesheet/type.ts +212 -0
  200. package/dist/runtime/runtime-cpp/dom/stylesheet/util.ts +186 -0
  201. package/dist/runtime/runtime-cpp/emitter/emitter.ts +29 -0
  202. package/dist/runtime/runtime-cpp/env.ts +1 -0
  203. package/dist/runtime/runtime-cpp/harmony-library.ts +1 -0
  204. package/dist/runtime/runtime-cpp/index.ts +79 -0
  205. package/dist/runtime/runtime-cpp/interface/event.ts +10 -0
  206. package/dist/runtime/runtime-cpp/interface/index.ts +7 -0
  207. package/dist/runtime/runtime-cpp/next-tick.ts +14 -0
  208. package/dist/runtime/runtime-cpp/system.ts +213 -0
  209. package/dist/runtime/runtime-cpp/utils/index.ts +63 -0
  210. package/dist/runtime/runtime-cpp/utils/info.ts +123 -0
  211. package/dist/runtime/runtime-cpp/utils/page.ts +12 -0
  212. package/dist/runtime/runtime-cpp/utils/router.ts +1 -0
  213. package/dist/runtime/runtime-harmony/apis/helper.ets +33 -0
  214. package/dist/runtime/runtime-harmony/apis/network/common.ets +41 -0
  215. package/dist/runtime/runtime-harmony/apis/network/downloadFile.ets +327 -0
  216. package/dist/runtime/runtime-harmony/apis/network/index.ets +58 -0
  217. package/dist/runtime/runtime-harmony/apis/network/request.ets +206 -0
  218. package/dist/runtime/runtime-harmony/apis/network/uploadFile.ets +190 -0
  219. package/dist/runtime/runtime-harmony/apis/route.ets +110 -0
  220. package/dist/runtime/runtime-harmony/apis/taskpool.ets +149 -0
  221. package/dist/runtime/runtime-harmony/index.ets +41 -0
  222. package/dist/runtime/runtime-harmony/utils.ts +53 -0
  223. package/package.json +25 -23
  224. package/static/@taro-oh/library-4.1.1-alpha.0.har +0 -0
  225. package/LICENSE +0 -174
@@ -0,0 +1,43 @@
1
+ import { BUTTON_THEME_COLOR } from './utils/constant/style'
2
+
3
+ import type { TaroAny, TaroButtonElement, TaroElement, TaroObject } from '../runtime'
4
+
5
+ export function getButtonColor (node: TaroButtonElement, color: ResourceColor) {
6
+ const _attrs: TaroAny = node._attrs
7
+ const isDisabled: boolean = _attrs.disabled || false
8
+ const isPlain: boolean = _attrs.plain || false
9
+ const type: string = _attrs.type || 'default'
10
+
11
+ if (isDisabled && isPlain) {
12
+ return Color.Black
13
+ }
14
+
15
+ if (isPlain) {
16
+ return BUTTON_THEME_COLOR.get(type).plainText
17
+ }
18
+
19
+ return color
20
+ }
21
+
22
+ export function getImageMode (mode: string): ImageFit {
23
+ switch (mode) {
24
+ case 'aspectFit': return ImageFit.Contain
25
+ case 'aspectFill': return ImageFit.Cover
26
+ case 'scaleToFill': return ImageFit.Fill
27
+ case 'widthFix': return ImageFit.Auto
28
+ case 'heightFix': return ImageFit.Auto
29
+ default: return ImageFit.Contain
30
+ }
31
+ }
32
+
33
+ @ComponentV2
34
+ export struct TaroDeprecated {
35
+ @Builder customBuilder() {}
36
+ @BuilderParam createChildItem?: (node: TaroElement, callback?: (node: TaroElement) => void) => void = this.customBuilder
37
+ @BuilderParam createLazyChildren?: (node: TaroElement, layer?: number) => void = this.customBuilder
38
+
39
+ @Param node: TaroObject = {}
40
+
41
+ build() {
42
+ }
43
+ }
@@ -0,0 +1,49 @@
1
+ export {
2
+ TaroDeprecated as TaroView,
3
+ TaroDeprecated as TaroImage,
4
+ TaroDeprecated as TaroText,
5
+ TaroDeprecated as TaroIcon,
6
+ TaroDeprecated as TaroInput,
7
+ TaroDeprecated as TaroTextArea,
8
+ TaroDeprecated as TaroButton,
9
+ TaroDeprecated as TaroSwiper,
10
+ TaroDeprecated as TaroScrollView,
11
+ TaroDeprecated as TaroScrollList,
12
+ TaroDeprecated as TaroListView,
13
+ TaroDeprecated as TaroMovableArea,
14
+ TaroDeprecated as TaroMovableView,
15
+ TaroDeprecated as TaroPicker,
16
+ TaroDeprecated as TaroProgress,
17
+ TaroDeprecated as TaroWaterFlow,
18
+ TaroDeprecated as TaroWaterFlowView,
19
+ TaroDeprecated as TaroList,
20
+ TaroDeprecated as TaroStickySection,
21
+ TaroDeprecated as TaroRadioGroup,
22
+ TaroDeprecated as TaroRadio,
23
+ TaroDeprecated as TaroCheckboxGroup,
24
+ TaroDeprecated as TaroCheckbox,
25
+ TaroDeprecated as TaroLabel,
26
+ TaroDeprecated as TaroCanvas,
27
+ TaroDeprecated as TaroForm,
28
+ getButtonColor, getImageMode
29
+ } from './deprecated'
30
+
31
+ export { TaroXComponent } from './xComponent'
32
+ export { default as TaroNavigationBar } from './navigationBar'
33
+
34
+ export { default as TaroVideo } from './video'
35
+ export { default as TaroSlider } from './slider'
36
+ export { default as TaroSwitch } from './switch'
37
+ export { default as TaroWebView } from './webView'
38
+ export { default as TaroRichText } from './richText'
39
+ export { default as TaroInnerHtml } from './innerHtml'
40
+ export { default as TaroPageMeta, IComponentAttributeUpdateEvents } from './pageMeta'
41
+
42
+ export { default as commonStyleModify, rowModify, columnModify, textModify, setNormalTextAttributeIntoInstance } from './style'
43
+ export { TOUCH_EVENT_MAP } from './utils/constant/event'
44
+ export { BUTTON_THEME_COLOR } from './utils/constant/style'
45
+ export { DynamicCenter } from './utils/DynamicCenter'
46
+ export { FlexManager } from './utils/flexManager'
47
+ export { isTagFirstChild } from './utils/helper'
48
+ export { getStyleAttr } from './utils/styles'
49
+ export { shouldBindEvent, getNodeThresholds, getNormalAttributes, getFontAttributes } from './utils/helper'
@@ -0,0 +1,16 @@
1
+ import htmlParser from './utils/htmlParser'
2
+
3
+ import type { TaroElement, TaroInnerHtmlElement } from '@tarojs/runtime'
4
+
5
+ @Component
6
+ export default struct TaroInnerHtml {
7
+ @Builder customBuilder() {}
8
+ @BuilderParam createChildItem: (node: TaroElement, callback?: (node: TaroElement) => void) => void = this.customBuilder
9
+ @ObjectLink node: TaroInnerHtmlElement
10
+
11
+ build() {
12
+ if (this.node?.hmStyle?.display !== 'none' && this.node.innerHTML) {
13
+ this.createChildItem(htmlParser(this.node.innerHTML)!)
14
+ }
15
+ }
16
+ }
@@ -0,0 +1,65 @@
1
+ import { eventCenter } from '@tarojs/runtime'
2
+
3
+ import { isTagFirstChild } from './utils/helper'
4
+
5
+ import type { IComponentAttributeUpdateEvents } from './pageMeta'
6
+ import type { TaroAny, TaroNavigationBarElement } from '@tarojs/runtime'
7
+
8
+ @Component
9
+ export default struct TaroNavigationBar {
10
+ @Builder customBuilder() {}
11
+ @BuilderParam createLazyChildren: (node: TaroNavigationBarElement, layer?: number) => void = this.customBuilder
12
+ @ObjectLink node: TaroNavigationBarElement
13
+
14
+ aboutToAppear(): void {
15
+ if (!isTagFirstChild(this.node, 'page-meta')) {
16
+ console.error('NavigationBar 只能是 PageMeta 内的第一个节点。')
17
+ }
18
+ if (this.node) {
19
+ this.node._instance = this
20
+ }
21
+
22
+ // FIXME 在 Harmony 提供 @Watch 文档后,根据 node 实际使用更细粒度的监听
23
+ eventCenter.on('__taroComponentAttributeUpdate', this.handleAttributeUpdate)
24
+ this.handleAttributes(this.node._attrs)
25
+ }
26
+
27
+ aboutToDisappear(): void {
28
+ eventCenter.off('__taroComponentAttributeUpdate', this.handleAttributeUpdate)
29
+ }
30
+
31
+ handleAttributeUpdate = (opt: IComponentAttributeUpdateEvents) => {
32
+ if (opt.id === this.node._nid.toString() && opt.tagName === 'NAVIGATION-BAR') {
33
+ const attrs: Record<string, TaroAny> = {}
34
+ attrs[opt.attribute] = opt.value
35
+ this.handleAttributes(attrs)
36
+ }
37
+ }
38
+
39
+ handleAttributes (attrs: Record<string, TaroAny>) {
40
+ const options: Record<string, TaroAny> = {}
41
+
42
+ if (attrs.title) {
43
+ options.title = attrs.title
44
+ }
45
+ if (attrs.loading) {
46
+ options.loading = attrs.loading
47
+ }
48
+ if (attrs.backgroundColor) {
49
+ options.backgroundColor = attrs.backgroundColor
50
+ }
51
+ if (attrs.frontColor) {
52
+ options.frontColor = attrs.frontColor
53
+ }
54
+ eventCenter?.trigger('__taroNavigationStyle', options)
55
+ // FIXME: 以下属性暂时不支持
56
+ // attrs.colorAnimationDuration
57
+ // attrs.colorAnimationTimingFunc
58
+ }
59
+
60
+ build() {
61
+ if (true) {
62
+ this.createLazyChildren(this.node, 0)
63
+ }
64
+ }
65
+ }
@@ -0,0 +1,94 @@
1
+ import { APP, eventCenter, getCurrentInstance } from '@tarojs/runtime'
2
+ import { pageScrollTo } from '@tarojs/taro'
3
+
4
+ import { isTagFirstChild } from './utils/helper'
5
+
6
+ import type { TaroAny, TaroPageMetaElement } from '@tarojs/runtime'
7
+
8
+ export interface IComponentAttributeUpdateEvents {
9
+ id: string
10
+ tagName: string
11
+ attribute: string
12
+ value: TaroAny
13
+ }
14
+
15
+ @Component
16
+ export default struct TaroPageMeta {
17
+ @Builder customBuilder() {}
18
+ @BuilderParam createLazyChildren: (node: TaroPageMetaElement, layer?: number) => void = this.customBuilder
19
+ @ObjectLink node: TaroPageMetaElement
20
+
21
+ page: TaroAny = {}
22
+
23
+ aboutToAppear(): void {
24
+ if (!isTagFirstChild(this.node, APP, 2)) {
25
+ // PageMeta 只能是页面内的第一个元素
26
+ console.error('PageMeta 只能是页面内的第一个元素。')
27
+ }
28
+
29
+ this.page = getCurrentInstance().page
30
+ if (this.node) {
31
+ this.node._instance = this
32
+ }
33
+
34
+ // FIXME 在 Harmony 提供 @Watch 文档后,根据 node 实际使用更细粒度的监听
35
+ eventCenter?.on('__taroComponentAttributeUpdate', this.handleAttributeUpdate)
36
+ this.handleAttributes(this.node._attrs)
37
+ }
38
+
39
+ aboutToDisappear(): void {
40
+ eventCenter?.off('__taroComponentAttributeUpdate', this.handleAttributeUpdate)
41
+ }
42
+
43
+ handleAttributeUpdate = (opt: IComponentAttributeUpdateEvents) => {
44
+ if (opt.id === this.node._nid.toString() && opt.tagName === 'PAGE-META') {
45
+ const attrs: Record<string, TaroAny> = {}
46
+ attrs[opt.attribute] = opt.value
47
+ this.handleAttributes(attrs)
48
+ }
49
+ }
50
+
51
+ handleAttributes (attrs: Record<string, TaroAny>) {
52
+ const options: Record<string, TaroAny> = {}
53
+ let triggerStyleEvent = false
54
+
55
+ // FIXME 更新类型支持度
56
+ if (attrs.backgroundColorTop || attrs.rootBackgroundColor || attrs.backgroundColor) {
57
+ options.backgroundColorContext = attrs.backgroundColorTop || attrs.rootBackgroundColor || attrs.backgroundColor
58
+ triggerStyleEvent = true
59
+ }
60
+ if (attrs.backgroundColorBottom || attrs.backgroundColor) {
61
+ options.backgroundColor = attrs.backgroundColorBottom || attrs.backgroundColor
62
+ triggerStyleEvent = true
63
+ }
64
+ if (attrs.backgroundTextStyle) {
65
+ options.backgroundTextStyle = attrs.backgroundTextStyle
66
+ triggerStyleEvent = true
67
+ }
68
+
69
+ if (this.page === getCurrentInstance().page) {
70
+ if (attrs.scrollTop || attrs.scrollDuration) {
71
+ pageScrollTo({
72
+ scrollTop: attrs.scrollTop || this.node._attrs.scrollTop,
73
+ duration: attrs.scrollDuration || this.node._attrs.scrollDuration,
74
+ } as TaroAny)
75
+ }
76
+ }
77
+ // pageStyle
78
+ // rootFontSize
79
+ // pageFontSize
80
+ // pageOrientation
81
+ if (triggerStyleEvent) {
82
+ eventCenter?.trigger('__taroPageStyle', options)
83
+ }
84
+ // onResize
85
+ // onScroll
86
+ // onScrollDone
87
+ }
88
+
89
+ build() {
90
+ if (true) {
91
+ this.createLazyChildren(this.node, 0)
92
+ }
93
+ }
94
+ }
@@ -0,0 +1,24 @@
1
+ import { AREA_CHANGE_EVENT_NAME, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME } from '@tarojs/runtime'
2
+
3
+ import commonStyleModify from './style'
4
+ import { generateText } from './utils'
5
+ import { getNodeThresholds } from './utils/helper'
6
+
7
+ import type { TaroAny, TaroRichTextElement } from '@tarojs/runtime'
8
+
9
+ @Component
10
+ export default struct TaroRichText {
11
+ @Builder customBuilder() {}
12
+ @BuilderParam createLazyChildren: (node: TaroRichTextElement, layer?: number) => void = this.customBuilder
13
+ @ObjectLink node: TaroRichTextElement
14
+
15
+ build () {
16
+ RichText(generateText(this.node))
17
+ .attributeModifier(commonStyleModify.setNode(this.node))
18
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
19
+ this.node._nodeInfo.areaInfo = res[1]
20
+ }))
21
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
22
+ }
23
+ }
24
+
@@ -0,0 +1,119 @@
1
+ import { AREA_CHANGE_EVENT_NAME, createTaroEvent, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME } from '@tarojs/runtime'
2
+
3
+ import commonStyleModify from './style'
4
+ import { getNodeThresholds } from './utils/helper'
5
+
6
+ import type { TaroAny, TaroEvent, TaroSliderElement } from '@tarojs/runtime'
7
+
8
+ @Extend(Slider)
9
+ function themeStyles(isDisabled: boolean) {
10
+ .opacity(isDisabled ? 0.4 : 1)
11
+ }
12
+
13
+ @ComponentV2
14
+ export default struct TaroSlider {
15
+ @Builder customBuilder() {}
16
+ @BuilderParam createLazyChildren: (node: TaroSliderElement) => void = this.customBuilder
17
+ @Param @Require node: TaroSliderElement
18
+
19
+ @Local attrMin: number = 0
20
+ @Local attrMax: number = 100
21
+ @Local attrStep: number = 1
22
+ @Local attrDisabled: boolean = false
23
+ @Local attrShowValue: boolean = false
24
+ @Local attrBlockColor?: ResourceColor = '#ffffff'
25
+ @Local attrActiveColor?: ResourceColor = '#1aad19'
26
+ @Local attrSelectedColor?: ResourceColor = '#1aad19'
27
+ @Local attrBackgroundColor?: ResourceColor = '#e9e9e9'
28
+ @Local attrColor?: ResourceColor = '#e9e9e9'
29
+ @Local attrBlockSize?: Length
30
+ @Local value: number = 0
31
+
32
+ @Computed get computedSelectedColor () {
33
+ return this.attrActiveColor || this.attrSelectedColor || '#1aad19'
34
+ }
35
+
36
+ @Computed get computedTrackColor () {
37
+ return this.attrBackgroundColor || this.attrColor || '#e9e9e9'
38
+ }
39
+
40
+ aboutToAppear () {
41
+ if (this.node) {
42
+ this.node._instance = this
43
+ this.attrMin = this.node._attrs?.min ?? this.attrMin
44
+ this.attrMax = this.node._attrs?.max ?? this.attrMax
45
+ this.attrStep = this.node._attrs?.step ?? this.attrStep
46
+ this.attrDisabled = this.node._attrs?.disabled ?? this.attrDisabled
47
+ this.attrShowValue = this.node._attrs?.showValue ?? this.attrShowValue
48
+ this.attrBlockColor = this.node._attrs?.blockColor ?? this.attrBlockColor
49
+ this.attrActiveColor = this.node._attrs?.activeColor ?? this.attrActiveColor
50
+ this.attrSelectedColor = this.node._attrs?.selectedColor ?? this.attrSelectedColor
51
+ this.attrBackgroundColor = this.node._attrs?.backgroundColor ?? this.attrBackgroundColor
52
+ this.attrColor = this.node._attrs?.color ?? this.attrColor
53
+ this.attrBlockSize = this.node._attrs?.blockSize ?? this.attrBlockSize
54
+ this.value = this.node.value ?? this.value
55
+
56
+ if (!this.node._isInit) {
57
+ this.node._isInit = true
58
+ this.node._reset = this.node.value || 0
59
+ }
60
+ }
61
+ }
62
+
63
+ @Builder createSlider (node: TaroSliderElement) {
64
+ Slider({
65
+ min: Number(this.attrMin || 0),
66
+ max: Number(this.attrMax || 100),
67
+ value: this.value,
68
+ step: Number(this.attrStep || 1),
69
+ style: SliderStyle.OutSet,
70
+ direction: Axis.Horizontal
71
+ })
72
+ .attributeModifier(commonStyleModify.setNode(node))
73
+ .selectedColor(this.computedSelectedColor)
74
+ .trackColor(this.computedTrackColor)
75
+ .trackThickness(this.attrBlockSize)
76
+ .blockColor(this.attrBlockColor || '#ffffff')
77
+ .enabled(!this.attrDisabled)
78
+ .width(!!this.attrShowValue ? '90%' : '100%')
79
+ .themeStyles(!!this.attrDisabled)
80
+ .onChange((value: number, mode: SliderChangeMode) => {
81
+ if (!!this.attrDisabled) {
82
+ if (mode === SliderChangeMode.End) {
83
+ this.node?.updateComponent()
84
+ }
85
+ } else {
86
+ this.value = value
87
+ this.node?.updateFormWidgetValue(value)
88
+
89
+ if (mode === SliderChangeMode.End) {
90
+ const event: TaroEvent = createTaroEvent('change', { detail: { value: this.value } }, node)
91
+ eventHandler(event, 'change', node)
92
+ } else if (mode === SliderChangeMode.Moving) {
93
+ const event: TaroEvent = createTaroEvent('changing', { detail: { value: this.value } }, node)
94
+ eventHandler(event, 'changing', node)
95
+ }
96
+ }
97
+ })
98
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
99
+ if (this.node) {
100
+ this.node._nodeInfo.areaInfo = res[1]
101
+ }
102
+ }))
103
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
104
+ }
105
+
106
+ build() {
107
+ if (!!this.attrShowValue) {
108
+ Row() {
109
+ this.createSlider(this.node)
110
+ Text(Number(this.value).toFixed(0))
111
+ .width('10%')
112
+ .textAlign(TextAlign.Center)
113
+ .opacity(!!this.attrDisabled ? 0.4 : 1)
114
+ }
115
+ } else {
116
+ this.createSlider(this.node)
117
+ }
118
+ }
119
+ }
@@ -0,0 +1,286 @@
1
+ import { isUndefined } from '@tarojs/shared'
2
+ import { ObjectAssign } from '@tarojs/runtime'
3
+
4
+ import { computeBackgroundPosition, convertVp2Px } from './utils'
5
+ import { getNormalAttributes } from './utils/helper'
6
+ import { isMaxWidthView } from './utils/styles'
7
+
8
+ import type { TaroAny, HarmonyStyle, TaroElement, TaroStyleType, TaroTextElement } from '@tarojs/runtime'
9
+
10
+ class CommonStyleModify<T extends CommonAttribute = CommonAttribute> implements AttributeModifier<T> {
11
+ initStyle?: TaroStyleType
12
+ node: TaroElement | null = null
13
+ style: TaroStyleType | null = null
14
+ overwriteStyle: TaroStyleType = {}
15
+
16
+ setNode (node: TaroElement, initStyle?: TaroStyleType) {
17
+ this.node = node
18
+ this.style = getNormalAttributes(this.node)
19
+ this.initStyle = initStyle
20
+ this.overwriteStyle = {}
21
+ // 覆盖初始化样式
22
+ if (initStyle) {
23
+ Object.keys(initStyle).forEach(key => {
24
+ if (this.style && !this.style[key]) {
25
+ this.style[key] = initStyle[key]
26
+ }
27
+ })
28
+ }
29
+ return this
30
+ }
31
+
32
+ setAnimationStyle (overwriteStyle: Record<string, TaroAny>) {
33
+ this.overwriteStyle = overwriteStyle
34
+ if (this.style && this.overwriteStyle && Object.keys(this.overwriteStyle).length) {
35
+ // 防止污染原始样式
36
+ this.style = ObjectAssign({}, this.style)
37
+ Object.keys(this.overwriteStyle).forEach(key => {
38
+ this.style![key] = this.overwriteStyle[key]
39
+ })
40
+ }
41
+ return this
42
+ }
43
+
44
+ applyNormalAttribute(instance: T): void {
45
+ if (this.node && this.style) {
46
+ setNormalAttributeIntoInstance(instance, this.style, this.node)
47
+ setTransformAttributeIntoInstance(instance, this.style || {})
48
+ }
49
+ }
50
+ }
51
+
52
+ class TextStyleModify extends CommonStyleModify<TextAttribute> {
53
+ withNormal: boolean = false
54
+
55
+ setNode (node: TaroTextElement, initStyle?: HarmonyStyle) {
56
+ this.withNormal = false
57
+ super.setNode(node, initStyle)
58
+ return this
59
+ }
60
+
61
+ withNormalStyle () {
62
+ this.withNormal = true
63
+ return this
64
+ }
65
+
66
+ applyNormalAttribute(instance: TextAttribute): void {
67
+ if (this.node && this.style) {
68
+ if (this.withNormal) {
69
+ setNormalAttributeIntoInstance(instance, this.style, this.node)
70
+ setTransformAttributeIntoInstance(instance, this.style || {})
71
+ }
72
+ setNormalTextAttributeIntoInstance(instance, this.style, this.node)
73
+ }
74
+ }
75
+ }
76
+
77
+ export function setTransformAttributeIntoInstance(instance: CommonAttribute, style: TaroStyleType) {
78
+ // Animation 需要提前和 @State 变量绑定才能产生动画效果,因此不能做 if else 判断
79
+ instance.translate({
80
+ x: style.transform?.Translate?.x,
81
+ y: style.transform?.Translate?.y,
82
+ z: style.transform?.Translate?.z,
83
+ })
84
+ instance.scale({
85
+ x: style.transform?.Scale?.x,
86
+ y: style.transform?.Scale?.y,
87
+ z: style.transform?.Scale?.z,
88
+ centerX: style.transformOrigin?.x,
89
+ centerY: style.transformOrigin?.y,
90
+ })
91
+ instance.rotate({
92
+ x: style.transform?.Rotate?.x,
93
+ y: style.transform?.Rotate?.y,
94
+ z: style.transform?.Rotate?.z,
95
+ centerX: style.transformOrigin?.x,
96
+ centerY: style.transformOrigin?.y,
97
+ angle: style.transform?.Rotate?.angle || 0,
98
+ })
99
+ }
100
+
101
+ export function setNormalTextAttributeIntoInstance(instance: TextAttribute | SpanAttribute, style: HarmonyStyle, node?: TaroTextElement | null) {
102
+ if (!isUndefined(style.color)) {
103
+ instance.fontColor(style.color)
104
+ }
105
+ if (!isUndefined(style.fontSize)) {
106
+ instance.fontSize(style.fontSize)
107
+ }
108
+ if (!isUndefined(style.fontWeight)) {
109
+ instance.fontWeight(style.fontWeight)
110
+ }
111
+ if (!isUndefined(style.fontStyle)) {
112
+ instance.fontStyle(style.fontStyle)
113
+ }
114
+ if (!isUndefined(style.fontFamily)) {
115
+ instance.fontFamily(style.fontFamily)
116
+ }
117
+ if (!isUndefined(style.textDecoration)) {
118
+ instance.decoration({
119
+ type: style.textDecoration!.type,
120
+ color: style.color
121
+ })
122
+ }
123
+ }
124
+
125
+ export function setNormalAttributeIntoInstance(instance: CommonAttribute, style: TaroStyleType, node?: TaroElement | null) {
126
+ instance.renderFit(RenderFit.RESIZE_FILL)
127
+ if (!isUndefined(style.id)) {
128
+ instance.id(style.id)
129
+ instance.key(style.id)
130
+ }
131
+ if (!isUndefined(style.display) || !isUndefined(style.visibility)) {
132
+ instance.visibility(style.display === 'none'
133
+ ? Visibility.None :
134
+ !isUndefined(style.visibility)
135
+ ? (style.visibility === 'hidden' ? Visibility.Hidden : Visibility.Visible)
136
+ : Visibility.Visible
137
+ )
138
+ }
139
+ if (!isUndefined(style.flexGrow)) {
140
+ instance.flexGrow(style.flexGrow)
141
+ }
142
+ if (!isUndefined(style.flexShrink)) {
143
+ instance.flexShrink(style.flexShrink)
144
+ }
145
+ if (!isUndefined(style.flexBasis)) {
146
+ instance.flexBasis(style.flexBasis)
147
+ }
148
+ if (!isUndefined(style.alignSelf)) {
149
+ instance.alignSelf(style.alignSelf)
150
+ }
151
+ if (!isUndefined(style.paddingTop) || !isUndefined(style.paddingRight) || !isUndefined(style.paddingBottom) || !isUndefined(style.paddingLeft)) {
152
+ instance.padding({
153
+ top: style.paddingTop,
154
+ right: style.paddingRight,
155
+ bottom: style.paddingBottom,
156
+ left: style.paddingLeft
157
+ })
158
+ }
159
+ if (!isUndefined(style.marginTop) || !isUndefined(style.marginRight) || !isUndefined(style.marginBottom) || !isUndefined(style.marginLeft)) {
160
+ instance.margin({
161
+ top: style.marginTop,
162
+ right: style.marginRight,
163
+ bottom: style.marginBottom,
164
+ left: style.marginLeft
165
+ })
166
+ }
167
+ if (node) {
168
+ instance.width(isMaxWidthView(node as TaroElement) && isUndefined(style.width) ? '100%' : style.width)
169
+ } else {
170
+ if (!isUndefined(style.width)) {
171
+ instance.width(style.width)
172
+ }
173
+ }
174
+ if (!isUndefined(style.height)) {
175
+ instance.height(style.height)
176
+ }
177
+ if (!isUndefined(style.minWidth) || !isUndefined(style.maxWidth) || !isUndefined(style.minHeight) || !isUndefined(style.maxHeight)) {
178
+ instance.constraintSize({
179
+ minWidth: style.minWidth,
180
+ maxWidth: style.maxWidth,
181
+ minHeight: style.minHeight,
182
+ maxHeight: style.maxHeight
183
+ })
184
+ }
185
+ if (!isUndefined(style.backgroundColor)) {
186
+ instance.backgroundColor(style.backgroundColor)
187
+ }
188
+ if (!isUndefined(style.backgroundImage)) {
189
+ if (style.backgroundImage.center) {
190
+ // radialGradient
191
+ instance.radialGradient(style.backgroundImage)
192
+ } else if (style.backgroundImage.colors) {
193
+ // linearGradient
194
+ instance.linearGradient(style.backgroundImage)
195
+ } else {
196
+ instance.backgroundImage(style.backgroundImage?.src, style.backgroundRepeat)
197
+ }
198
+ }
199
+ if (!isUndefined(style.backgroundSize)) {
200
+ instance.backgroundImageSize(style.backgroundSize)
201
+ }
202
+ if (!isUndefined(style.backgroundPosition)) {
203
+ if (typeof style.backgroundPosition !== 'number') {
204
+ let pos = computeBackgroundPosition(style)
205
+ instance.backgroundImagePosition({
206
+ x: pos.offsetX,
207
+ y: pos.offsetY,
208
+ })
209
+ } else {
210
+ instance.backgroundImagePosition(style.backgroundPosition)
211
+ }
212
+ }
213
+ if (!isUndefined(style.borderTopStyle) || !isUndefined(style.borderRightStyle) || !isUndefined(style.borderBottomStyle) || !isUndefined(style.borderLeftStyle)) {
214
+ instance.borderStyle({
215
+ top: style.borderTopStyle,
216
+ right: style.borderRightStyle,
217
+ bottom: style.borderBottomStyle,
218
+ left: style.borderLeftStyle
219
+ })
220
+ }
221
+ if (!isUndefined(style.borderTopWidth) || !isUndefined(style.borderRightWidth) || !isUndefined(style.borderBottomWidth) || !isUndefined(style.borderLeftWidth)) {
222
+ instance.borderWidth({
223
+ top: style.borderTopWidth,
224
+ right: style.borderRightWidth,
225
+ bottom: style.borderBottomWidth,
226
+ left: style.borderLeftWidth
227
+ })
228
+ }
229
+ if (!isUndefined(style.borderTopColor) || !isUndefined(style.borderRightColor) || !isUndefined(style.borderBottomColor) || !isUndefined(style.borderLeftColor)) {
230
+ instance.borderColor({
231
+ top: style.borderTopColor,
232
+ right: style.borderRightColor,
233
+ bottom: style.borderBottomColor,
234
+ left: style.borderLeftColor
235
+ })
236
+ }
237
+ if (!isUndefined(style.borderTopLeftRadius) || !isUndefined(style.borderTopRightRadius) || !isUndefined(style.borderBottomLeftRadius) || !isUndefined(style.borderBottomRightRadius)) {
238
+ instance.borderRadius({
239
+ topLeft: style.borderTopLeftRadius,
240
+ topRight: style.borderTopRightRadius,
241
+ bottomLeft: style.borderBottomLeftRadius,
242
+ bottomRight: style.borderBottomRightRadius
243
+ })
244
+ }
245
+ if (!isUndefined(style.opacity)) {
246
+ instance.opacity(style.opacity)
247
+ }
248
+ if (!isUndefined(style.overflow)) {
249
+ instance.clip(style.overflow === 'hidden')
250
+ }
251
+ if (style.position === 'absolute' || style.position === 'fixed') {
252
+ instance.position({
253
+ x: style.left || 0,
254
+ y: style.top || 0,
255
+ })
256
+ // 绝对定位和固定定位在web上都会脱离文档流,因此需要设置zIndex让它相比正常流的元素更上层
257
+ instance.zIndex(1)
258
+ }
259
+ if (style.position === 'relative') {
260
+ instance.offset({
261
+ x: style.left || 0,
262
+ y: style.top || 0,
263
+ })
264
+ // 绝对定位和固定定位在web上都会脱离文档流,因此需要设置zIndex让它相比正常流的元素更上层
265
+ instance.zIndex(1)
266
+ }
267
+ if (!isUndefined(style.zIndex)) {
268
+ // 为了适应position不设置z-index也能高于同层级组件,估且让设置了z-index的会更高一级
269
+ instance.zIndex(style.zIndex! + 1)
270
+ }
271
+ if (!isUndefined(style.boxShadow)) {
272
+ instance.shadow({
273
+ radius: convertVp2Px(style.boxShadow!.radius),
274
+ color: style.boxShadow!.color,
275
+ offsetX: convertVp2Px(style.boxShadow!.offsetX),
276
+ offsetY: convertVp2Px(style.boxShadow!.offsetY),
277
+ fill: style.boxShadow!.fill,
278
+ })
279
+ }
280
+ }
281
+
282
+ export const rowModify = new CommonStyleModify()
283
+ export const columnModify = new CommonStyleModify()
284
+ export const textModify = new TextStyleModify()
285
+
286
+ export default new CommonStyleModify()