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

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 (239) 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 +74 -21
  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 +27 -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 +17 -9
  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 +3 -8
  41. package/dist/apis/index.ts +27 -17
  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} +4 -3
  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 +158 -88
  93. package/dist/apis/ui/{animation.ts → animation/animation.ts} +73 -31
  94. package/dist/apis/ui/animation/index.ts +7 -0
  95. package/dist/apis/ui/background.ts +4 -19
  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 +45 -59
  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 +10 -4
  103. package/dist/apis/{page → ui/scroll}/index.ts +32 -27
  104. package/dist/apis/ui/sticky.ts +4 -0
  105. package/dist/apis/{tabbar/index.ts → ui/tab-bar.ts} +6 -8
  106. package/dist/apis/ui/window.ts +20 -0
  107. package/dist/apis/utils/handler.ts +4 -4
  108. package/dist/apis/utils/index.ts +1 -1
  109. package/dist/apis/worker/index.ts +4 -0
  110. package/dist/apis/wxml/IntersectionObserver.ts +24 -25
  111. package/dist/apis/wxml/index.ts +7 -2
  112. package/dist/apis/wxml/nodesRef.ts +2 -2
  113. package/dist/apis/wxml/selectorQuery.ts +29 -17
  114. package/dist/components-harmony-ets/button.ets +106 -80
  115. package/dist/components-harmony-ets/canvas.ets +51 -0
  116. package/dist/components-harmony-ets/checkbox.ets +82 -148
  117. package/dist/components-harmony-ets/form.ets +45 -132
  118. package/dist/components-harmony-ets/icon.ets +66 -69
  119. package/dist/components-harmony-ets/image.ets +26 -61
  120. package/dist/components-harmony-ets/index.ets +92 -0
  121. package/dist/components-harmony-ets/innerHtml.ets +7 -70
  122. package/dist/components-harmony-ets/input.ets +60 -146
  123. package/dist/components-harmony-ets/label.ets +86 -92
  124. package/dist/components-harmony-ets/listView.ets +26 -0
  125. package/dist/components-harmony-ets/movableArea.ets +124 -0
  126. package/dist/components-harmony-ets/movableView.ets +93 -0
  127. package/dist/components-harmony-ets/navigationBar.ets +65 -0
  128. package/dist/components-harmony-ets/pageMeta.ets +94 -0
  129. package/dist/components-harmony-ets/picker.ets +172 -198
  130. package/dist/components-harmony-ets/progress.ets +52 -0
  131. package/dist/components-harmony-ets/pseudo.ets +80 -0
  132. package/dist/components-harmony-ets/radio.ets +85 -155
  133. package/dist/components-harmony-ets/richText.ets +15 -87
  134. package/dist/components-harmony-ets/scrollList.ets +94 -0
  135. package/dist/components-harmony-ets/scrollView.ets +81 -149
  136. package/dist/components-harmony-ets/slider.ets +47 -94
  137. package/dist/components-harmony-ets/stickySection.ets +42 -0
  138. package/dist/components-harmony-ets/style.ets +396 -0
  139. package/dist/components-harmony-ets/swiper.ets +51 -151
  140. package/dist/components-harmony-ets/switch.ets +35 -76
  141. package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
  142. package/dist/components-harmony-ets/text.ets +131 -76
  143. package/dist/components-harmony-ets/textArea.ets +64 -140
  144. package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
  145. package/dist/components-harmony-ets/utils/DynamicCenter.ts +4 -13
  146. package/dist/components-harmony-ets/utils/constant/style.ets +9 -6
  147. package/dist/components-harmony-ets/utils/flexManager.ets +68 -85
  148. package/dist/components-harmony-ets/utils/helper.ets +18 -65
  149. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  150. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  151. package/dist/components-harmony-ets/utils/index.ts +55 -51
  152. package/dist/components-harmony-ets/utils/styles.ets +177 -65
  153. package/dist/components-harmony-ets/video.ets +70 -116
  154. package/dist/components-harmony-ets/view.ets +58 -64
  155. package/dist/components-harmony-ets/webView.ets +56 -0
  156. package/dist/index.d.ts +152 -0
  157. package/dist/index.js +230 -60
  158. package/dist/index.js.map +1 -1
  159. package/dist/runtime-ets/bom/document.ts +6 -4
  160. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
  161. package/dist/runtime-ets/bom/window.ts +9 -2
  162. package/dist/runtime-ets/current.ts +3 -0
  163. package/dist/runtime-ets/dom/bind.ts +96 -0
  164. package/dist/runtime-ets/dom/class-list.ts +4 -6
  165. package/dist/runtime-ets/dom/comment.ts +1 -2
  166. package/dist/runtime-ets/dom/cssNesting.ts +409 -0
  167. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +30 -20
  168. package/dist/runtime-ets/dom/dataSource.ts +64 -0
  169. package/dist/runtime-ets/dom/document.ts +36 -51
  170. package/dist/runtime-ets/dom/element/canvas.ts +136 -0
  171. package/dist/runtime-ets/dom/element/element.ts +439 -0
  172. package/dist/runtime-ets/dom/element/form.ts +403 -0
  173. package/dist/runtime-ets/dom/element/index.ts +120 -0
  174. package/dist/runtime-ets/dom/element/movableArea.ts +11 -0
  175. package/dist/runtime-ets/dom/element/movableView.ts +242 -0
  176. package/dist/runtime-ets/dom/element/normal.ts +103 -0
  177. package/dist/runtime-ets/dom/element/progress.ts +11 -0
  178. package/dist/runtime-ets/dom/element/scrollView.ts +15 -0
  179. package/dist/runtime-ets/dom/element/text.ts +10 -0
  180. package/dist/runtime-ets/dom/element/video.ts +50 -0
  181. package/dist/runtime-ets/dom/element/webView.ts +68 -0
  182. package/dist/runtime-ets/dom/event.ts +26 -5
  183. package/dist/runtime-ets/dom/eventTarget.ts +3 -3
  184. package/dist/runtime-ets/dom/node.ts +114 -49
  185. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +805 -0
  186. package/dist/runtime-ets/dom/stylesheet/index.ts +122 -429
  187. package/dist/runtime-ets/dom/stylesheet/type.ts +93 -17
  188. package/dist/runtime-ets/dom/stylesheet/util.ts +145 -17
  189. package/dist/runtime-ets/index.ts +2 -3
  190. package/dist/runtime-ets/interface/event.ts +3 -2
  191. package/dist/runtime-ets/utils/index.ts +87 -17
  192. package/dist/runtime-ets/utils/info.ts +21 -47
  193. package/dist/runtime-framework/react/app.ts +20 -28
  194. package/dist/runtime-framework/react/hooks.ts +3 -4
  195. package/dist/runtime-framework/react/index.ts +1 -2
  196. package/dist/runtime-framework/react/native-page.ts +421 -0
  197. package/dist/runtime-framework/react/page.ts +5 -17
  198. package/dist/runtime-framework/solid/app.ts +25 -45
  199. package/dist/runtime-framework/solid/connect.ts +21 -3
  200. package/dist/runtime-framework/solid/hooks.ts +17 -12
  201. package/dist/runtime-framework/solid/index.ts +6 -2
  202. package/dist/runtime-framework/solid/page.ts +84 -36
  203. package/dist/runtime-framework/solid/reconciler/props.ts +70 -25
  204. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  205. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  206. package/dist/runtime-framework/solid/utils/index.ts +0 -2
  207. package/dist/runtime-utils.d.ts +827 -0
  208. package/dist/runtime-utils.js +1633 -549
  209. package/dist/runtime-utils.js.map +1 -1
  210. package/dist/runtime.d.ts +1 -0
  211. package/dist/runtime.js +1633 -549
  212. package/dist/runtime.js.map +1 -1
  213. package/index.js +3 -1
  214. package/package.json +14 -15
  215. package/static/media/cancel.svg +1 -0
  216. package/static/media/circle.svg +1 -0
  217. package/static/media/clear.svg +1 -0
  218. package/static/media/download.svg +1 -0
  219. package/static/media/info.svg +1 -0
  220. package/static/media/info_circle.svg +1 -0
  221. package/static/media/search.svg +1 -0
  222. package/static/media/success.svg +1 -0
  223. package/static/media/success_no_circle.svg +1 -0
  224. package/static/media/taro_arrow_left.svg +1 -0
  225. package/static/media/taro_home.svg +1 -0
  226. package/static/media/waiting.svg +1 -0
  227. package/static/media/warn.svg +1 -0
  228. package/types/harmony.d.ts +4 -0
  229. package/types/index.d.ts +4 -0
  230. package/types/runtime.d.ts +7 -1
  231. package/LICENSE +0 -160
  232. package/dist/components-harmony-ets/base.ets +0 -63
  233. package/dist/components-harmony-ets/element.ets +0 -223
  234. package/dist/components-harmony-ets/utils/constant/icon.ts +0 -19
  235. package/dist/runtime-ets/dom/element.ts +0 -457
  236. package/dist/runtime-ets/dom/text.ts +0 -19
  237. package/dist/runtime-ets/utils/bind.ts +0 -35
  238. package/types/api.d.ts +0 -4
  239. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
