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

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 (202) hide show
  1. package/dist/apis/apis.ts +6 -2
  2. package/dist/apis/base/crypto.ts +4 -0
  3. package/dist/apis/base/debug.ts +5 -0
  4. package/dist/apis/base/index.ts +9 -1
  5. package/dist/apis/base/performance.ts +8 -0
  6. package/dist/apis/base/system.ts +1 -1
  7. package/dist/apis/base/update.ts +5 -0
  8. package/dist/apis/base/weapp/app-event.ts +75 -0
  9. package/dist/apis/base/weapp/life-cycle.ts +21 -0
  10. package/dist/apis/canvas/index.ts +18 -0
  11. package/dist/apis/data-analysis/index.ts +6 -0
  12. package/dist/apis/device/accelerometer.ts +2 -1
  13. package/dist/apis/device/accessibility.ts +4 -0
  14. package/dist/apis/device/battery.ts +2 -2
  15. package/dist/apis/device/bluetooth-ble.ts +19 -0
  16. package/dist/apis/device/bluetooth-peripheral.ts +6 -0
  17. package/dist/apis/device/bluetooth.ts +16 -0
  18. package/dist/apis/device/calendar.ts +5 -0
  19. package/dist/apis/device/clipboard.ts +1 -1
  20. package/dist/apis/device/compass.ts +21 -0
  21. package/dist/apis/device/contact.ts +5 -0
  22. package/dist/apis/device/crypto.ts +4 -0
  23. package/dist/apis/device/gyroscope.ts +7 -0
  24. package/dist/apis/device/iBeacon.ts +10 -0
  25. package/dist/apis/device/index.ts +15 -0
  26. package/dist/apis/device/keyboard.ts +2 -1
  27. package/dist/apis/device/memory.ts +10 -3
  28. package/dist/apis/device/motion.ts +6 -0
  29. package/dist/apis/device/network.ts +26 -9
  30. package/dist/apis/device/nfc.ts +10 -0
  31. package/dist/apis/device/phone.ts +2 -1
  32. package/dist/apis/device/scan.ts +4 -0
  33. package/dist/apis/device/screen.ts +2 -1
  34. package/dist/apis/device/sms.ts +4 -0
  35. package/dist/apis/device/vibrate.ts +19 -11
  36. package/dist/apis/device/wifi.ts +15 -0
  37. package/dist/apis/ext/index.ts +5 -0
  38. package/dist/apis/files/index.ts +2 -1
  39. package/dist/apis/files/manager.ts +2 -1
  40. package/dist/apis/framework/index.ts +5 -6
  41. package/dist/apis/index.ts +2 -0
  42. package/dist/apis/location/index.ts +61 -68
  43. package/dist/apis/media/EditorContext.ts +32 -0
  44. package/dist/apis/media/audio/index.ts +18 -0
  45. package/dist/apis/media/background-audio/index.ts +16 -0
  46. package/dist/apis/media/camera.ts +16 -0
  47. package/dist/apis/media/common.ts +2 -1
  48. package/dist/apis/media/{image.ts → image/index.ts} +3 -2
  49. package/dist/apis/media/index.ts +10 -0
  50. package/dist/apis/media/live.ts +5 -0
  51. package/dist/apis/media/map.ts +4 -0
  52. package/dist/apis/media/media-recorder.ts +4 -0
  53. package/dist/apis/media/recorder.ts +6 -0
  54. package/dist/apis/media/video/VideoContext.ts +68 -0
  55. package/dist/apis/media/{video.ts → video/index.ts} +13 -2
  56. package/dist/apis/media/video-decoder.ts +4 -0
  57. package/dist/apis/media/video-processing.ts +4 -0
  58. package/dist/apis/media/voip.ts +19 -0
  59. package/dist/apis/network/index.ts +3 -0
  60. package/dist/apis/network/mdns.ts +13 -0
  61. package/dist/apis/network/request.ts +7 -6
  62. package/dist/apis/network/tcp.ts +4 -0
  63. package/dist/apis/network/udp.ts +4 -0
  64. package/dist/apis/network/webSocket.ts +2 -6
  65. package/dist/apis/open-api/account.ts +4 -0
  66. package/dist/apis/open-api/address.ts +4 -0
  67. package/dist/apis/open-api/authorize.ts +5 -0
  68. package/dist/apis/open-api/card.ts +5 -0
  69. package/dist/apis/open-api/channels-live.ts +11 -0
  70. package/dist/apis/open-api/customer-service.ts +4 -0
  71. package/dist/apis/open-api/device-voip.ts +5 -0
  72. package/dist/apis/open-api/facial.ts +7 -0
  73. package/dist/apis/open-api/favorites.ts +5 -0
  74. package/dist/apis/open-api/group.ts +4 -0
  75. package/dist/apis/open-api/index.ts +20 -6
  76. package/dist/apis/open-api/invoice.ts +5 -0
  77. package/dist/apis/open-api/license-plate.ts +4 -0
  78. package/dist/apis/open-api/login.ts +6 -0
  79. package/dist/apis/open-api/my-miniprogram.ts +4 -0
  80. package/dist/apis/open-api/privacy.ts +7 -0
  81. package/dist/apis/open-api/red-package.ts +4 -0
  82. package/dist/apis/open-api/settings.ts +5 -0
  83. package/dist/apis/open-api/soter.ts +6 -0
  84. package/dist/apis/open-api/subscribe-message.ts +6 -0
  85. package/dist/apis/open-api/{user-info/index.ts → user-info.ts} +1 -16
  86. package/dist/apis/open-api/werun.ts +5 -0
  87. package/dist/apis/payment/index.ts +6 -0
  88. package/dist/apis/route/index.ts +19 -28
  89. package/dist/apis/share/index.ts +33 -0
  90. package/dist/apis/storage/background-fetch.ts +7 -0
  91. package/dist/apis/storage/cache-manager.ts +4 -0
  92. package/dist/apis/storage/index.ts +20 -18
  93. package/dist/apis/ui/{animation.ts → animation/animation.ts} +2 -2
  94. package/dist/apis/ui/animation/index.ts +7 -0
  95. package/dist/apis/ui/background.ts +2 -18
  96. package/dist/apis/ui/custom-component.ts +8 -0
  97. package/dist/apis/ui/fonts.ts +4 -0
  98. package/dist/apis/ui/index.ts +8 -10
  99. package/dist/apis/ui/interaction/index.ts +3 -0
  100. package/dist/apis/ui/menu.ts +4 -0
  101. package/dist/apis/ui/navigation-bar/index.ts +60 -21
  102. package/dist/apis/ui/pull-down-refresh.ts +1 -1
  103. package/dist/apis/{page → ui/scroll}/index.ts +27 -22
  104. package/dist/apis/ui/sticky.ts +4 -0
  105. package/dist/apis/{tabbar/index.ts → ui/tab-bar.ts} +3 -5
  106. package/dist/apis/ui/window.ts +20 -0
  107. package/dist/apis/utils/handler.ts +4 -4
  108. package/dist/apis/worker/index.ts +4 -0
  109. package/dist/apis/wxml/IntersectionObserver.ts +12 -21
  110. package/dist/apis/wxml/index.ts +7 -2
  111. package/dist/apis/wxml/nodesRef.ts +2 -2
  112. package/dist/apis/wxml/selectorQuery.ts +3 -4
  113. package/dist/components-harmony-ets/button.ets +97 -85
  114. package/dist/components-harmony-ets/checkbox.ets +68 -142
  115. package/dist/components-harmony-ets/form.ets +31 -140
  116. package/dist/components-harmony-ets/icon.ets +60 -75
  117. package/dist/components-harmony-ets/image.ets +14 -69
  118. package/dist/components-harmony-ets/innerHtml.ets +6 -74
  119. package/dist/components-harmony-ets/input.ets +62 -152
  120. package/dist/components-harmony-ets/label.ets +63 -96
  121. package/dist/components-harmony-ets/picker.ets +168 -198
  122. package/dist/components-harmony-ets/radio.ets +69 -146
  123. package/dist/components-harmony-ets/richText.ets +14 -70
  124. package/dist/components-harmony-ets/scrollView.ets +84 -156
  125. package/dist/components-harmony-ets/slider.ets +40 -88
  126. package/dist/components-harmony-ets/style.ets +154 -0
  127. package/dist/components-harmony-ets/swiper.ets +25 -166
  128. package/dist/components-harmony-ets/switch.ets +29 -72
  129. package/dist/components-harmony-ets/text.ets +37 -68
  130. package/dist/components-harmony-ets/textArea.ets +44 -132
  131. package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -11
  132. package/dist/components-harmony-ets/utils/constant/style.ets +9 -6
  133. package/dist/components-harmony-ets/utils/flexManager.ets +45 -92
  134. package/dist/components-harmony-ets/utils/helper.ets +4 -64
  135. package/dist/components-harmony-ets/utils/index.ts +1 -1
  136. package/dist/components-harmony-ets/utils/styles.ets +62 -27
  137. package/dist/components-harmony-ets/video.ets +63 -122
  138. package/dist/components-harmony-ets/view.ets +52 -69
  139. package/dist/components-harmony-ets/webView.ets +50 -0
  140. package/dist/index.js +135 -8
  141. package/dist/index.js.map +1 -1
  142. package/dist/runtime-ets/bom/getComputedStyle.ts +1 -1
  143. package/dist/runtime-ets/bom/window.ts +2 -2
  144. package/dist/runtime-ets/dom/bind.ts +80 -0
  145. package/dist/runtime-ets/dom/class-list.ts +2 -4
  146. package/dist/runtime-ets/dom/comment.ts +1 -2
  147. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +31 -7
  148. package/dist/runtime-ets/dom/dataSource.ts +64 -0
  149. package/dist/runtime-ets/dom/document.ts +35 -47
  150. package/dist/runtime-ets/dom/element/element.ts +163 -0
  151. package/dist/runtime-ets/dom/element/form.ts +406 -0
  152. package/dist/runtime-ets/dom/element/index.ts +92 -0
  153. package/dist/runtime-ets/dom/element/normal.ts +76 -0
  154. package/dist/runtime-ets/dom/element/scrollView.ts +14 -0
  155. package/dist/runtime-ets/dom/element/text.ts +17 -0
  156. package/dist/runtime-ets/dom/element/video.ts +49 -0
  157. package/dist/runtime-ets/dom/element/webView.ts +61 -0
  158. package/dist/runtime-ets/dom/event.ts +24 -1
  159. package/dist/runtime-ets/dom/eventTarget.ts +2 -1
  160. package/dist/runtime-ets/dom/node.ts +87 -44
  161. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +624 -0
  162. package/dist/runtime-ets/dom/stylesheet/index.ts +263 -288
  163. package/dist/runtime-ets/dom/stylesheet/type.ts +47 -11
  164. package/dist/runtime-ets/dom/stylesheet/util.ts +129 -7
  165. package/dist/runtime-ets/index.ts +1 -3
  166. package/dist/runtime-ets/interface/event.ts +2 -1
  167. package/dist/runtime-ets/utils/index.ts +18 -8
  168. package/dist/runtime-ets/utils/info.ts +22 -48
  169. package/dist/runtime-framework/react/app.ts +14 -27
  170. package/dist/runtime-framework/react/hooks.ts +3 -3
  171. package/dist/runtime-framework/react/index.ts +1 -0
  172. package/dist/runtime-framework/react/native-page.ts +344 -0
  173. package/dist/runtime-framework/react/page.ts +4 -11
  174. package/dist/runtime-framework/solid/hooks.ts +3 -3
  175. package/dist/runtime-framework/solid/page.ts +0 -6
  176. package/dist/runtime-utils.js +1216 -349
  177. package/dist/runtime-utils.js.map +1 -1
  178. package/dist/runtime.js +1216 -349
  179. package/dist/runtime.js.map +1 -1
  180. package/package.json +12 -11
  181. package/static/media/cancel.svg +1 -0
  182. package/static/media/circle.svg +1 -0
  183. package/static/media/clear.svg +1 -0
  184. package/static/media/download.svg +1 -0
  185. package/static/media/info.svg +1 -0
  186. package/static/media/info_circle.svg +1 -0
  187. package/static/media/search.svg +1 -0
  188. package/static/media/success.svg +1 -0
  189. package/static/media/success_no_circle.svg +1 -0
  190. package/static/media/taro_arrow_left.svg +1 -0
  191. package/static/media/taro_home.svg +1 -0
  192. package/static/media/waiting.svg +1 -0
  193. package/static/media/warn.svg +1 -0
  194. package/types/runtime.d.ts +6 -0
  195. package/LICENSE +0 -160
  196. package/dist/components-harmony-ets/base.ets +0 -63
  197. package/dist/components-harmony-ets/element.ets +0 -223
  198. package/dist/components-harmony-ets/utils/constant/icon.ts +0 -19
  199. package/dist/runtime-ets/dom/element.ts +0 -457
  200. package/dist/runtime-ets/dom/text.ts +0 -19
  201. package/dist/runtime-ets/utils/bind.ts +0 -35
  202. package/types/api.d.ts +0 -4
