@tarojs/plugin-platform-harmony-ets 3.7.0-alpha.27

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 (212) hide show
  1. package/LICENSE +160 -0
  2. package/dist/apis/apis.ts +15 -0
  3. package/dist/apis/base/index.ts +5 -0
  4. package/dist/apis/base/system.ts +77 -0
  5. package/dist/apis/device/accelerometer.ts +76 -0
  6. package/dist/apis/device/battery.ts +24 -0
  7. package/dist/apis/device/clipboard.ts +70 -0
  8. package/dist/apis/device/index.ts +9 -0
  9. package/dist/apis/device/keyboard.ts +62 -0
  10. package/dist/apis/device/memory.ts +4 -0
  11. package/dist/apis/device/network.ts +72 -0
  12. package/dist/apis/device/phone.ts +43 -0
  13. package/dist/apis/device/screen.ts +79 -0
  14. package/dist/apis/device/vibrate.ts +24 -0
  15. package/dist/apis/files/index.ts +135 -0
  16. package/dist/apis/files/manager.ts +941 -0
  17. package/dist/apis/framework/index.ts +32 -0
  18. package/dist/apis/index.ts +124 -0
  19. package/dist/apis/location/index.ts +133 -0
  20. package/dist/apis/media/common.ts +74 -0
  21. package/dist/apis/media/image.ts +122 -0
  22. package/dist/apis/media/index.ts +3 -0
  23. package/dist/apis/media/video.ts +86 -0
  24. package/dist/apis/navigate/index.ts +8 -0
  25. package/dist/apis/network/downloadFile.ts +113 -0
  26. package/dist/apis/network/index.ts +4 -0
  27. package/dist/apis/network/request.ts +113 -0
  28. package/dist/apis/network/uploadFile.ts +158 -0
  29. package/dist/apis/network/webSocket.ts +130 -0
  30. package/dist/apis/open-api/index.ts +7 -0
  31. package/dist/apis/open-api/user-info/index.ts +85 -0
  32. package/dist/apis/page/index.ts +92 -0
  33. package/dist/apis/route/index.ts +138 -0
  34. package/dist/apis/storage/index.ts +133 -0
  35. package/dist/apis/tabbar/index.ts +147 -0
  36. package/dist/apis/ui/animation.ts +222 -0
  37. package/dist/apis/ui/background.ts +35 -0
  38. package/dist/apis/ui/index.ts +14 -0
  39. package/dist/apis/ui/interaction/index.ts +195 -0
  40. package/dist/apis/ui/navigation-bar/index.ts +33 -0
  41. package/dist/apis/ui/pull-down-refresh.ts +41 -0
  42. package/dist/apis/utils/handler.ts +116 -0
  43. package/dist/apis/utils/index.ts +85 -0
  44. package/dist/apis/utils/types.ts +12 -0
  45. package/dist/apis/utils/validate.ts +87 -0
  46. package/dist/apis/wxml/IntersectionObserver.ts +119 -0
  47. package/dist/apis/wxml/index.ts +12 -0
  48. package/dist/apis/wxml/nodesRef.ts +56 -0
  49. package/dist/apis/wxml/selectorQuery.ts +287 -0
  50. package/dist/components/components-react.js +51 -0
  51. package/dist/components/components-react.js.map +1 -0
  52. package/dist/components-harmony/button/index.css +109 -0
  53. package/dist/components-harmony/button/index.hml +31 -0
  54. package/dist/components-harmony/button/index.js +105 -0
  55. package/dist/components-harmony/camera/index.hml +6 -0
  56. package/dist/components-harmony/camera/index.js +12 -0
  57. package/dist/components-harmony/checkbox/index.hml +11 -0
  58. package/dist/components-harmony/checkbox/index.js +60 -0
  59. package/dist/components-harmony/checkbox-group/index.hml +3 -0
  60. package/dist/components-harmony/checkbox-group/index.js +22 -0
  61. package/dist/components-harmony/cover-image/index.css +4 -0
  62. package/dist/components-harmony/cover-image/index.hml +9 -0
  63. package/dist/components-harmony/cover-image/index.js +15 -0
  64. package/dist/components-harmony/form/index.hml +10 -0
  65. package/dist/components-harmony/form/index.js +11 -0
  66. package/dist/components-harmony/icon/index.css +27 -0
  67. package/dist/components-harmony/icon/index.hml +54 -0
  68. package/dist/components-harmony/icon/index.js +17 -0
  69. package/dist/components-harmony/image/index.css +5 -0
  70. package/dist/components-harmony/image/index.hml +11 -0
  71. package/dist/components-harmony/image/index.js +28 -0
  72. package/dist/components-harmony/input/index.hml +21 -0
  73. package/dist/components-harmony/input/index.js +98 -0
  74. package/dist/components-harmony/label/index.hml +3 -0
  75. package/dist/components-harmony/label/index.js +6 -0
  76. package/dist/components-harmony/navbar/index.css +56 -0
  77. package/dist/components-harmony/navbar/index.hml +9 -0
  78. package/dist/components-harmony/navbar/index.js +30 -0
  79. package/dist/components-harmony/navigator/index.css +8 -0
  80. package/dist/components-harmony/navigator/index.hml +9 -0
  81. package/dist/components-harmony/navigator/index.js +104 -0
  82. package/dist/components-harmony/picker/index.hml +25 -0
  83. package/dist/components-harmony/picker/index.js +132 -0
  84. package/dist/components-harmony/picker-view/index.hml +23 -0
  85. package/dist/components-harmony/picker-view/index.js +161 -0
  86. package/dist/components-harmony/picker-view-column/index.hml +3 -0
  87. package/dist/components-harmony/picker-view-column/index.js +3 -0
  88. package/dist/components-harmony/progress/index.css +4 -0
  89. package/dist/components-harmony/progress/index.hml +28 -0
  90. package/dist/components-harmony/progress/index.js +23 -0
  91. package/dist/components-harmony/radio/index.hml +11 -0
  92. package/dist/components-harmony/radio/index.js +41 -0
  93. package/dist/components-harmony/radio-group/index.hml +3 -0
  94. package/dist/components-harmony/radio-group/index.js +11 -0
  95. package/dist/components-harmony/rich-text/index.hml +5 -0
  96. package/dist/components-harmony/rich-text/index.js +16 -0
  97. package/dist/components-harmony/scroll-view/index.css +5 -0
  98. package/dist/components-harmony/scroll-view/index.hml +12 -0
  99. package/dist/components-harmony/scroll-view/index.js +65 -0
  100. package/dist/components-harmony/slider/index.hml +16 -0
  101. package/dist/components-harmony/slider/index.js +53 -0
  102. package/dist/components-harmony/swiper/index.css +3 -0
  103. package/dist/components-harmony/swiper/index.hml +14 -0
  104. package/dist/components-harmony/swiper/index.js +19 -0
  105. package/dist/components-harmony/switch/index.hml +7 -0
  106. package/dist/components-harmony/switch/index.js +16 -0
  107. package/dist/components-harmony/tabbar/index.css +7 -0
  108. package/dist/components-harmony/tabbar/index.hml +26 -0
  109. package/dist/components-harmony/tabbar/index.js +42 -0
  110. package/dist/components-harmony/textarea/index.hml +24 -0
  111. package/dist/components-harmony/textarea/index.js +92 -0
  112. package/dist/components-harmony/utils/index.js +41 -0
  113. package/dist/components-harmony/video/index.hml +7 -0
  114. package/dist/components-harmony/video/index.js +73 -0
  115. package/dist/components-harmony/web-view/index.hml +8 -0
  116. package/dist/components-harmony/web-view/index.js +22 -0
  117. package/dist/components-harmony-ets/base.ets +63 -0
  118. package/dist/components-harmony-ets/button.ets +119 -0
  119. package/dist/components-harmony-ets/checkbox.ets +219 -0
  120. package/dist/components-harmony-ets/element.ets +223 -0
  121. package/dist/components-harmony-ets/form.ets +149 -0
  122. package/dist/components-harmony-ets/icon.ets +84 -0
  123. package/dist/components-harmony-ets/image.ets +85 -0
  124. package/dist/components-harmony-ets/index.ts +49 -0
  125. package/dist/components-harmony-ets/innerHtml.ets +79 -0
  126. package/dist/components-harmony-ets/input.ets +195 -0
  127. package/dist/components-harmony-ets/label.ets +111 -0
  128. package/dist/components-harmony-ets/picker.ets +370 -0
  129. package/dist/components-harmony-ets/radio.ets +225 -0
  130. package/dist/components-harmony-ets/richText.ets +97 -0
  131. package/dist/components-harmony-ets/scrollView.ets +199 -0
  132. package/dist/components-harmony-ets/slider.ets +159 -0
  133. package/dist/components-harmony-ets/swiper.ets +204 -0
  134. package/dist/components-harmony-ets/switch.ets +113 -0
  135. package/dist/components-harmony-ets/text.ets +97 -0
  136. package/dist/components-harmony-ets/textArea.ets +169 -0
  137. package/dist/components-harmony-ets/utils/AttributeManager.ets +250 -0
  138. package/dist/components-harmony-ets/utils/DynamicCenter.ts +48 -0
  139. package/dist/components-harmony-ets/utils/constant/event.ets +25 -0
  140. package/dist/components-harmony-ets/utils/constant/icon.ts +19 -0
  141. package/dist/components-harmony-ets/utils/constant/style.ets +88 -0
  142. package/dist/components-harmony-ets/utils/events.ts +24 -0
  143. package/dist/components-harmony-ets/utils/flexManager.ets +107 -0
  144. package/dist/components-harmony-ets/utils/helper.ets +99 -0
  145. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +103 -0
  146. package/dist/components-harmony-ets/utils/htmlParser/index.ts +56 -0
  147. package/dist/components-harmony-ets/utils/index.ts +83 -0
  148. package/dist/components-harmony-ets/utils/styles.ets +91 -0
  149. package/dist/components-harmony-ets/video.ets +161 -0
  150. package/dist/components-harmony-ets/view.ets +79 -0
  151. package/dist/index.js +1183 -0
  152. package/dist/index.js.map +1 -0
  153. package/dist/runtime-ets/bom/document.ts +38 -0
  154. package/dist/runtime-ets/bom/getComputedStyle.ts +5 -0
  155. package/dist/runtime-ets/bom/navigator.ts +21 -0
  156. package/dist/runtime-ets/bom/raf.ts +37 -0
  157. package/dist/runtime-ets/bom/window.ts +44 -0
  158. package/dist/runtime-ets/constant.ts +29 -0
  159. package/dist/runtime-ets/current.ts +16 -0
  160. package/dist/runtime-ets/dom/class-list.ts +117 -0
  161. package/dist/runtime-ets/dom/comment.ts +10 -0
  162. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +105 -0
  163. package/dist/runtime-ets/dom/document.ts +108 -0
  164. package/dist/runtime-ets/dom/element.ts +457 -0
  165. package/dist/runtime-ets/dom/event.ts +164 -0
  166. package/dist/runtime-ets/dom/eventTarget.ts +98 -0
  167. package/dist/runtime-ets/dom/node.ts +215 -0
  168. package/dist/runtime-ets/dom/stylesheet/index.ts +687 -0
  169. package/dist/runtime-ets/dom/stylesheet/type.ts +136 -0
  170. package/dist/runtime-ets/dom/stylesheet/util.ts +134 -0
  171. package/dist/runtime-ets/dom/text.ts +19 -0
  172. package/dist/runtime-ets/index.ts +19 -0
  173. package/dist/runtime-ets/interface/event.ts +9 -0
  174. package/dist/runtime-ets/interface/index.ts +1 -0
  175. package/dist/runtime-ets/utils/bind.ts +35 -0
  176. package/dist/runtime-ets/utils/index.ts +135 -0
  177. package/dist/runtime-ets/utils/info.ts +128 -0
  178. package/dist/runtime-framework/react/app.ts +256 -0
  179. package/dist/runtime-framework/react/connect.ts +24 -0
  180. package/dist/runtime-framework/react/constant.ts +5 -0
  181. package/dist/runtime-framework/react/hooks.ts +101 -0
  182. package/dist/runtime-framework/react/index.ts +16 -0
  183. package/dist/runtime-framework/react/page.ts +263 -0
  184. package/dist/runtime-framework/react/utils/index.ts +25 -0
  185. package/dist/runtime-framework/react/utils/is.ts +46 -0
  186. package/dist/runtime-framework/solid/README.md +99 -0
  187. package/dist/runtime-framework/solid/app.ts +200 -0
  188. package/dist/runtime-framework/solid/connect.ts +11 -0
  189. package/dist/runtime-framework/solid/contant.ts +5 -0
  190. package/dist/runtime-framework/solid/hooks.ts +88 -0
  191. package/dist/runtime-framework/solid/index.ts +10 -0
  192. package/dist/runtime-framework/solid/page.ts +202 -0
  193. package/dist/runtime-framework/solid/reconciler/h.ts +132 -0
  194. package/dist/runtime-framework/solid/reconciler/index.ts +3 -0
  195. package/dist/runtime-framework/solid/reconciler/props.ts +151 -0
  196. package/dist/runtime-framework/solid/reconciler/render.ts +61 -0
  197. package/dist/runtime-framework/solid/reconciler/use.ts +8 -0
  198. package/dist/runtime-framework/solid/utils/index.ts +49 -0
  199. package/dist/runtime-framework/solid/utils/is.ts +46 -0
  200. package/dist/runtime-utils.js +4149 -0
  201. package/dist/runtime-utils.js.map +1 -0
  202. package/dist/runtime.js +4150 -0
  203. package/dist/runtime.js.map +1 -0
  204. package/dist/template/container.js +7 -0
  205. package/index.js +4 -0
  206. package/package.json +54 -0
  207. package/types/api.d.ts +4 -0
  208. package/types/component.d.ts +4 -0
  209. package/types/harmony.d.ts +11 -0
  210. package/types/runtime.d.ts +15 -0
  211. package/types/taro.d.ts +7 -0
  212. package/types/webpack-sources.d.ts +108 -0
