@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,73 @@
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, TaroSwitchElement, TaroEvent } from '@tarojs/runtime'
7
+
8
+ interface SwitchAttrs {
9
+ selectedColor?: ResourceColor
10
+ disabled?: boolean
11
+ }
12
+
13
+ @Extend(Toggle)
14
+ function attrs(attr: SwitchAttrs) {
15
+ .selectedColor(attr.selectedColor)
16
+ .enabled(!attr.disabled)
17
+ }
18
+
19
+ function getAttributes (node: TaroSwitchElement): SwitchAttrs {
20
+ const attr: SwitchAttrs = {}
21
+ attr.selectedColor = node._attrs.color || '#04BE02'
22
+ attr.disabled = !!node._attrs.disabled
23
+ return attr
24
+ }
25
+
26
+ @Extend(Toggle)
27
+ function themeStyles(isDisabled: boolean) {
28
+ .opacity(isDisabled ? 0.4 : 1)
29
+ }
30
+
31
+ @Component
32
+ export default struct TaroSwitch {
33
+ @Builder customBuilder() {}
34
+ @BuilderParam createLazyChildren: (node: TaroSwitchElement, layer?: number) => void = this.customBuilder
35
+ @ObjectLink node: TaroSwitchElement
36
+ @State overwriteStyle: Record<string, TaroAny> = {}
37
+
38
+ aboutToAppear () {
39
+ if (this.node && !this.node._isInit) {
40
+ this.node._isInit = true
41
+ this.node._instance = this
42
+ this.node._reset = this.node.checked || false
43
+ }
44
+ }
45
+
46
+ build () {
47
+ Toggle({
48
+ type: this.node._attrs.type !== 'checkbox' ? ToggleType.Switch : ToggleType.Checkbox,
49
+ isOn: this.node.checked,
50
+ })
51
+ .attrs(getAttributes(this.node))
52
+ .margin(0)
53
+ .themeStyles(!!this.node._attrs.disabled)
54
+ .onChange((isOn: boolean) => {
55
+ if (this.node) {
56
+ if (!this.node?._attrs.disabled) {
57
+ const event: TaroEvent = createTaroEvent('change', { detail: { value: isOn } }, this.node)
58
+
59
+ this.node.updateCheckedValue(isOn)
60
+ eventHandler(event, 'change', this.node)
61
+ } else {
62
+ this.node.updateComponent()
63
+ }
64
+ }
65
+ })
66
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
67
+ if (this.node) {
68
+ this.node._nodeInfo.areaInfo = res[1]
69
+ }
70
+ }))
71
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
72
+ }
73
+ }
@@ -0,0 +1,58 @@
1
+ export const TaroViewTagName = 'view'
2
+ export const TaroIconTagName = 'icon'
3
+ export const TaroProgressTagName = 'progress'
4
+ export const TaroRichTextTagName = 'rich-text'
5
+ export const TaroTextTagName = 'text'
6
+ export const TaroButtonTagName = 'button'
7
+ export const TaroCheckboxTagName = 'checkbox'
8
+ export const TaroCheckboxGroupTagName = 'checkbox-group'
9
+ export const TaroFormTagName = 'form'
10
+ export const TaroInputTagName = 'input'
11
+ export const TaroLabelTagName = 'label'
12
+ export const TaroPickerTagName = 'picker'
13
+ export const TaroPickerViewTagName = 'picker-view'
14
+ export const TaroPickerViewColumnTagName = 'picker-view-column'
15
+ export const TaroRadioTagName = 'radio'
16
+ export const TaroRadioGroupTagName = 'radio-group'
17
+ export const TaroSliderTagName = 'slider'
18
+ export const TaroSwitchTagName = 'switch'
19
+ export const TaroCoverImageTagName = 'cover-image'
20
+ export const TaroTextareaTagName = 'textarea'
21
+ export const TaroCoverViewTagName = 'cover-view'
22
+ export const TaroMovableAreaTagName = 'movable-area'
23
+ export const TaroMovableViewTagName = 'movable-view'
24
+ export const TaroScrollViewTagName = 'scroll-view'
25
+ export const TaroSwiperTagName = 'swiper'
26
+ export const TaroSwiperItemTagName = 'swiper-item'
27
+ export const TaroNavigatorTagName = 'navigator'
28
+ export const TaroAudioTagName = 'audio'
29
+ export const TaroCameraTagName = 'camera'
30
+ export const TaroImageTagName = 'image'
31
+ export const TaroLivePlayerTagName = 'live-player'
32
+ export const TaroVideoTagName = 'video'
33
+ export const TaroCanvasTagName = 'canvas'
34
+ export const TaroAdTagName = 'ad'
35
+ export const TaroWebViewTagName = 'web-view'
36
+ export const TaroBlockTagName = 'block'
37
+ export const TaroMapTagName = 'map'
38
+ export const TaroPageMetaTagName = 'page-meta'
39
+ export const TaroNavigationBarTagName = 'navigation-bar'
40
+ export const TaroSlotTagName = 'slot'
41
+ export const TaroNativeSlotTagName = 'native-slot'
42
+ export const TaroCustomWrapperTagName = 'custom-wrapper'
43
+
44
+ export const TaroSpanTagName = 'span'
45
+ export const TaroTabsTagName = 'tabs'
46
+ export const TaroTabBarTagName = 'tab-bar'
47
+ export const TaroTabContentTagName = 'tab-content'
48
+ export const TaroListTagName = 'list'
49
+ export const TaroListItemTagName = 'list-item'
50
+ export const TaroOpenDataTagName = 'open-data'
51
+ export const TaroIgnoreTagName = 'ignore'
52
+
53
+ export const TaroStickySectionTagName = 'sticky-section'
54
+ export const TaroStickyHeaderTagName = 'sticky-header'
55
+ export const TaroListViewTagName = 'list-view'
56
+ export const TaroWaterFlowTagName = 'water-flow'
57
+ export const TaroFlowSectionTagName = 'flow-section'
58
+ export const TaroFlowItemTagName = 'flow-item'
@@ -0,0 +1,252 @@
1
+ import matrix4 from '@ohos.matrix4'
2
+ import { convertNumber2VP } from '@tarojs/runtime'
3
+
4
+ import type { TaroAny } from '@tarojs/runtime'
5
+
6
+ type matrixNums = [number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number]
7
+
8
+ interface IRotate {
9
+ x?: number,
10
+ y?: number,
11
+ z?: number,
12
+ angle: number | string,
13
+ centerX?: number | string,
14
+ centerY?: number | string
15
+ }
16
+
17
+ interface ITranslate {
18
+ x?: number | string,
19
+ y?: number | string,
20
+ z? : number | string
21
+ }
22
+
23
+ interface IScale {
24
+ x?: number,
25
+ y?: number,
26
+ z?: number,
27
+ centerX?: number | string,
28
+ centerY?: number | string
29
+ }
30
+
31
+ interface ITransform {
32
+ rotate: IRotate
33
+ translate: ITranslate
34
+ scale: IScale
35
+ transform?: matrix4.Matrix4Transit
36
+ }
37
+
38
+ class AttributeManager {
39
+
40
+ static getNodeStyle<T = TaroAny> (style: TaroAny = {}, name: string, defaultValue?: TaroAny): T {
41
+ const res: TaroAny = style[name]
42
+
43
+ if (res === undefined) return defaultValue
44
+
45
+ return res
46
+ }
47
+
48
+ static getTextAlign (style: TaroAny = {}): TextAlign {
49
+ const value: string = style.textAlign
50
+ switch (value) {
51
+ case 'right':
52
+ return TextAlign.End
53
+ case 'center':
54
+ return TextAlign.Center
55
+ default:
56
+ return TextAlign.Start
57
+ }
58
+ }
59
+
60
+ static getNodeAnimationData (style: TaroAny = {}): TaroAny {
61
+ let res: TaroAny = {}
62
+ const dataValue: string = AttributeManager.getNodeStyle(style, 'animation')
63
+
64
+ if (dataValue) {
65
+ let values: string[] = dataValue.toString().trim().split(new RegExp("/\s+/"))
66
+ switch (values.length) {
67
+ case 4:
68
+ res = { duration: values[0], curve: values[1], delay: values[2] }
69
+ break
70
+ case 8:
71
+ res = { duration: values[0], curve: values[1], delay: values[2], iterations: values[3], playMode: values[4] }
72
+ break
73
+ default:
74
+ break
75
+ }
76
+
77
+ Object.keys(res).forEach(key => {
78
+ if (!isNaN(res[key]) && values.length > 1) {
79
+ res[key] = convertNumber2VP(res[key])
80
+ }
81
+ })
82
+ }
83
+
84
+ let playMode: PlayMode
85
+ switch (AttributeManager.getNodeStyle(style, 'animationDirection') || res.playMode) {
86
+ case 'reverse':
87
+ playMode = PlayMode.Reverse
88
+ break
89
+ case 'alternate':
90
+ playMode = PlayMode.Alternate
91
+ break
92
+ case 'alternate-reverse':
93
+ playMode = PlayMode.AlternateReverse
94
+ break
95
+ case 'normal':
96
+ default:
97
+ playMode = PlayMode.Normal
98
+ }
99
+ return {
100
+ duration: AttributeManager.parseTime2Number(AttributeManager.getNodeStyle(style, 'animationDuration') || res.duration || 1000),
101
+ tempo: 1,
102
+ curve: AttributeManager.getNodeStyle(style, 'animationTimingFunction') || res.curve || Curve.EaseInOut,
103
+ delay: AttributeManager.parseTime2Number(AttributeManager.getNodeStyle(style, 'animationDelay') || res.delay || 0),
104
+ iterations: Number(AttributeManager.getNodeStyle(style, 'animationIterationCount') || res.iterations) || 1,
105
+ playMode,
106
+ // TODO onFinish
107
+ }
108
+ }
109
+
110
+ static parseTime2Number (time = ''): number {
111
+ if (typeof time === 'number') return time
112
+ if (time === 'infinite') return Infinity
113
+ if (time === 'auto') return 0
114
+
115
+ const matchs = time.match(new RegExp("/^(\d*)([a-z]*)$/")) || []
116
+
117
+ const value = matchs[1]
118
+ const unit = matchs[2]
119
+
120
+ let ms = Number(value)
121
+ switch (unit) {
122
+ case 's':
123
+ ms *= 1000
124
+ break
125
+ case 'ms':
126
+ default:
127
+ ms *= 1
128
+ }
129
+ return ms
130
+ }
131
+
132
+ static getTransform(style: TaroAny = {}): ITransform {
133
+ const transform: string = style.transform || ''
134
+ const transformOrigin: string = AttributeManager.getNodeStyle(style, 'transformOrigin') || '0 0'
135
+
136
+ const origin: (string | number)[] = transformOrigin.split(new RegExp("/\s+/")).map(item => item)
137
+
138
+ const result: ITransform = {
139
+ rotate: { angle: 0 },
140
+ translate: {},
141
+ scale: {},
142
+ }
143
+ let resultTransform: matrix4.Matrix4Transit
144
+
145
+ const matches: string[] = transform.match(new RegExp("/(\w+)\(([^)]+)\)/g")) || [];
146
+
147
+ // 处理matrix
148
+
149
+ matches.forEach(match => {
150
+ const matchs = match.split(new RegExp("/\(|\)/")).filter(Boolean);
151
+ const name: string = matchs[0]
152
+ const params: string[] = []
153
+ for (let i = 1; i < matchs.length; i++) {
154
+ params.push(matchs[i])
155
+ }
156
+
157
+ switch (name) {
158
+ case 'translateX':
159
+ result.translate.x = parseTransformUnit(params[0])
160
+ break;
161
+ case 'translateY':
162
+ result.translate.y = parseTransformUnit(params[0])
163
+ break;
164
+ case 'translateZ':
165
+ result.translate.z = parseTransformUnit(params[0])
166
+ break;
167
+ case 'scaleX':
168
+ result.scale.x = parseFloat(params[0])
169
+ break;
170
+ case 'scaleY':
171
+ result.scale.y = parseFloat(params[0])
172
+ break;
173
+ case 'scaleZ':
174
+ result.scale.z = parseFloat(params[0])
175
+ break;
176
+ case 'rotateX':
177
+ result.rotate.x = parseFloat(params[0])
178
+ break;
179
+ case 'rotateY':
180
+ result.rotate.y = parseFloat(params[0])
181
+ break;
182
+ case 'rotateZ':
183
+ result.rotate.z = parseFloat(params[0])
184
+ break;
185
+ case 'translate':
186
+ const xy = params[0].split(new RegExp("/\s*,\s*/"))
187
+ result.translate.x = parseTransformUnit(xy[0])
188
+ result.translate.y = parseTransformUnit(xy[1])
189
+ break;
190
+ case 'translate3d':
191
+ const xyz = params[0].split(new RegExp("/\s*,\s*/"))
192
+ result.translate.x = parseTransformUnit(xyz[0])
193
+ result.translate.y = parseTransformUnit(xyz[1])
194
+ result.translate.z = parseTransformUnit(xyz[2])
195
+ break;
196
+ case 'scale':
197
+ result.scale.x = parseFloat(params[0])
198
+ result.scale.y = parseFloat(params[1]) || result.scale.x
199
+ break;
200
+ case 'scale3d':
201
+ result.scale.x = parseFloat(params[0])
202
+ result.scale.y = parseFloat(params[1]) || result.scale.x
203
+ result.scale.z = parseFloat(params[2]) || result.scale.x
204
+ break;
205
+ case 'rotate':
206
+ const angle = parseFloat(params[0])
207
+ const axis = parseTransformUnit(params[1]) || 'z';
208
+ switch (axis) {
209
+ case 'x': result.rotate.x = angle; break
210
+ case 'y': result.rotate.y = angle; break
211
+ case 'z': result.rotate.z = angle; break
212
+ }
213
+ break;
214
+ case 'rotate3d':
215
+ result.rotate.x = parseFloat(params[0]) || 0
216
+ result.rotate.y = parseFloat(params[1]) || 0
217
+ result.rotate.z = parseFloat(params[2]) || 0
218
+ break;
219
+ case 'matrix':
220
+ const matrixArr: number[] = params[0].split(',').map(item => parseFloat(item))
221
+ result.transform = matrix4.init(convertMatrixToMatrix3d(matrixArr))
222
+ break;
223
+ case 'matrix3d':
224
+ const matrix3dArr: number[] = params[0].split(',').map(item => parseFloat(item))
225
+ result.transform = matrix4.init(matrix3dArr as matrixNums)
226
+ break;
227
+ }
228
+ })
229
+
230
+ return result
231
+ }
232
+ }
233
+
234
+
235
+ function parseTransformUnit (val: string) {
236
+ return parseFloat(val) === 0 ? 0 : val
237
+ }
238
+
239
+
240
+ // matrix 转 matrix3d
241
+ function convertMatrixToMatrix3d(matrix2d: number[]): matrixNums {
242
+ const matrix3d: number[] = new Array(16).fill(0);
243
+ matrix3d[0] = matrix2d[0];
244
+ matrix3d[5] = matrix2d[3];
245
+ matrix3d[10] = 1;
246
+ matrix3d[15] = 1;
247
+ matrix3d[12] = matrix2d[4];
248
+ matrix3d[13] = matrix2d[5];
249
+ return matrix3d as matrixNums;
250
+ }
251
+
252
+ export { AttributeManager }
@@ -0,0 +1,41 @@
1
+ import { TaroElement } from '@tarojs/runtime'
2
+
3
+ import type { TaroAny } from '@tarojs/runtime'
4
+
5
+ export class DynamicCenter {
6
+ install (node: TaroElement, parentNode: TaroElement) {
7
+ if (!parentNode._isCompileMode) return
8
+
9
+ this.bindComponentToNodeWithDFS(node, parentNode._instance)
10
+ }
11
+
12
+ uninstall (node: TaroElement) {
13
+ if (!node._isCompileMode || !node._instance) return
14
+
15
+ if (node._attrs?._dynamicID) {
16
+ node._instance[node._attrs._dynamicID] = new TaroElement('Ignore')
17
+ }
18
+ node._instance = null
19
+ }
20
+
21
+ bindComponentToNodeWithDFS (node: TaroElement, component: TaroAny) {
22
+ if (!node) return
23
+
24
+ const dynamicID = node._attrs?._dynamicID
25
+
26
+ // dynamicID 只是为了更新到精准的 node
27
+ node._instance = component
28
+ node._isCompileMode = true
29
+
30
+ if (dynamicID) {
31
+ node._isDynamicNode = true
32
+ component[dynamicID] = node
33
+ }
34
+
35
+ if (!node.childNodes || !node.childNodes.length) return
36
+
37
+ for (let i = 0; i < node.childNodes.length; i++) {
38
+ this.bindComponentToNodeWithDFS(node.childNodes[i] as TaroElement, component)
39
+ }
40
+ }
41
+ }
@@ -0,0 +1,25 @@
1
+ export class TOUCH_EVENT_MAP {
2
+ static readonly TouchTypeUp = 'touchend'
3
+ static readonly TouchTypeMove = 'touchmove'
4
+ static readonly TouchTypeDown = 'touchstart'
5
+ static readonly TouchTypeCancel = 'touchcancel'
6
+
7
+ static get (event: TouchType) {
8
+ switch (event) {
9
+ case TouchType.Up: return TOUCH_EVENT_MAP.TouchTypeUp
10
+ case TouchType.Move: return TOUCH_EVENT_MAP.TouchTypeMove
11
+ case TouchType.Down: return TOUCH_EVENT_MAP.TouchTypeDown
12
+ case TouchType.Cancel: return TOUCH_EVENT_MAP.TouchTypeCancel
13
+ }
14
+ return TOUCH_EVENT_MAP.TouchTypeUp
15
+ }
16
+
17
+ static values () {
18
+ return [
19
+ TOUCH_EVENT_MAP.TouchTypeUp,
20
+ TOUCH_EVENT_MAP.TouchTypeMove,
21
+ TOUCH_EVENT_MAP.TouchTypeUp,
22
+ TOUCH_EVENT_MAP.TouchTypeUp,
23
+ ]
24
+ }
25
+ }
@@ -0,0 +1,91 @@
1
+ // 各种组件的默认样式
2
+
3
+ export class TEXT_DEFAULT_STYLE {
4
+ static COLOR = 'black'
5
+ static FONT_SIZE = '24'
6
+ static FONT_WEIGHT = FontWeight.Normal
7
+ static FONT_FAMILY = 'HarmonyOS Sans'
8
+ static TEXT_ALIGN = TextAlign.Start
9
+ static TEXT_OVERFLOW = TextOverflow.Clip
10
+ }
11
+
12
+ interface IBUTTON_THEME_COLOR {
13
+ text: Color
14
+ background: string
15
+ plainText: string | Color
16
+ }
17
+
18
+ export class BUTTON_THEME_COLOR {
19
+ static get (type: string): IBUTTON_THEME_COLOR {
20
+ switch (type) {
21
+ case 'primary': return {
22
+ text: Color.White,
23
+ background: '#1aad19',
24
+ plainText: '#1aad19'
25
+ }
26
+ case 'warn': return {
27
+ text: Color.White,
28
+ background: '#e64340',
29
+ plainText: '#e64340'
30
+ }
31
+ default: return {
32
+ text: Color.Black,
33
+ background: '#f7f7f7',
34
+ plainText: Color.Black
35
+ }
36
+ }
37
+ }
38
+ }
39
+
40
+ export class INPUT_TYPE_MAP {
41
+ static get (type: string) {
42
+ switch (type) {
43
+ case 'text': return InputType.Normal;
44
+ case 'number': return InputType.Number;
45
+ case 'idcard': return InputType.Number;
46
+ case 'safe-password': return InputType.Password;
47
+ }
48
+ return InputType.Normal
49
+ }
50
+ }
51
+
52
+ export class INPUT_CONFIRM_MAP {
53
+ static go = EnterKeyType.Go // 右下角按钮为“前往”
54
+ static send = EnterKeyType.Send // 右下角按钮为“发送”
55
+ static done = EnterKeyType.Done // 右下角按钮为“完成”
56
+ static next = EnterKeyType.Next // 右下角按钮为“下一个”
57
+ static search = EnterKeyType.Search // 右下角按钮为“搜索”
58
+
59
+ static get (type: string) {
60
+ switch (type) {
61
+ case 'go': return EnterKeyType.Go
62
+ case 'send': return EnterKeyType.Send
63
+ case 'done': return EnterKeyType.Done
64
+ case 'next': return EnterKeyType.Next
65
+ case 'search': return EnterKeyType.Search
66
+ }
67
+ return EnterKeyType.Done
68
+ }
69
+ }
70
+
71
+ export class CurveMap {
72
+ static default = Curve.Linear
73
+ static linear = Curve.Linear
74
+ static easeInCubic = Curve.EaseIn
75
+ static easeOutCubic = Curve.EaseOut
76
+ static easeInOutCubic = Curve.EaseInOut
77
+ }
78
+
79
+ export class BORDER_STYLE_MAP {
80
+ static solid = BorderStyle.Solid
81
+ static dotted = BorderStyle.Dotted
82
+ static dashed = BorderStyle.Dashed
83
+
84
+ static get(type: string): BorderStyle {
85
+ switch (type) {
86
+ case 'dotted': return BorderStyle.Dotted;
87
+ case 'dashed': return BorderStyle.Dashed;
88
+ default: return BorderStyle.Solid;
89
+ }
90
+ }
91
+ }
@@ -0,0 +1,26 @@
1
+ import { TaroEvent } from '@tarojs/runtime'
2
+
3
+ import type { EventOptions, TaroElement } from '@tarojs/runtime'
4
+
5
+ export function createTaroEvent(type: string, opts: Partial<EventOptions> = {}, node?: TaroElement) {
6
+ opts.bubbles ||= true
7
+ opts.cancelable ||= true
8
+ const e = new TaroEvent(type, opts as Required<EventOptions>)
9
+
10
+ if (node) {
11
+ const properties: Record<string, PropertyDescriptor> = {}
12
+ properties.target = properties.currentTarget = {
13
+ get() {
14
+ return node
15
+ }
16
+ }
17
+ Object.defineProperties(e, properties)
18
+ }
19
+ for (const key in opts) {
20
+ if (['bubbles', 'cancelable'].includes(key)) {
21
+ continue
22
+ }
23
+ e[key] = opts[key]
24
+ }
25
+ return e
26
+ }
@@ -0,0 +1,49 @@
1
+ import { isUndefined } from '@tarojs/shared'
2
+
3
+ import { getNormalAttributes } from './styles'
4
+
5
+ import type { TaroAny, TaroElement, HarmonyStyle } from '@tarojs/runtime'
6
+
7
+ class FlexManager {
8
+ static isFlexNode (node: TaroElement): boolean {
9
+ return !!node.hmStyle?.display?.includes('flex')
10
+ }
11
+
12
+ static convertFlexAlignItemsToColumnOrRow (direction: FlexDirection, alignItems?: ItemAlign): VerticalAlign | HorizontalAlign {
13
+ if (direction === FlexDirection.Column) {
14
+ switch (alignItems) {
15
+ case ItemAlign.Center:
16
+ return HorizontalAlign.Center
17
+ case ItemAlign.End:
18
+ return HorizontalAlign.End
19
+ default:
20
+ return HorizontalAlign.Start
21
+ }
22
+ } else {
23
+ switch (alignItems) {
24
+ case ItemAlign.Center:
25
+ return VerticalAlign.Center
26
+ case ItemAlign.End:
27
+ return VerticalAlign.Bottom
28
+ default:
29
+ return VerticalAlign.Top
30
+ }
31
+ }
32
+ }
33
+
34
+ static alignItems<T> (node: TaroElement): T {
35
+ const hmStyle: HarmonyStyle = getNormalAttributes(node)
36
+ let flexDirection: TaroAny = hmStyle.flexDirection
37
+ if (!flexDirection && flexDirection !== 0) {
38
+ flexDirection = hmStyle.display === 'flex' ? FlexDirection.Row : FlexDirection.Column
39
+ }
40
+ return (FlexManager.isFlexNode(node) ? FlexManager.convertFlexAlignItemsToColumnOrRow(flexDirection, hmStyle.alignItems) : HorizontalAlign.Start) as T
41
+ }
42
+
43
+ static justifyContent (node: TaroElement): FlexAlign {
44
+ const hmStyle: HarmonyStyle = getNormalAttributes(node)
45
+ return FlexManager.isFlexNode(node) ? (isUndefined(hmStyle.justifyContent) ? FlexAlign.Start : hmStyle.justifyContent!) : FlexAlign.Start
46
+ }
47
+ }
48
+
49
+ export { FlexManager }
@@ -0,0 +1,51 @@
1
+ import { VIEW } from '@tarojs/runtime'
2
+
3
+ import { getNormalAttributes, getFontAttributes } from './styles'
4
+
5
+ import type { TaroAny, TaroElement, TaroNode } from '@tarojs/runtime'
6
+
7
+ export const parseStyles = (styles = ''): Record<string, string> => {
8
+ const styleObj: Record<string, string> = {}
9
+ styles
10
+ .split(';')
11
+ .filter((style) => style.split(':').length === 2)
12
+ .map((style) => [
13
+ style.split(':')[0].trim().replace(new RegExp("-([a-z])", "g"), (_, letter: string): string => letter.toUpperCase()),
14
+ style.split(':')[1].trim()
15
+ ])
16
+ .forEach((style) => {
17
+ const key = style[0]
18
+ const value = style[1]
19
+ styleObj[key] = value
20
+ })
21
+ return styleObj
22
+ }
23
+
24
+ export function shouldBindEvent (cb: TaroAny, node: TaroElement | null, eventNames: string[], disabled = false): TaroAny {
25
+ if (!node || node._attrs?.disabled || disabled) return null
26
+ if (!node.__listeners) {
27
+ return null
28
+ }
29
+ const listeners = Object.keys(node.__listeners)
30
+ if (listeners.every(e => !eventNames.includes(e))) return null
31
+ return cb
32
+ }
33
+
34
+ export function getNodeThresholds (node: TaroElement): number[] | null {
35
+ return node?._nodeInfo?.thresholds || null
36
+ }
37
+
38
+ export function isTagFirstChild (node: TaroElement, tagName = VIEW, level = 0): boolean {
39
+ const parent: TaroElement | null = node.parentElement
40
+ const list: TaroNode[] = node.parentNode?.childNodes || []
41
+ if (list.length < 1 || level < 0) return false
42
+ else if (!parent) return true
43
+
44
+ if (parent.nodeName === tagName.toUpperCase()) {
45
+ return list[0] === node
46
+ } else {
47
+ return (list[0] === node) && isTagFirstChild(parent, tagName, --level)
48
+ }
49
+ }
50
+
51
+ export { getNormalAttributes, getFontAttributes }