@@ -1,20 +1,33 @@
1
+ // @ts-nocheck
1
2
  import matrix4 from '@ohos.matrix4'
2
3
 
3
4
  export interface HarmonyStyle extends TaroStyleType {
4
5
  textAlign?: TextAlign
5
6
  textOverflow?: HarmonyType.Overflow
6
- maxLines?: number
7
+ WebkitLineClamp?: number
7
8
  letterSpacing?: number | string
8
9
  }
9
10
 
10
11
  export interface TaroStyleType {
11
12
  id?: string
12
13
 
13
- padding?: Margin | Length
14
- margin?: Margin | Length
14
+ paddingTop?: Length
15
+ paddingRight?: Length
16
+ paddingBottom?: Length
17
+ paddingLeft?: Length
18
+
19
+ marginTop?: Length
20
+ marginRight?: Length
21
+ marginBottom?: Length
22
+ marginLeft?: Length
23
+
15
24
  width?: Length
16
25
  height?: Length
17
- constraintSize?: ConstraintSizeOptions
26
+
27
+ minHeight?: Length
28
+ maxHeight?: Length
29
+ minWidth?: Length
30
+ maxWidth?: Length
18
31
 
19
32
  display?: 'flex' | 'block' | 'none'
20
33
 
@@ -28,29 +41,47 @@ export interface TaroStyleType {
28
41
  flexGrow?: number
29
42
  flexShrink?: number
30
43
  alignSelf?: ItemAlign
31
- direction?: FlexDirection
44
+ flexDirection?: FlexDirection
32
45
  justifyContent?: FlexAlign
33
46
  alignItems?: ItemAlign
34
- wrap?: FlexWrap
47
+ flexWrap?: FlexWrap
35
48
  alignContent?: FlexAlign
36
49
 
37
50
  // background
38
51
  backgroundColor?: ResourceColor
39
- backgroundImage?: ResourceStr
52
+ backgroundImage?: HarmonyType.Background.BackgroundImage
40
53
  backgroundRepeat?: ImageRepeat
41
- backgroundImageSize?: SizeOptions | ImageSize
54
+ backgroundSize?: SizeOptions | ImageSize
55
+ backgroundPosition?: Position | Alignment
42
56
 
43
57
  // transform
44
58
  rotate?: HarmonyType.Transform.Rotate
45
59
  translate?: HarmonyType.Transform.Translate
46
60
  scale?: HarmonyType.Transform.Scale
47
61
  transform?: HarmonyType.Transform.Transform
62
+ transformOrigin?: HarmonyType.Transform.Origin
48
63
 
49
64
  // border
50
65
  borderWidth?: Length | EdgeWidths
66
+ borderLeftWidth?: Length
67
+ borderRightWidth?: Length
68
+ borderTopWidth?: Length
69
+ borderBottomWidth?: Length
51
70
  borderColor?: ResourceColor | EdgeColors
71
+ borderLeftColor?: ResourceColor
72
+ borderRightColor?: ResourceColor
73
+ borderTopColor?: ResourceColor
74
+ borderBottomColor?: ResourceColor
52
75
  borderStyle?: BorderStyle | EdgeStyles
76
+ borderLeftStyle?: BorderStyle
77
+ borderRightStyle?: BorderStyle
78
+ borderTopStyle?: BorderStyle
79
+ borderBottomStyle?: BorderStyle
53
80
  borderRadius?: Length | BorderRadiuses
81
+ borderTopLeftRadius?: Length
82
+ borderTopRightRadius?: Length
83
+ borderBottomLeftRadius?: Length
84
+ borderBottomRightRadius?: Length
54
85
 
55
86
  // text
56
87
  color?: ResourceColor
@@ -59,7 +90,7 @@ export interface TaroStyleType {
59
90
  fontWeight?: number | FontWeight | string
60
91
  fontFamily?: string | Resource
61
92
  lineHeight?: string | number | Resource
62
- decoration?: TextDecorationType
93
+ textDecoration?: TextDecorationType
63
94
 
64
95
  // gradient
65
96
  linearGradient?: HarmonyType.LinearGradient
@@ -67,14 +98,14 @@ export interface TaroStyleType {
67
98
  // other
68
99
  opacity?: number | Resource
69
100
  zIndex?: number
70
- clip?: boolean
101
+ overflow?: boolean
71
102
  focus?: boolean
72
103
  }
73
104
 
74
105
  export interface TaroTextStyleType {
75
106
  textAlign?: TextAlign
76
107
  textOverflow?: HarmonyType.Overflow
77
- maxLines?: number
108
+ WebkitLineClamp?: number
78
109
  letterSpacing?: number | string
79
110
  }
80
111
 
@@ -103,11 +134,16 @@ export namespace HarmonyType {
103
134
  export interface backgroundImage {
104
135
  src: ResourceStr
105
136
  repeat?: ImageRepeat
137
+ colors?: Array<[ResourceColor, number]>
106
138
  }
107
139
  export type backgroundImageSize = SizeOptions | ImageSize
108
140
  export type backgroundImagePosition = Position | Alignment
109
141
  }
110
142
  export namespace Transform {
143
+ export interface Origin {
144
+ x?: number
145
+ y?: number
146
+ }
111
147
  export interface Rotate {
112
148
  x?: number
113
149
  y?: number
@@ -1,10 +1,10 @@
1
1
  // @ts-nocheck
2
+ import matrix4 from '@ohos.matrix4'
2
3
  import { isNumber } from '@tarojs/shared'
3
4
 
4
5
  import { convertNumber2VP } from '../../'
5
6
 
6
7
  export class FlexManager {
7
-
8
8
  static flexAlign (value: string | number | undefined): FlexAlign {
9
9
  switch (value) {
10
10
  case 'flex-end':
@@ -22,6 +22,25 @@ export class FlexManager {
22
22
  }
23
23
  }
24
24
 
25
+ static reverseFlexAlign (value: FlexAlign): string {
26
+ switch (value) {
27
+ case FlexAlign.Start:
28
+ return 'flex-start'
29
+ case FlexAlign.End:
30
+ return 'flex-end'
31
+ case FlexAlign.Center:
32
+ return 'center'
33
+ case FlexAlign.SpaceBetween:
34
+ return 'space-between'
35
+ case FlexAlign.SpaceAround:
36
+ return 'space-around'
37
+ case FlexAlign.SpaceEvenly:
38
+ return 'space-evenly'
39
+ default:
40
+ return ''
41
+ }
42
+ }
43
+
25
44
  static direction (value: string): FlexDirection {
26
45
  switch (value) {
27
46
  case 'row': return FlexDirection.Row
@@ -31,6 +50,16 @@ export class FlexManager {
31
50
  }
32
51
  }
33
52
 
53
+ static reverseDirection (value: FlexDirection): string {
54
+ switch (value) {
55
+ case FlexDirection.Row: return 'row'
56
+ case FlexDirection.RowReverse: return 'row-reverse'
57
+ case FlexDirection.Column: return 'column'
58
+ case FlexDirection.ColumnReverse: return 'column-reverse'
59
+ default: return ''
60
+ }
61
+ }
62
+
34
63
  static itemAlign (value: string | number | undefined): ItemAlign {
35
64
  switch (value) {
36
65
  case 'flex-start':
@@ -48,6 +77,25 @@ export class FlexManager {
48
77
  }
49
78
  }
50
79
 
80
+ static reverseItemAlign (value: ItemAlign): string {
81
+ switch (value) {
82
+ case ItemAlign.Start:
83
+ return 'flex-start'
84
+ case ItemAlign.End:
85
+ return 'flex-end'
86
+ case ItemAlign.Center:
87
+ return 'center'
88
+ case ItemAlign.Stretch:
89
+ return 'stretch'
90
+ case ItemAlign.Baseline:
91
+ return 'baseline'
92
+ case ItemAlign.Auto:
93
+ return 'auto'
94
+ default:
95
+ return ''
96
+ }
97
+ }
98
+
51
99
  static justifyContent (value: string): FlexAlign {
52
100
  return FlexManager.flexAlign(value)
53
101
  }
@@ -61,7 +109,29 @@ export class FlexManager {
61
109
  }
62
110
 
63
111
  static flexWrap (value: string): FlexWrap {
64
- return value === 'wrap' ? FlexWrap.Wrap : FlexWrap.NoWrap
112
+ switch (value) {
113
+ case 'nowrap':
114
+ return FlexWrap.NoWrap
115
+ case 'wrap':
116
+ return FlexWrap.Wrap
117
+ case 'wrap-reverse':
118
+ return FlexWrap.WrapReverse
119
+ default:
120
+ return FlexWrap.NoWrap
121
+ }
122
+ }
123
+
124
+ static reverseFlexWrap (value: FlexWrap): string {
125
+ switch (value) {
126
+ case FlexWrap.NoWrap:
127
+ return 'nowrap'
128
+ case FlexWrap.Wrap:
129
+ return 'wrap'
130
+ case FlexWrap.WrapReverse:
131
+ return 'wrap-reverse'
132
+ default:
133
+ return 'nowrap'
134
+ }
65
135
  }
66
136
 
67
137
  static alignContent (style: Record<string, string | number> = {}): FlexAlign | undefined {
@@ -93,6 +163,32 @@ export class FlexManager {
93
163
  }
94
164
  }
95
165
 
166
+
167
+ export class BORDER_STYLE_MAP {
168
+ static solid = BorderStyle.Solid
169
+ static dotted = BorderStyle.Dotted
170
+ static dashed = BorderStyle.Dashed
171
+
172
+ static get(type: string): BorderStyle {
173
+ switch (type) {
174
+ case 'dotted': return BorderStyle.Dotted
175
+ case 'dashed': return BorderStyle.Dashed
176
+ default: return BorderStyle.Solid
177
+ }
178
+ }
179
+
180
+ static reverse(type: BorderStyle): string {
181
+ switch (type) {
182
+ case BorderStyle.Dotted: return 'dotted'
183
+ case BorderStyle.Dashed: return 'dashed'
184
+ case BorderStyle.Solid: return 'solid'
185
+ default: return ''
186
+ }
187
+
188
+ }
189
+ }
190
+
191
+
96
192
  export function getNodeMarginOrPaddingData (dataValue: string) {
97
193
  let res: any = {}
98
194
  if (dataValue) {
@@ -114,10 +210,7 @@ export function getNodeMarginOrPaddingData (dataValue: string) {
114
210
  break
115
211
  }
116
212
  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
- }
213
+ res[key] = getUnit(res[key]) || 0
121
214
  })
122
215
  }
123
216
  return res
@@ -125,10 +218,39 @@ export function getNodeMarginOrPaddingData (dataValue: string) {
125
218
 
126
219
 
127
220
  export function getUnit (val) {
221
+ // 空的字符串代表 Reconciler remove 了这个 prop,不进行后面的逻辑了
222
+ if (val === '') return val
223
+
128
224
  if (/\d+(vp)$/.test(val)) {
129
225
  return val
130
- } else if (isNumber(val) || /\d+px$/.test(val)) {
226
+ } else if (isNumber(val)) {
131
227
  return convertNumber2VP(parseFloat(val))
132
228
  }
229
+ if (val) {
230
+ // 匹配vw\vh
231
+ const exec = val.match(/(\d+)(vw|vh|px)$/)
232
+ if (exec) {
233
+ const [, num, unit] = exec
234
+ return convertNumber2VP(parseFloat(num), unit)
235
+ }
236
+ }
133
237
  return val
134
238
  }
239
+
240
+ export function getTransform(transform) {
241
+ if (transform) {
242
+ return transform.reduce((res, item) => {
243
+ switch (item.type) {
244
+ case 'Translate': return res.translate(item.value)
245
+ case 'Scale': return res.scale(item.value)
246
+ case 'Rotate': return res.rotate(item.value)
247
+ case 'Matrix': return res.combine(matrix4.init(item.value))
248
+ }
249
+ return res
250
+ }, matrix4.identity())
251
+ }
252
+ }
253
+
254
+ export function capitalizeFirstLetter (str: string) {
255
+ return str.charAt(0).toUpperCase() + str.slice(1)
256
+ }
@@ -9,11 +9,9 @@ export * from './bom/window'
9
9
  export * from './dom/element'
10
10
  export * from './dom/event'
11
11
  export * from './dom/node'
12
- export * from './dom/text'
13
12
  export * from './dom/stylesheet'
14
13
  export * from './interface'
15
14
  export * from './utils'
16
- export * from './utils/bind'
17
15
  export * from './utils/info'
18
- export { URLSearchParams, eventSource } from '@tarojs/runtime/dist/runtime.esm'
16
+ export { URLSearchParams, eventSource, Events } from '@tarojs/runtime/dist/runtime.esm'
19
17
  export { hooks } from '@tarojs/shared'
@@ -4,6 +4,7 @@ export interface EventOptions {
4
4
  [x: string]: any
5
5
  }
6
6
 
7
- export interface EventHandler extends Function {
7
+ export interface EventHandler<T = any, R = void> {
8
+ (...args: T[]): R
8
9
  _stop?: boolean
9
10
  }
@@ -1,11 +1,15 @@
1
+ import _display from '@ohos.display'
1
2
  import { pxTransformHelper } from '@tarojs/taro'
2
3
 
3
4
  import { NodeType } from '../dom/node'
5
+ import convertWebStyle2HmStyle from '../dom/stylesheet/covertWeb2Hm'
4
6
 
5
7
  import type { CSSProperties } from 'react'
6
- import type { TaroElement } from '../dom/element'
8
+ import type { TaroElement } from '../dom/element/element'
7
9
  import type { TaroNode } from '../dom/node'
8
10
 
11
+ const display = _display.getDefaultDisplaySync()
12
+
9
13
  export function isElement (node: TaroNode): node is TaroElement {
10
14
  return node.nodeType === NodeType.ELEMENT_NODE
11
15
  }
@@ -18,7 +22,6 @@ export function isElement (node: TaroNode): node is TaroElement {
18
22
  export function isParentBinded (node: TaroElement | null, type: string): boolean {
19
23
  let res = false
20
24
 
21
- // TODO: 当前 node 结构没有 root,因此不作判断,后续可根据情况添加 root 条件
22
25
  while (node?.parentElement) {
23
26
  if (node.parentElement.__listeners[type]?.length) {
24
27
  res = true
@@ -35,7 +38,10 @@ export function convertNumber2PX (value: number) {
35
38
  return pxTransformHelper(value, 'vp')
36
39
  }
37
40
 
38
- export function convertNumber2VP (value: number) {
41
+ export function convertNumber2VP (value: number, unit = 'px') {
42
+ if (unit === 'vw' || unit === 'vh') {
43
+ return (value / 100 * (unit === 'vw' ? display.width: display.height)) + 'px'
44
+ }
39
45
  return pxTransformHelper(value, 'vp')
40
46
  }
41
47
 
@@ -48,7 +54,11 @@ export function calcDynamicStyle (styleSheet: Record<string, CSSProperties>, cla
48
54
  obj.push(styleSheet[className])
49
55
  }
50
56
  }
51
- obj.push(style)
57
+
58
+ if (style) {
59
+ obj.push(convertWebStyle2HmStyle(style))
60
+ }
61
+
52
62
  return Object.assign.apply(null, [{}].concat(obj))
53
63
  }
54
64
 
@@ -84,10 +94,10 @@ export function bindFn (fn: any, ctx: any, ...args: any) {
84
94
 
85
95
  // 使用深度优先遍历寻找节点树中对应的子节点,且只需要找到第一个
86
96
  // 通过 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 {
97
+ export function findChildNodeWithDFS<T extends TaroElement = TaroElement> (node: TaroElement, selector: string | ((ele: T) => boolean), selectAll: true): T[] | null;
98
+ export function findChildNodeWithDFS<T extends TaroElement = TaroElement> (node: TaroElement, selector: string | ((ele: T) => boolean), selectAll?: false): T | null;
99
+ export function findChildNodeWithDFS<T extends TaroElement = TaroElement> (node: TaroElement, selector: string | ((ele: T) => boolean), selectAll: boolean): T[] | T | null;
100
+ export function findChildNodeWithDFS<T extends TaroElement = TaroElement> (node: TaroElement, selector: string | ((ele: T) => boolean), selectAll): T[] | T | null {
91
101
  const queue = [node]
92
102
 
93
103
  const nodeList: TaroElement[] = []
@@ -1,6 +1,6 @@
1
1
  import { isFunction } from '@tarojs/shared'
2
2
 
3
- import type { TaroElement } from '../dom/element'
3
+ import type { TaroElement } from '../dom/element/element'
4
4
 
5
5
  export const AREA_CHANGE_EVENT_NAME = 'areaChange'
6
6
  export const VISIBLE_CHANGE_EVENT_NAME = 'visibleChange'
@@ -20,34 +20,23 @@ export function createEventTapName (eventName: string) {
20
20
  export const disconnectEvent = (node: TaroElement, eventName: string) => {
21
21
  if (!node) return null
22
22
 
23
- const id = node._nid
24
- const component = node._instance
25
-
26
23
  try {
27
- component.nodeInfoMap[id].eventMap[createEventTapName(eventName)] = false
24
+ node._nodeInfo.eventMap[createEventTapName(eventName)] = false
28
25
  } catch (e) {
29
26
  console.warn(`disconnectEvent ${eventName} error: `, e)
30
27
  }
31
28
  }
32
29
 
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
30
+ export function getComponentEventCallback (node: TaroElement, eventName: string, callback?: (data: any) => void) {
31
+ if (!node) return null
38
32
 
39
- if (component?.nodeInfoMap?.[id]?.eventMap?.[createEventTapName(eventName)]) {
33
+ if (node._nodeInfo?.eventMap?.[createEventTapName(eventName)]) {
40
34
  return (...eventResult: any[]) => {
41
- if (!component?.nodeInfoMap?.[id]?.eventMap?.[createEventTapName(eventName)]) return
42
-
43
- const res = {
44
- component,
45
- eventResult
46
- }
35
+ if (!node._nodeInfo?.eventMap?.[createEventTapName(eventName)]) return
47
36
 
48
- callback && callback.call(component, res)
37
+ callback && callback(eventResult)
49
38
 
50
- node?.[createEventOnName(eventName)]?.(res)
39
+ node?.[createEventOnName(eventName)]?.(eventResult)
51
40
  }
52
41
  }
53
42
 
@@ -56,33 +45,27 @@ export function getComponentEventCallback (node: TaroElement, eventName: string,
56
45
 
57
46
  // eslint-disable-next-line @typescript-eslint/ban-types
58
47
  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 }) => {
48
+ node._nodeInfo.eventMap[createEventTapName(eventName)] = true
49
+ node[createEventOnName(eventName)] = (eventResult) => {
63
50
  callback && callback(...eventResult)
64
51
  }
65
52
 
66
- // 是半编译模式的节点但没有自主更新权,需要父节点触发更新
67
- if (!node._isDynamicNode && node._isCompileMode) {
53
+ if (!node._isDynamicNode || !node._isCompileMode) {
68
54
  node.updateComponent()
69
55
  }
70
56
  }
71
57
 
72
58
  // eslint-disable-next-line @typescript-eslint/ban-types
73
59
  export async function setNodeEventCallbackAndTriggerComponentUpdate (node: TaroElement, eventName: string, callback: Function, isAsync = false) {
74
- const id = node._nid
75
- const instance = node._instance
76
-
77
60
  if (isAsync) {
78
61
  // 阻塞函数执行,等待监听节点绑定上的回调函数
79
- if (!instance.nodeInfoMap[id].eventMap[createEventTapName(eventName)]) {
62
+ if (!node._nodeInfo.eventMap[createEventTapName(eventName)]) {
80
63
  let onEventPromiseResolve
81
64
  const eventPromise = new Promise(resolve => {
82
65
  onEventPromiseResolve = resolve
83
66
  })
84
67
 
85
- instance.nodeInfoMap[id].promiseMap[eventName] = eventPromise
68
+ node._nodeInfo.promiseMap[eventName] = eventPromise
86
69
  tapCallbackToNodeAndUpdate(node, eventName, (...eventResult) => {
87
70
  callback && callback(...eventResult)
88
71
 
@@ -90,39 +73,30 @@ export async function setNodeEventCallbackAndTriggerComponentUpdate (node: TaroE
90
73
  })
91
74
  }
92
75
 
93
- await instance.nodeInfoMap[id].promiseMap[eventName]
76
+ await node._nodeInfo.promiseMap[eventName]
94
77
  } else {
95
78
  tapCallbackToNodeAndUpdate(node, eventName, callback)
96
79
  }
97
80
  }
98
81
 
99
82
  // eslint-disable-next-line @typescript-eslint/ban-types
100
- export function bindAttributesCallback (node: TaroElement, attributeName: string, callback: Function) {
83
+ export function bindAttributesCallback (node: TaroElement, _: string, callback: Function) {
101
84
  if (!node) return
102
85
 
103
- const id = node._nid
104
- const component = node._instance
105
-
106
- component.nodeInfoMap[id].attributeCallback[attributeName] = callback
86
+ node._nodeInfo = callback
107
87
  }
108
88
 
109
89
  export function triggerAttributesCallback (node, attributeName) {
110
90
  if (!node) return
111
91
 
112
- const id = node._nid
113
92
  const value = node._attrs[attributeName]
114
-
115
- return node.awaitAppear.then(() => {
116
- const component = node._instance
117
- const cb = component.nodeInfoMap[id].attributeCallback[attributeName]
93
+ const cb = node._nodeInfo.attributeCallback[attributeName]
118
94
 
119
- isFunction(cb) && cb(value)
120
- })
95
+ isFunction(cb) && cb(value)
121
96
  }
122
97
 
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 = {}
98
+ export function initComponentNodeInfo (node: TaroElement) {
99
+ node._nodeInfo.eventMap = {}
100
+ node._nodeInfo.promiseMap = {}
101
+ node._nodeInfo.attributeCallback = {}
128
102
  }
@@ -1,7 +1,5 @@
1
- // eslint-disable-next-line import/no-duplicates
2
- import { Current, document } from '@tarojs/runtime'
3
- // eslint-disable-next-line import/no-duplicates
4
- import { eventCenter } from '@tarojs/runtime/dist/runtime.esm'
1
+ import { Current, document } from '@tarojs/runtime' // eslint-disable-line import/no-duplicates
2
+ import { AppInstance, eventCenter } from '@tarojs/runtime/dist/runtime.esm' // eslint-disable-line import/no-duplicates
5
3
 
6
4
  import { setReconciler } from './connect'
7
5
  import { injectPageInstance } from './page'
@@ -28,8 +26,11 @@ const pageKeyId = incrementId()
28
26
 
29
27
  export function connectReactPage (
30
28
  R: typeof React,
31
- id: string
29
+ id: string,
30
+ getCtx: () => any
32
31
  ) {
32
+ const ctx = getCtx?.()
33
+
33
34
  return (Page): React.ComponentClass<any> => {
34
35
  // eslint-disable-next-line dot-notation
35
36
  const isReactComponent = isClassComponent(R, Page)
@@ -65,11 +66,10 @@ export function connectReactPage (
65
66
  const children = this.state.hasError
66
67
  ? []
67
68
  : h(ReactMeta.PageContext.Provider, { value: id }, h(Page, {
68
- ...this.props,
69
+ ...Object.assign({}, ctx?.props, this.props),
69
70
  ...refs
70
71
  }))
71
72
 
72
- // TODO root
73
73
  return h(
74
74
  'view',
75
75
  { id, className: 'taro_page' },
@@ -129,8 +129,8 @@ export function createReactApp (
129
129
  appWrapperResolver(this)
130
130
  }
131
131
 
132
- public mount (pageComponent: any, id: string, cb: () => void) {
133
- const pageWrapper = connectReactPage(react, id)(pageComponent)
132
+ public mount (pageComponent: any, id: string, getCtx: () => any, cb: () => void) {
133
+ const pageWrapper = connectReactPage(react, id, getCtx)(pageComponent)
134
134
  const key = id + pageKeyId()
135
135
  const page = () => h(pageWrapper, { key, tid: id })
136
136
  this.pages.push(page)
@@ -172,14 +172,13 @@ export function createReactApp (
172
172
  render (cb: () => void) {
173
173
  appWrapper.forceUpdate(cb)
174
174
  },
175
- mount (component: any, id: string, cb: () => void) {
175
+ mount (component: any, id: string, getCtx: () => any, cb: () => void) {
176
176
  if (appWrapper) {
177
- appWrapper.mount(component, id, cb)
177
+ appWrapper.mount(component, id, getCtx, cb)
178
178
  } else {
179
- appWrapperPromise.then(appWrapper => appWrapper.mount(component, id, cb))
179
+ appWrapperPromise.then(appWrapper => appWrapper.mount(component, id, getCtx, cb))
180
180
  }
181
181
  },
182
-
183
182
  unmount (id: string, cb: () => void) {
184
183
  appWrapper?.unmount(id, cb)
185
184
  },
@@ -212,7 +211,7 @@ export function createReactApp (
212
211
 
213
212
  app.onCreate?.()
214
213
  }
215
-
214
+
216
215
  eventCenter.trigger('__taroRouterLaunch', launchParam)
217
216
  })
218
217
  },
@@ -236,19 +235,7 @@ export function createReactApp (
236
235
  app?.componentDidHide?.()
237
236
  })
238
237
  }
239
- }
240
-
241
- // TODO: function componennt hook
242
- // function triggerAppHook (lifecycle: string, ...option) {
243
- // const instance = getPageInstance('taro-app')
244
- // if (instance) {
245
- // const app = getAppInstance()
246
- // const func = hooks.call('getLifecycle', instance, lifecycle)
247
- // if (Array.isArray(func)) {
248
- // func.forEach(cb => cb.apply(app, option))
249
- // }
250
- // }
251
- // }
238
+ } as unknown as AppInstance
252
239
 
253
240
  Current.app = app
254
241
 
@@ -7,14 +7,14 @@ import { HOOKS_APP_ID } from './utils'
7
7
 
8
8
  import type {
9
9
  AppInstance,
10
- Func,
11
10
  Instance,
12
11
  PageLifeCycle,
13
- PageProps
12
+ PageProps,
13
+ TFunc
14
14
  } from '@tarojs/runtime/dist/runtime.esm'
15
15
 
16
16
  const createTaroHook = (lifecycle: keyof PageLifeCycle | keyof AppInstance) => {
17
- return (fn: Func) => {
17
+ return (fn: TFunc) => {
18
18
  const { R: React, PageContext } = ReactMeta
19
19
  const id = React.useContext(PageContext) || HOOKS_APP_ID
20
20
  const instRef = React.useRef<Instance<PageProps>>()
@@ -13,4 +13,5 @@ hooks.tap('initNativeApi', function (taro) {
13
13
  export * from './app'
14
14
  export * from './connect'
15
15
  export * from './hooks'
16
+ export * from './native-page'
16
17
  export * from './page'