@@ -2,7 +2,7 @@ import { AREA_CHANGE_EVENT_NAME, Current, getPageScrollerOrNode, setNodeEventCal
2
2
 
3
3
  import { NodesRef } from './nodesRef'
4
4
 
5
- import type Taro from '@tarojs/api'
5
+ import type Taro from '@tarojs/taro/types'
6
6
 
7
7
  interface ISelectorQueryQueue {
8
8
  component: any
@@ -112,7 +112,7 @@ function filter (fields, dom) {
112
112
  return res
113
113
  }
114
114
  if (context) {
115
- // TODO: 暂未实现获取 context
115
+ // TODO: 暂未实现获取 context
116
116
  // const typeName = dom.type
117
117
  // if (/^video/i.test(typeName)) {
118
118
  // return { context: dom }
@@ -135,8 +135,7 @@ function filter (fields, dom) {
135
135
  // if (dataset) res.dataset = Object.assign({}, dom.dataset)
136
136
 
137
137
  if (rect || size) {
138
- const id = dom?._nid
139
- const { areaInfo } = dom?._instance?.nodeInfoMap?.[id] || {}
138
+ const { areaInfo } = dom?._nodeInfo || {}
140
139
 
141
140
  if (areaInfo) {
142
141
  if (rect) {
@@ -153,7 +152,7 @@ function filter (fields, dom) {
153
152
  }
154
153
  }
155
154
  if (scrollOffset) {
156
- const scroller = dom._instance.scroller
155
+ const scroller = dom.scroller
157
156
 
158
157
  if (scroller) {
159
158
  const { xOffset, yOffset } = scroller.currentOffset()
@@ -180,37 +179,50 @@ function filter (fields, dom) {
180
179
 
181
180
  function querySelector (selector, selectAll) {
182
181
  if (typeof selector === 'string') {
183
- return parseHandler(selector, selectAll)
182
+ return selector.split(',').reduce((prev, current) => {
183
+ const item = current.trim()
184
+
185
+ return prev.concat(parseHandler(item, selectAll))
186
+ }, [])
184
187
  }
185
- return null
188
+ return []
186
189
  }
187
190
 
188
191
  function queryBat (queue, cb) {
189
192
  const result: any = []
190
193
  const taro = (Current as any).taro
191
194
  const page = taro.getCurrentInstance().page
192
- const element = getPageScrollerOrNode(page.node, page)
195
+ const element = getPageScrollerOrNode(page?.node, page)
193
196
 
194
- if (element == null) return null
197
+ if (!element) return null
195
198
 
196
199
  arr = []
197
200
  traversalDFSDom(element)
198
- queue.forEach(item => {
201
+ queue.forEach((item) => {
199
202
  const { selector, single, fields } = item
200
- const nodeList = querySelector(selector, !single)
201
203
 
202
- result.push(nodeList.map(dom => {
204
+ if (single) {
205
+ const dom = querySelector(selector, !single)[0]
203
206
  // eslint-disable-next-line no-async-promise-executor
204
- return new Promise(async resolve => {
207
+ result.push(new Promise(async resolve => {
205
208
  await setNodeEventCallbackAndTriggerComponentUpdate(dom, AREA_CHANGE_EVENT_NAME, null, true)
206
-
207
209
  resolve(filter(fields, dom))
208
- })
209
- }))
210
+ }))
211
+ } else {
212
+ const nodeList = querySelector(selector, !single)
213
+ result.push(nodeList.map(dom => {
214
+ // eslint-disable-next-line no-async-promise-executor
215
+ return new Promise(async resolve => {
216
+ await setNodeEventCallbackAndTriggerComponentUpdate(dom, AREA_CHANGE_EVENT_NAME, null, true)
217
+
218
+ resolve(filter(fields, dom))
219
+ })
220
+ }))
221
+ }
210
222
  })
211
223
 
212
224
  Promise.all(result.map(item => {
213
- return Promise.all(item)
225
+ return item instanceof Array ? Promise.all(item) : item
214
226
  })).then(data => {
215
227
  cb(data)
216
228
  })
@@ -1,56 +1,36 @@
1
- import { bindInstanceToNode, eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, initComponentNodeInfo } from '@tarojs/runtime'
2
- import { createNode } from './render'
3
- import TaroComponentWrapper from './base'
4
- import { createTaroEvent } from './utils/events'
1
+ import { eventHandler, createTaroEvent, convertNumber2VP, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME } from '@tarojs/runtime'
2
+ import commonStyleModify from './style'
5
3
  import { BUTTON_THEME_COLOR } from './utils/constant/style'
6
- import { AttributeManager } from './utils/AttributeManager'
7
4
  import { TOUCH_EVENT_MAP } from './utils/constant/event'
8
- import { getNormalAttributes, shouldBindEvent, getNodeThresholds, bindAnimation } from './utils/helper'
5
+ import { shouldBindEvent, getNodeThresholds } from './utils/helper'
9
6
 
10
- import type { TaroAny, TaroEvent } from '@tarojs/runtime'
11
- import type { TaroButtonElement, TaroElement } from './element'
12
- import type { TaroStyleType } from '@tarojs/runtime'
7
+ import type { TaroAny, TaroEvent, TaroButtonElement, TaroStyleType } from '@tarojs/runtime'
13
8
 
14
9
  @Extend(Button)
15
- function attrs (style: TaroStyleType) {
16
- .id(style.id)
17
- .key(style.id)
18
- .padding(style.padding)
19
- .margin(style.margin)
20
- .width(style.width)
21
- .height(style.height)
22
- .constraintSize(style.constraintSize)
23
- .flexGrow(style.flexGrow)
24
- .flexShrink(style.flexShrink)
25
- .flexBasis(style.flexBasis)
26
- .alignSelf(style.alignSelf)
27
- .backgroundColor(style.backgroundColor)
28
- .backgroundImage(style.backgroundImage, style.backgroundRepeat)
29
- .backgroundImageSize(style.backgroundImageSize)
30
- .rotate(style.rotate)
31
- .scale(style.scale)
32
- .translate(style.translate)
33
- .transform(style.transform)
34
- .borderStyle(style.borderStyle)
35
- .borderWidth(style.borderWidth)
10
+ function themeStyles(style: TaroStyleType) {
11
+ .fontColor(style.color)
12
+ .opacity(style.opacity)
36
13
  .borderColor(style.borderColor)
14
+ .borderWidth(style.borderWidth)
37
15
  .borderRadius(style.borderRadius)
38
- .linearGradient(style.linearGradient)
39
- .zIndex(style.zIndex)
40
- .opacity(style.opacity)
41
- .clip(style.clip)
16
+ .backgroundColor(style.backgroundColor)
42
17
  }
43
18
 
19
+ export function getButtonColor (node: TaroButtonElement, color: ResourceColor) {
20
+ const _attrs = node._attrs
21
+ const isDisabled: boolean = _attrs.disabled || false
22
+ const isPlain: boolean = _attrs.plain || false
23
+ const type: string = _attrs.type || 'default'
24
+
25
+ if (isDisabled && isPlain) {
26
+ return Color.Black
27
+ }
44
28
 
45
- @Extend(Button)
46
- function themeStyles(style: TaroStyleType) {
47
- .border({
48
- width: 1,
49
- color: style.backgroundColor
50
- })
51
- .fontColor(style.color)
52
- .opacity(style.opacity)
53
- .backgroundColor(style.backgroundColor)
29
+ if (isPlain) {
30
+ return BUTTON_THEME_COLOR.get(type).plainText
31
+ }
32
+
33
+ return color
54
34
  }
55
35
 
56
36
  function getThemeAttributes (node: TaroButtonElement): TaroStyleType {
@@ -61,59 +41,105 @@ function getThemeAttributes (node: TaroButtonElement): TaroStyleType {
61
41
  const type: string = _attrs.type || 'default'
62
42
 
63
43
  return {
64
- opacity: isDisabled ? 0.4 : 1,
44
+ borderColor: {
45
+ top: hmStyle.borderTopColor || getButtonColor(node, BUTTON_THEME_COLOR.get(type).background),
46
+ right: hmStyle.borderRightColor || getButtonColor(node, BUTTON_THEME_COLOR.get(type).background),
47
+ bottom: hmStyle.borderBottomColor || getButtonColor(node, BUTTON_THEME_COLOR.get(type).background),
48
+ left: hmStyle.borderLeftColor || getButtonColor(node, BUTTON_THEME_COLOR.get(type).background)
49
+ },
50
+ borderWidth: {
51
+ top: hmStyle.borderTopWidth || 1,
52
+ right: hmStyle.borderRightWidth || 1,
53
+ bottom: hmStyle.borderBottomWidth || 1,
54
+ left: hmStyle.borderLeftWidth || 1
55
+ },
56
+ borderRadius: {
57
+ topLeft: hmStyle.borderTopLeftRadius || convertNumber2VP(10),
58
+ topRight: hmStyle.borderTopRightRadius || convertNumber2VP(10),
59
+ bottomLeft: hmStyle.borderBottomLeftRadius || convertNumber2VP(10),
60
+ bottomRight: hmStyle.borderBottomRightRadius || convertNumber2VP(10)
61
+ },
62
+ opacity: isDisabled ? 0.4 : hmStyle.opacity,
65
63
  backgroundColor: isPlain ? Color.Transparent : (hmStyle.backgroundColor || BUTTON_THEME_COLOR.get(type).background),
66
- color: hmStyle.color || BUTTON_THEME_COLOR.get(type).text,
64
+ color: hmStyle.color || getButtonColor(node, BUTTON_THEME_COLOR.get(type).text),
67
65
  }
68
66
  }
69
67
 
70
- @Component
71
- export default struct TaroButton {
72
- nodeInfoMap: TaroAny = {}
68
+ function getButtonWidth (node: TaroButtonElement): string | number {
69
+ const isMini = node._attrs.size === 'mini'
73
70
 
74
- @ObjectLink node: TaroButtonElement
71
+ return isMini ? convertNumber2VP(120) : '100%'
72
+ }
75
73
 
76
- @Styles visibleChangeEvent () {
77
- .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
74
+ function getButtonHeight (node: TaroButtonElement): string | number {
75
+ const isMini = node._attrs.size === 'mini'
76
+
77
+ return isMini ? convertNumber2VP(60) : convertNumber2VP(92)
78
+ }
79
+
80
+ function getButtonMinWidth (node: TaroButtonElement): string | number | undefined {
81
+ if (node.hmStyle.width) {
82
+ return undefined
78
83
  }
79
84
 
80
- aboutToAppear () {
81
- initComponentNodeInfo(this, this.node)
82
- bindInstanceToNode(this.node, this)
83
- // 绑定动画
84
- bindAnimation(this.node)
85
+ return getButtonWidth(node)
86
+ }
87
+
88
+ function getButtonMinHeight (node: TaroButtonElement): string | number | undefined {
89
+ if (node.hmStyle.height) {
90
+ return undefined
91
+ }
92
+
93
+ return getButtonHeight(node)
94
+ }
95
+
96
+ @Component
97
+ export default struct TaroButton {
98
+ @Builder customBuilder() {}
99
+ @BuilderParam createLazyChildren: (node: TaroButtonElement) => void = this.customBuilder
100
+ @ObjectLink node: TaroButtonElement
101
+ @State overwriteStyle: Record<string, TaroAny> = {}
102
+
103
+ aboutToAppear(): void {
104
+ if (this.node) {
105
+ this.node._instance = this
106
+ }
85
107
  }
86
108
 
87
109
  build() {
88
- TaroComponentWrapper({ node: this.node }) {
89
- Button({ stateEffect: !this.node._attrs.disabled }) {
110
+ Button({ stateEffect: !this.node._attrs.disabled }) {
111
+ if (this.node._attrs.loading) {
90
112
  Row() {
91
- if (this.node._attrs.loading) {
92
- LoadingProgress()
113
+ LoadingProgress()
93
114
  .width(20).height(20)
94
115
  .color(getThemeAttributes(this.node).color)
95
- }
96
- ForEach(this.node.childNodes, (item: TaroElement) => {
97
- createNode(item)
98
- }, (item: TaroElement) => item._nid)
116
+ this.createLazyChildren(this.node)
99
117
  }
118
+ } else {
119
+ this.createLazyChildren(this.node)
100
120
  }
101
- .attrs(getNormalAttributes(this.node))
102
- .themeStyles(getThemeAttributes(this.node))
103
- .onClick((e: ClickEvent) => {
104
- if (['submit', 'reset'].includes(this.node._attrs.formType)) {
105
- const eventName = this.node._attrs.formType + '-btn'
106
- const event: TaroEvent = createTaroEvent(eventName, {}, this.node)
107
- eventHandler(event, eventName, this.node)
108
- }
109
- eventHandler(e, 'click', this.node)
110
- })
111
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
112
- .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, res => {
113
- const eventResult: TaroAny = res.eventResult
114
- this.nodeInfoMap[this.node._nid].areaInfo = eventResult[1]
115
- }))
116
- .visibleChangeEvent()
117
121
  }
122
+ .themeStyles(getThemeAttributes(this.node))
123
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
124
+ .constraintSize({
125
+ minWidth: this.node.hmStyle?.minWidth || getButtonMinWidth(this.node),
126
+ minHeight: this.node.hmStyle?.minHeight || getButtonMinHeight(this.node),
127
+ maxWidth: this.node.hmStyle?.maxWidth,
128
+ maxHeight: this.node.hmStyle?.maxHeight,
129
+ })
130
+ .type(ButtonType.Normal)
131
+ .onClick((e: ClickEvent) => {
132
+ if (this.node._attrs.formType && ['submit', 'reset'].includes(this.node._attrs.formType)) {
133
+ const eventName = this.node._attrs.formType + '-btn'
134
+ const event: TaroEvent = createTaroEvent(eventName, {}, this.node)
135
+ eventHandler(event, eventName, this.node)
136
+ }
137
+ eventHandler(e, 'click', this.node)
138
+ })
139
+ .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
140
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
141
+ this.node._nodeInfo.areaInfo = res[1]
142
+ }))
143
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
118
144
  }
119
145
  }
@@ -0,0 +1,51 @@
1
+ import type { TaroAny, TaroCanvasElement } from '@tarojs/runtime'
2
+ import { cancelAnimationFrame, requestAnimationFrame } from '@tarojs/runtime'
3
+ import commonStyleModify from './style'
4
+
5
+ @Component
6
+ export default struct TaroCanvas {
7
+ @ObjectLink node: TaroCanvasElement
8
+ rafId: number = 0
9
+ @State overwriteStyle: Record<string, TaroAny> = {}
10
+
11
+ aboutToAppear(): void {
12
+ if (this.node) {
13
+ this.node._instance = this
14
+ }
15
+ }
16
+
17
+ aboutToDisappear() {
18
+ if(this.rafId) {
19
+ cancelAnimationFrame(this.rafId)
20
+ }
21
+ }
22
+
23
+ build() {
24
+ Canvas(this.node._context)
25
+ .attributeModifier(commonStyleModify.setNode(this.node as TaroAny, {
26
+ width: '100%',
27
+ height: '100%',
28
+ backgroundColor: '#ffff00'
29
+ }).setAnimationStyle(this.overwriteStyle))
30
+ .onReady(() => {
31
+ const context = this.node._context
32
+
33
+ const draw = () => {
34
+ if (this.node._drawList.length) {
35
+ while (this.node._drawList.length) {
36
+ const item = this.node._drawList.shift()
37
+ if (item) {
38
+ if (typeof context[item.key] === 'function') {
39
+ context[item.key](...[].concat(item.value))
40
+ } else {
41
+ context[item.key] = item.value
42
+ }
43
+ }
44
+ }
45
+ }
46
+ this.rafId = requestAnimationFrame(draw)
47
+ }
48
+ draw()
49
+ })
50
+ }
51
+ }
@@ -1,13 +1,11 @@
1
- import { bindInstanceToNode, eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME, initComponentNodeInfo, TaroAny, TaroEvent } from '@tarojs/runtime'
1
+ import { createTaroEvent, eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME } from '@tarojs/runtime'
2
2
 
3
- import TaroComponentWrapper from './base'
4
- import { createNode } from './render'
5
- import { createTaroEvent } from './utils/events'
6
- import { FlexManager } from './utils/FlexManager'
7
- import { shouldBindEvent, getNormalAttributes, getNodeThresholds } from './utils/helper'
3
+ import commonStyleModify, { rowModify, columnModify } from './style'
4
+ import { FlexManager } from './utils/flexManager'
5
+ import { shouldBindEvent, getNodeThresholds } from './utils/helper'
8
6
 
9
- import type { TaroCheckboxElement, TaroCheckboxGroupElement, TaroElement } from './element'
10
- import type { TaroStyleType } from '@tarojs/runtime'
7
+ import type { TaroAny, TaroEvent, TaroCheckboxElement, TaroCheckboxGroupElement } from '@tarojs/runtime'
8
+ import { isUndefined } from '@tarojs/shared'
11
9
 
12
10
  interface CheckboxOptions {
13
11
  name?: string
@@ -17,36 +15,6 @@ interface CheckboxAttrs {
17
15
  selectedColor?: ResourceColor
18
16
  }
19
17
 
20
- @Extend(Checkbox)
21
- function checkboxStyle (style: TaroStyleType) {
22
- .id(style.id)
23
- .key(style.id)
24
- .padding(style.padding)
25
- .margin(style.margin)
26
- .width(style.width)
27
- .height(style.height)
28
- .constraintSize(style.constraintSize)
29
- .flexGrow(style.flexGrow)
30
- .flexShrink(style.flexShrink)
31
- .flexBasis(style.flexBasis)
32
- .alignSelf(style.alignSelf)
33
- .backgroundColor(style.backgroundColor)
34
- .backgroundImage(style.backgroundImage, style.backgroundRepeat)
35
- .backgroundImageSize(style.backgroundImageSize)
36
- .rotate(style.rotate)
37
- .scale(style.scale)
38
- .translate(style.translate)
39
- .transform(style.transform)
40
- .borderStyle(style.borderStyle)
41
- .borderWidth(style.borderWidth)
42
- .borderColor(style.borderColor)
43
- .borderRadius(style.borderRadius)
44
- .linearGradient(style.linearGradient)
45
- .zIndex(style.zIndex)
46
- .opacity(style.opacity)
47
- .clip(style.clip)
48
- }
49
-
50
18
  @Extend(Checkbox)
51
19
  function checkboxAttr(attr: CheckboxAttrs) {
52
20
  .selectedColor(attr.selectedColor)
@@ -60,158 +28,124 @@ function getAttributes (node: TaroCheckboxElement): CheckboxAttrs {
60
28
  }
61
29
 
62
30
  function getOptions (node: TaroCheckboxElement): CheckboxOptions {
63
- const value: string = node._attrs.value
64
31
  return {
65
- name: value || node.textContent
32
+ name: node.value as string || node.textContent
66
33
  }
67
34
  }
68
35
 
69
36
 
70
37
  @Component
71
38
  export struct TaroCheckbox {
72
- nodeInfoMap: TaroAny = {}
73
-
39
+ @Builder customBuilder() {}
40
+ @BuilderParam createLazyChildren: (node: TaroCheckboxElement) => void = this.customBuilder
74
41
  @ObjectLink node: TaroCheckboxElement
75
-
76
- @State checked: boolean = false
77
-
78
- @Styles visibleChangeEvent () {
79
- .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
80
- }
42
+ @State overwriteStyle: Record<string, TaroAny> = {}
81
43
 
82
44
  aboutToAppear () {
83
- initComponentNodeInfo(this, this.node)
84
- bindInstanceToNode(this.node, this)
85
-
86
- this.checked = !!this.node._attrs.checked
87
- }
88
-
89
- @Styles defaultEvent () {
90
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
91
- .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, res => {
92
- const eventResult: TaroAny = res.eventResult
93
- this.nodeInfoMap[this.node._nid].areaInfo = eventResult[1]
94
- }))
45
+ if (this.node && !this.node._isInit) {
46
+ this.node._isInit = true
47
+ this.node._instance = this
48
+ this.node._reset = this.node.checked || false
49
+ }
95
50
  }
96
51
 
97
- build() {
98
- TaroComponentWrapper({ node: this.node }) {
99
- Stack() {
100
- Row() {
101
- Checkbox(getOptions(this.node))
102
- .defaultEvent()
103
- .checkboxStyle(getNormalAttributes(this.node))
104
- .checkboxAttr(getAttributes(this.node))
105
- .opacity(!!this.node._attrs.disabled ? 0.4 : 1)
106
- .select(this.checked)
107
- .onChange((value: boolean) => {
108
- if (!!this.node._attrs.disabled) {
109
- // FIXME 找下文档是否有强制刷新方法
110
- this.checked = !this.checked
111
- this.checked = !this.checked
52
+ build () {
53
+ Stack() {
54
+ Row() {
55
+ Checkbox(getOptions(this.node))
56
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
57
+ .checkboxAttr(getAttributes(this.node))
58
+ .opacity(!!this.node._attrs.disabled ? 0.4 : 1)
59
+ .select(this.node.checked)
60
+ .onChange((value: boolean) => {
61
+ if (this.node) {
62
+ if (!!this.node?._attrs.disabled) {
63
+ this.node.updateComponent()
112
64
  } else {
113
- this.checked = value
114
- if (this.checked) {
115
- const event: TaroEvent = createTaroEvent('change', { detail: { value: this.node._attrs.value } }, this.node)
65
+ this.node.updateCheckedValue(value)
66
+
67
+ if (value) {
68
+ const event: TaroEvent = createTaroEvent('change', { detail: { value: this.node?._attrs.value } }, this.node)
116
69
  eventHandler(event, 'change', this.node)
117
70
  }
118
71
  }
119
- })
120
- .visibleChangeEvent()
121
- Text(this.node.textContent)
122
- .textAlign(TextAlign.Center)
123
- .opacity(!!this.node._attrs.disabled ? 0.4 : 1)
124
- }
125
- .onClick(() => {
126
- this.checked = !this.checked
127
- })
72
+ }
73
+ })
74
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
75
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
76
+ if (this.node) {
77
+ this.node._nodeInfo.areaInfo = res[1]
78
+ }
79
+ }))
80
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
81
+ Text(this.node.textContent)
82
+ .textAlign(TextAlign.Center)
83
+ .opacity(!!this.node._attrs.disabled ? 0.4 : 1)
128
84
  }
85
+ .onClick(() => {
86
+ if (this.node) {
87
+ if (!this.node?._attrs.disabled) {
88
+ this.node.checked = !this.node.checked
89
+ }
90
+ }
91
+ })
129
92
  }
130
93
  }
131
94
  }
132
95
 
133
-
134
- @Extend(Flex)
135
- function checkboxGroupAttrs (style: TaroStyleType) {
136
- .id(style.id)
137
- .key(style.id)
138
- .padding(style.padding)
139
- .margin(style.margin)
140
- .width(style.width)
141
- .height(style.height)
142
- .constraintSize(style.constraintSize)
143
- .flexGrow(style.flexGrow)
144
- .flexShrink(style.flexShrink)
145
- .flexBasis(style.flexBasis)
146
- .alignSelf(style.alignSelf)
147
- .backgroundColor(style.backgroundColor)
148
- .backgroundImage(style.backgroundImage, style.backgroundRepeat)
149
- .backgroundImageSize(style.backgroundImageSize)
150
- .rotate(style.rotate)
151
- .scale(style.scale)
152
- .translate(style.translate)
153
- .transform(style.transform)
154
- .borderStyle(style.borderStyle)
155
- .borderWidth(style.borderWidth)
156
- .borderColor(style.borderColor)
157
- .borderRadius(style.borderRadius)
158
- .linearGradient(style.linearGradient)
159
- .zIndex(style.zIndex)
160
- .opacity(style.opacity)
161
- .clip(style.clip)
162
- }
163
-
164
96
  interface ChangeEventDetail { value: string[] }
165
97
 
166
98
  @Component
167
99
  export struct TaroCheckboxGroup {
168
- nodeInfoMap: TaroAny = {}
169
-
100
+ @Builder customBuilder() {}
101
+ @BuilderParam createLazyChildren: (node: TaroCheckboxGroupElement) => void = this.customBuilder
170
102
  @ObjectLink node: TaroCheckboxGroupElement
103
+ @State overwriteStyle: Record<string, TaroAny> = {}
171
104
 
172
105
  @Styles visibleChangeEvent () {
173
106
  .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
174
107
  }
175
108
 
176
109
  aboutToAppear () {
177
- initComponentNodeInfo(this, this.node)
178
- bindInstanceToNode(this.node, this)
179
-
180
- // 阻止事件冒泡传递上去
181
- this.node.addEventListener('change', (e: TaroEvent<ChangeEventDetail>) => {
182
- e.stopPropagation()
183
- e.detail.value = this.getValues()
184
- })
185
- }
186
-
187
- // Element使用的获取值方法
188
- getValues () {
189
- const childList = this.node.getElementsByTagName<TaroCheckboxElement>('CHECKBOX')
190
- const result: string[] = []
191
- childList.forEach(element => {
192
- if (element._instance.checked) {
193
- result.push(element._attrs.value)
194
- }
195
- })
196
- return result
110
+ if (this.node) {
111
+ this.node._instance = this
112
+ // 阻止事件冒泡传递上去
113
+ this.node.addEventListener('change', (e: TaroEvent<ChangeEventDetail>) => {
114
+ e.stopPropagation()
115
+ e.detail.value = (this.node as TaroCheckboxGroupElement).value
116
+ })
117
+ }
197
118
  }
198
119
 
199
120
  @Styles defaultEvent () {
200
121
  .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
201
- .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, res => {
202
- const eventResult: TaroAny = res.eventResult
203
- this.nodeInfoMap[this.node._nid].areaInfo = eventResult[1]
122
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
123
+ if (this.node) {
124
+ this.node._nodeInfo.areaInfo = res[1]
125
+ }
204
126
  }))
205
127
  }
206
128
 
207
129
  build() {
208
- TaroComponentWrapper({ node: this.node }) {
130
+ if (FlexManager.useFlexLayout(this.node)) {
209
131
  Flex(FlexManager.flexOptions(this.node)) {
210
- ForEach(this.node.childNodes, (item: TaroElement) => {
211
- createNode(item)
212
- }, (item: TaroElement) => item._nid)
132
+ this.createLazyChildren(this.node)
133
+ }
134
+ .attributeModifier(commonStyleModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
135
+ .defaultEvent()
136
+ .visibleChangeEvent()
137
+ } else if (FlexManager.isFlexNode(this.node) && FlexManager.direction(this.node) !== FlexDirection.Column) {
138
+ Row() {
139
+ this.createLazyChildren(this.node)
140
+ }
141
+ .attributeModifier(rowModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
142
+ .defaultEvent()
143
+ .visibleChangeEvent()
144
+ } else {
145
+ Column() {
146
+ this.createLazyChildren(this.node)
213
147
  }
214
- .checkboxGroupAttrs(getNormalAttributes(this.node))
148
+ .attributeModifier(columnModify.setNode(this.node).setAnimationStyle(this.overwriteStyle))
215
149
  .defaultEvent()
216
150
  .visibleChangeEvent()
217
151
  }