@@ -0,0 +1,136 @@
1
+ import matrix4 from '@ohos.matrix4'
2
+
3
+ export interface HarmonyStyle extends TaroStyleType {
4
+ textAlign?: TextAlign
5
+ textOverflow?: HarmonyType.Overflow
6
+ maxLines?: number
7
+ letterSpacing?: number | string
8
+ }
9
+
10
+ export interface TaroStyleType {
11
+ id?: string
12
+
13
+ padding?: Margin | Length
14
+ margin?: Margin | Length
15
+ width?: Length
16
+ height?: Length
17
+ constraintSize?: ConstraintSizeOptions
18
+
19
+ display?: 'flex' | 'block' | 'none'
20
+
21
+ // position
22
+ position?: 'relative' | 'absolute' | 'fixed'
23
+ top?: Length
24
+ left?: Length
25
+
26
+ // flex
27
+ flexBasis?: number | string
28
+ flexGrow?: number
29
+ flexShrink?: number
30
+ alignSelf?: ItemAlign
31
+ direction?: FlexDirection
32
+ justifyContent?: FlexAlign
33
+ alignItems?: ItemAlign
34
+ wrap?: FlexWrap
35
+ alignContent?: FlexAlign
36
+
37
+ // background
38
+ backgroundColor?: ResourceColor
39
+ backgroundImage?: ResourceStr
40
+ backgroundRepeat?: ImageRepeat
41
+ backgroundImageSize?: SizeOptions | ImageSize
42
+
43
+ // transform
44
+ rotate?: HarmonyType.Transform.Rotate
45
+ translate?: HarmonyType.Transform.Translate
46
+ scale?: HarmonyType.Transform.Scale
47
+ transform?: HarmonyType.Transform.Transform
48
+
49
+ // border
50
+ borderWidth?: Length | EdgeWidths
51
+ borderColor?: ResourceColor | EdgeColors
52
+ borderStyle?: BorderStyle | EdgeStyles
53
+ borderRadius?: Length | BorderRadiuses
54
+
55
+ // text
56
+ color?: ResourceColor
57
+ fontSize?: number | string | Resource
58
+ fontStyle?: FontStyle
59
+ fontWeight?: number | FontWeight | string
60
+ fontFamily?: string | Resource
61
+ lineHeight?: string | number | Resource
62
+ decoration?: TextDecorationType
63
+
64
+ // gradient
65
+ linearGradient?: HarmonyType.LinearGradient
66
+
67
+ // other
68
+ opacity?: number | Resource
69
+ zIndex?: number
70
+ clip?: boolean
71
+ focus?: boolean
72
+ }
73
+
74
+ export interface TaroTextStyleType {
75
+ textAlign?: TextAlign
76
+ textOverflow?: HarmonyType.Overflow
77
+ maxLines?: number
78
+ letterSpacing?: number | string
79
+ }
80
+
81
+ export namespace HarmonyType {
82
+ export interface FlexOptions {
83
+ direction?: FlexDirection
84
+ justifyContent?: FlexAlign
85
+ alignItems?: ItemAlign
86
+ }
87
+ export interface LinearGradient {
88
+ angle?: number | string
89
+ direction?: GradientDirection
90
+ colors: Array<[ResourceColor, number]>
91
+ repeating?: boolean
92
+ }
93
+ export interface Overflow {
94
+ overflow: TextOverflow
95
+ }
96
+ export interface RadioStyle {
97
+ checkedBackgroundColor?: ResourceColor
98
+ uncheckedBorderColor?: ResourceColor
99
+ indicatorColor?: ResourceColor
100
+ }
101
+ export namespace Background {
102
+ export type backgroundColor = ResourceColor
103
+ export interface backgroundImage {
104
+ src: ResourceStr
105
+ repeat?: ImageRepeat
106
+ }
107
+ export type backgroundImageSize = SizeOptions | ImageSize
108
+ export type backgroundImagePosition = Position | Alignment
109
+ }
110
+ export namespace Transform {
111
+ export interface Rotate {
112
+ x?: number
113
+ y?: number
114
+ z?: number
115
+ angle: number | string
116
+ centerX?: number | string
117
+ centerY?: number | string
118
+ center?: number
119
+ perspective?: number
120
+ }
121
+ export interface Translate {
122
+ x?: number | string
123
+ y?: number | string
124
+ z? : number | string
125
+ }
126
+ export interface Scale {
127
+ x?: number
128
+ y?: number
129
+ z?: number
130
+ centerX?: number | string
131
+ centerY?: number | string
132
+ }
133
+ export type Transform = matrix4.Matrix4Transit
134
+ }
135
+ }
136
+
@@ -0,0 +1,134 @@
1
+ // @ts-nocheck
2
+ import { isNumber } from '@tarojs/shared'
3
+
4
+ import { convertNumber2VP } from '../../'
5
+
6
+ export class FlexManager {
7
+
8
+ static flexAlign (value: string | number | undefined): FlexAlign {
9
+ switch (value) {
10
+ case 'flex-end':
11
+ return FlexAlign.End
12
+ case 'center':
13
+ return FlexAlign.Center
14
+ case 'space-between':
15
+ return FlexAlign.SpaceBetween
16
+ case 'space-around':
17
+ return FlexAlign.SpaceAround
18
+ case 'space-evenly':
19
+ return FlexAlign.SpaceEvenly
20
+ default:
21
+ return FlexAlign.Start
22
+ }
23
+ }
24
+
25
+ static direction (value: string): FlexDirection {
26
+ switch (value) {
27
+ case 'row': return FlexDirection.Row
28
+ case 'row-reverse': return FlexDirection.RowReverse
29
+ case 'column-reverse': return FlexDirection.ColumnReverse
30
+ default: return FlexDirection.Column
31
+ }
32
+ }
33
+
34
+ static itemAlign (value: string | number | undefined): ItemAlign {
35
+ switch (value) {
36
+ case 'flex-start':
37
+ return ItemAlign.Start
38
+ case 'flex-end':
39
+ return ItemAlign.End
40
+ case 'center':
41
+ return ItemAlign.Center
42
+ case 'stretch':
43
+ return ItemAlign.Stretch
44
+ case 'baseline':
45
+ return ItemAlign.Baseline
46
+ default:
47
+ return ItemAlign.Auto
48
+ }
49
+ }
50
+
51
+ static justifyContent (value: string): FlexAlign {
52
+ return FlexManager.flexAlign(value)
53
+ }
54
+
55
+ static alignItems (value: string): ItemAlign {
56
+ return FlexManager.itemAlign(value)
57
+ }
58
+
59
+ static alignSelf (value: string): ItemAlign {
60
+ return FlexManager.itemAlign(value)
61
+ }
62
+
63
+ static flexWrap (value: string): FlexWrap {
64
+ return value === 'wrap' ? FlexWrap.Wrap : FlexWrap.NoWrap
65
+ }
66
+
67
+ static alignContent (style: Record<string, string | number> = {}): FlexAlign | undefined {
68
+ if (style.flexWrap !== 'wrap') return undefined
69
+ const value = style.alignContent
70
+ return FlexManager.flexAlign(value)
71
+ }
72
+
73
+ static flexSize (style: Record<string, string | number> = {}): [number, number, number | string] {
74
+ const flex = style.flex
75
+ const flexGrow = style.flexGrow || 0
76
+ const flexShrink = style.flexShrink || 0
77
+ const flexBasis = style.flexBasis || 'auto'
78
+ let res: [number, number, number | string] = [Number(flexGrow), Number(flexShrink), flexBasis]
79
+
80
+ if (typeof flex === 'number') {
81
+ res = [flex, 1, 0]
82
+ } else if (flex === 'auto') {
83
+ res = [1, 1, 'auto']
84
+ } else if (flex === 'none') {
85
+ res = [0, 0, 'auto']
86
+ } else if (typeof flex === 'string') {
87
+ const FlexList = flex.replace(new RegExp('\\s+'), ' ').split(' ')
88
+ FlexList.forEach((item, index) => {
89
+ res[index] = index < 2 ? Number(item) : item
90
+ })
91
+ }
92
+ return res
93
+ }
94
+ }
95
+
96
+ export function getNodeMarginOrPaddingData (dataValue: string) {
97
+ let res: any = {}
98
+ if (dataValue) {
99
+ const values = dataValue.trim().split(new RegExp('\\s+'))
100
+ switch (values.length) {
101
+ case 1:
102
+ res = { top: values[0], right: values[0], bottom: values[0], left: values[0] }
103
+ break
104
+ case 2:
105
+ res = { top: values[0], right: values[1], bottom: values[0], left: values[1] }
106
+ break
107
+ case 3:
108
+ res = { top: values[0], right: values[1], bottom: values[2], left: values[1] }
109
+ break
110
+ case 4:
111
+ res = { top: values[0], right: values[1], bottom: values[2], left: values[3] }
112
+ break
113
+ default:
114
+ break
115
+ }
116
+ Object.keys(res).forEach(key => {
117
+ const exec = `${res[key]}`.match(/(\d+)(px)$/)
118
+ if (exec && values.length > 1) {
119
+ res[key] = getUnit(+exec[1])
120
+ }
121
+ })
122
+ }
123
+ return res
124
+ }
125
+
126
+
127
+ export function getUnit (val) {
128
+ if (/\d+(vp)$/.test(val)) {
129
+ return val
130
+ } else if (isNumber(val) || /\d+px$/.test(val)) {
131
+ return convertNumber2VP(parseFloat(val))
132
+ }
133
+ return val
134
+ }
@@ -0,0 +1,19 @@
1
+ import { NodeType, TaroNode } from './node'
2
+
3
+ class TextNode extends TaroNode {
4
+ constructor(value = '', nodeName = '#text', nodeType: NodeType = NodeType.TEXT_NODE) {
5
+ super(nodeName, nodeType)
6
+ this.textContent = value
7
+ }
8
+
9
+ public get data (): string {
10
+ return this.textContent
11
+ }
12
+
13
+ public set data (value: string) {
14
+ this.textContent = value
15
+ }
16
+ }
17
+
18
+ @Observed
19
+ export class TaroTextNode extends TextNode {}
@@ -0,0 +1,19 @@
1
+ // Current必须放在前面初始化
2
+ // eslint-disable-next-line simple-import-sort/exports
3
+ export * from './current'
4
+ export * from './bom/document'
5
+ export * from './bom/getComputedStyle'
6
+ export { nav as navigator } from './bom/navigator'
7
+ export { caf as cancelAnimationFrame, now, raf as requestAnimationFrame } from './bom/raf'
8
+ export * from './bom/window'
9
+ export * from './dom/element'
10
+ export * from './dom/event'
11
+ export * from './dom/node'
12
+ export * from './dom/text'
13
+ export * from './dom/stylesheet'
14
+ export * from './interface'
15
+ export * from './utils'
16
+ export * from './utils/bind'
17
+ export * from './utils/info'
18
+ export { URLSearchParams, eventSource } from '@tarojs/runtime/dist/runtime.esm'
19
+ export { hooks } from '@tarojs/shared'
@@ -0,0 +1,9 @@
1
+ export interface EventOptions {
2
+ bubbles: boolean
3
+ cancelable: boolean
4
+ [x: string]: any
5
+ }
6
+
7
+ export interface EventHandler extends Function {
8
+ _stop?: boolean
9
+ }
@@ -0,0 +1 @@
1
+ export * from './event'
@@ -0,0 +1,35 @@
1
+ import { bindAttributesCallback } from './info'
2
+
3
+ import type { TaroElement } from '../dom/element'
4
+
5
+ // function convertToCamelCase(str) {
6
+ // return str.replace(/-(.)/g, (_, char) => char.toUpperCase()).replace(/^\w/, firstChar => firstChar.toUpperCase())
7
+ // }
8
+
9
+ export function bindInstanceToNode (node: TaroElement, instance: any) {
10
+ if (!node) return
11
+
12
+ // @ts-ignore
13
+ node._instance = instance
14
+
15
+ // 触发appear,让node监听到TaroNode已经和ete自定义组件绑定上
16
+ // @ts-ignore
17
+ node.resolveAppear?.() // #text node节点没有实现该方法
18
+ }
19
+
20
+ export function bindScrollTo (node: TaroElement, instance: any) {
21
+ bindAttributesCallback(node, 'scrollTo', () => {
22
+ instance.scroller.scrollTo({
23
+ xOffset: node._attrs.scrollLeft || 0,
24
+ yOffset: node._attrs.scrollTop || 0,
25
+ })
26
+ })
27
+ }
28
+
29
+ export function bindFocus (node: TaroElement) {
30
+ bindAttributesCallback(node, 'focus', () => {
31
+ // TODO: ETS转TS
32
+ // focusControl.requestFocus(node._nid)
33
+ })
34
+ }
35
+
@@ -0,0 +1,135 @@
1
+ import { pxTransformHelper } from '@tarojs/taro'
2
+
3
+ import { NodeType } from '../dom/node'
4
+
5
+ import type { CSSProperties } from 'react'
6
+ import type { TaroElement } from '../dom/element'
7
+ import type { TaroNode } from '../dom/node'
8
+
9
+ export function isElement (node: TaroNode): node is TaroElement {
10
+ return node.nodeType === NodeType.ELEMENT_NODE
11
+ }
12
+
13
+ /**
14
+ * 往上寻找组件树直到 root,寻找是否有祖先组件绑定了同类型的事件
15
+ * @param node 当前组件
16
+ * @param type 事件类型
17
+ */
18
+ export function isParentBinded (node: TaroElement | null, type: string): boolean {
19
+ let res = false
20
+
21
+ // TODO: 当前 node 结构没有 root,因此不作判断,后续可根据情况添加 root 条件
22
+ while (node?.parentElement) {
23
+ if (node.parentElement.__listeners[type]?.length) {
24
+ res = true
25
+ break
26
+ }
27
+ node = node.parentElement
28
+ }
29
+
30
+ return res
31
+ }
32
+
33
+ // FIXME 当前样式转换、@tarojs/runtime 中尺寸使用该方法,暂不修复
34
+ export function convertNumber2PX (value: number) {
35
+ return pxTransformHelper(value, 'vp')
36
+ }
37
+
38
+ export function convertNumber2VP (value: number) {
39
+ return pxTransformHelper(value, 'vp')
40
+ }
41
+
42
+ export function calcDynamicStyle (styleSheet: Record<string, CSSProperties>, classNames: string, style: CSSProperties): CSSProperties {
43
+ const obj: CSSProperties[] = []
44
+ const classes = typeof classNames === 'string' ? classNames.split(' ') : []
45
+ for (let i = 0; i < classes.length; i++) {
46
+ const className = classes[i]
47
+ if (styleSheet[className]) {
48
+ obj.push(styleSheet[className])
49
+ }
50
+ }
51
+ obj.push(style)
52
+ return Object.assign.apply(null, [{}].concat(obj))
53
+ }
54
+
55
+ export function getPageScrollerOrNode (scrollerOrNode: any, page: any) {
56
+ if (!page) return scrollerOrNode
57
+
58
+ const isArrayData = scrollerOrNode instanceof Array
59
+
60
+ if (isArrayData) {
61
+ const index = page.tabBarCurrentIndex || 0
62
+
63
+ return scrollerOrNode[index]
64
+ }
65
+
66
+ return scrollerOrNode
67
+ }
68
+
69
+ export function ObjectAssign(...objects) {
70
+ return Object.assign.apply(this, [{}].concat(...objects))
71
+ }
72
+
73
+ export function callFn (fn: any, ctx: any, ...args: any) {
74
+ if (typeof fn === 'function') {
75
+ return fn.apply(ctx, args)
76
+ }
77
+ }
78
+ export function bindFn (fn: any, ctx: any, ...args: any) {
79
+ if (typeof fn === 'function') {
80
+ return fn.bind(ctx, ...args)
81
+ }
82
+ }
83
+
84
+
85
+ // 使用深度优先遍历寻找节点树中对应的子节点,且只需要找到第一个
86
+ // 通过 selector 判断是 id 还是 selector,从 node 的 id 和 className 属性中寻找
87
+ export function findChildNodeWithDFS<T extends TaroElement> (node: TaroElement, selector: string | ((ele: T) => boolean), selectAll: true): TaroElement[] | null;
88
+ export function findChildNodeWithDFS<T extends TaroElement> (node: TaroElement, selector: string | ((ele: T) => boolean), selectAll?: false): TaroElement | null;
89
+ export function findChildNodeWithDFS<T extends TaroElement> (node: TaroElement, selector: string | ((ele: T) => boolean), selectAll: boolean): TaroElement[] | TaroElement | null;
90
+ export function findChildNodeWithDFS<T extends TaroElement> (node: TaroElement, selector: string | ((ele: T) => boolean), selectAll): TaroElement[] | TaroElement | null {
91
+ const queue = [node]
92
+
93
+ const nodeList: TaroElement[] = []
94
+ while (queue.length) {
95
+ const currentNode = queue.shift()
96
+ if (currentNode) {
97
+ if (typeof selector === 'string') {
98
+ if (selector.startsWith('#')) {
99
+ // @ts-ignore
100
+ const id = currentNode.id || currentNode._nid
101
+ if (id === selector.slice(1)) {
102
+ nodeList.push(currentNode)
103
+ if (!selectAll) break
104
+ }
105
+ } else {
106
+ if (currentNode.className?.includes(selector.slice(1))) {
107
+ nodeList.push(currentNode)
108
+ if (!selectAll) break
109
+ }
110
+ }
111
+ } else if (typeof selector === 'function') {
112
+ if (selector(currentNode)) {
113
+ nodeList.push(currentNode)
114
+ if (!selectAll) break
115
+ }
116
+ }
117
+
118
+ if (currentNode.childNodes && currentNode.childNodes.length) {
119
+ // @ts-ignore
120
+ queue.push(...currentNode.childNodes)
121
+ }
122
+ }
123
+ }
124
+
125
+ if (nodeList.length) {
126
+ return selectAll ? nodeList : nodeList[0]
127
+ }
128
+
129
+ return null
130
+ }
131
+
132
+ export type TaroAny = any
133
+ export type TaroFunc = (...args: TaroAny[]) => TaroAny
134
+ export type TaroIndent = string | number | boolean | undefined | null
135
+ export type TaroObject = Record<string | number | symbol, TaroAny>
@@ -0,0 +1,128 @@
1
+ import { isFunction } from '@tarojs/shared'
2
+
3
+ import type { TaroElement } from '../dom/element'
4
+
5
+ export const AREA_CHANGE_EVENT_NAME = 'areaChange'
6
+ export const VISIBLE_CHANGE_EVENT_NAME = 'visibleChange'
7
+
8
+ function capitalize (s: string) {
9
+ return s.charAt(0).toUpperCase() + s.slice(1)
10
+ }
11
+
12
+ export function createEventOnName (eventName: string) {
13
+ return `on${capitalize(eventName)}`
14
+ }
15
+
16
+ export function createEventTapName (eventName: string) {
17
+ return `is${capitalize(eventName)}Tap`
18
+ }
19
+
20
+ export const disconnectEvent = (node: TaroElement, eventName: string) => {
21
+ if (!node) return null
22
+
23
+ const id = node._nid
24
+ const component = node._instance
25
+
26
+ try {
27
+ component.nodeInfoMap[id].eventMap[createEventTapName(eventName)] = false
28
+ } catch (e) {
29
+ console.warn(`disconnectEvent ${eventName} error: `, e)
30
+ }
31
+ }
32
+
33
+ export function getComponentEventCallback (node: TaroElement, eventName: string, callback?: (data: {component: any, eventResult: any}) => void) {
34
+ if (!node || !node?._instance) return null
35
+
36
+ const id = node._nid
37
+ const component = node?._instance
38
+
39
+ if (component?.nodeInfoMap?.[id]?.eventMap?.[createEventTapName(eventName)]) {
40
+ return (...eventResult: any[]) => {
41
+ if (!component?.nodeInfoMap?.[id]?.eventMap?.[createEventTapName(eventName)]) return
42
+
43
+ const res = {
44
+ component,
45
+ eventResult
46
+ }
47
+
48
+ callback && callback.call(component, res)
49
+
50
+ node?.[createEventOnName(eventName)]?.(res)
51
+ }
52
+ }
53
+
54
+ return null
55
+ }
56
+
57
+ // eslint-disable-next-line @typescript-eslint/ban-types
58
+ function tapCallbackToNodeAndUpdate (node: TaroElement, eventName: string, callback: Function) {
59
+ const id = node._nid
60
+
61
+ node._instance.nodeInfoMap[id].eventMap[createEventTapName(eventName)] = true
62
+ node[createEventOnName(eventName)] = ({ eventResult }) => {
63
+ callback && callback(...eventResult)
64
+ }
65
+
66
+ // 是半编译模式的节点但没有自主更新权,需要父节点触发更新
67
+ if (!node._isDynamicNode && node._isCompileMode) {
68
+ node.updateComponent()
69
+ }
70
+ }
71
+
72
+ // eslint-disable-next-line @typescript-eslint/ban-types
73
+ export async function setNodeEventCallbackAndTriggerComponentUpdate (node: TaroElement, eventName: string, callback: Function, isAsync = false) {
74
+ const id = node._nid
75
+ const instance = node._instance
76
+
77
+ if (isAsync) {
78
+ // 阻塞函数执行,等待监听节点绑定上的回调函数
79
+ if (!instance.nodeInfoMap[id].eventMap[createEventTapName(eventName)]) {
80
+ let onEventPromiseResolve
81
+ const eventPromise = new Promise(resolve => {
82
+ onEventPromiseResolve = resolve
83
+ })
84
+
85
+ instance.nodeInfoMap[id].promiseMap[eventName] = eventPromise
86
+ tapCallbackToNodeAndUpdate(node, eventName, (...eventResult) => {
87
+ callback && callback(...eventResult)
88
+
89
+ onEventPromiseResolve()
90
+ })
91
+ }
92
+
93
+ await instance.nodeInfoMap[id].promiseMap[eventName]
94
+ } else {
95
+ tapCallbackToNodeAndUpdate(node, eventName, callback)
96
+ }
97
+ }
98
+
99
+ // eslint-disable-next-line @typescript-eslint/ban-types
100
+ export function bindAttributesCallback (node: TaroElement, attributeName: string, callback: Function) {
101
+ if (!node) return
102
+
103
+ const id = node._nid
104
+ const component = node._instance
105
+
106
+ component.nodeInfoMap[id].attributeCallback[attributeName] = callback
107
+ }
108
+
109
+ export function triggerAttributesCallback (node, attributeName) {
110
+ if (!node) return
111
+
112
+ const id = node._nid
113
+ const value = node._attrs[attributeName]
114
+
115
+ return node.awaitAppear.then(() => {
116
+ const component = node._instance
117
+ const cb = component.nodeInfoMap[id].attributeCallback[attributeName]
118
+
119
+ isFunction(cb) && cb(value)
120
+ })
121
+ }
122
+
123
+ export function initComponentNodeInfo (component: any, node: TaroElement) {
124
+ component.nodeInfoMap[node._nid] = {}
125
+ component.nodeInfoMap[node._nid].eventMap = {}
126
+ component.nodeInfoMap[node._nid].promiseMap = {}
127
+ component.nodeInfoMap[node._nid].attributeCallback = {}
128
+ }