@tarojs/plugin-platform-harmony-ets 4.0.0-beta.5 → 4.0.0-beta.50

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 (122) hide show
  1. package/dist/apis/base/system.ts +53 -20
  2. package/dist/apis/canvas/index.ts +10 -1
  3. package/dist/apis/device/clipboard.ts +4 -0
  4. package/dist/apis/framework/index.ts +1 -5
  5. package/dist/apis/index.ts +27 -17
  6. package/dist/apis/network/request.ts +5 -5
  7. package/dist/apis/route/index.ts +15 -0
  8. package/dist/apis/storage/index.ts +148 -80
  9. package/dist/apis/ui/animation/animation.ts +71 -28
  10. package/dist/apis/ui/background.ts +2 -1
  11. package/dist/apis/ui/interaction/index.ts +40 -49
  12. package/dist/apis/ui/navigation-bar/index.ts +1 -1
  13. package/dist/apis/utils/index.ts +1 -1
  14. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  15. package/dist/apis/wxml/index.ts +2 -0
  16. package/dist/apis/wxml/selectorQuery.ts +18 -9
  17. package/dist/components-harmony-ets/button.ets +48 -34
  18. package/dist/components-harmony-ets/canvas.ets +51 -0
  19. package/dist/components-harmony-ets/checkbox.ets +69 -61
  20. package/dist/components-harmony-ets/form.ets +51 -29
  21. package/dist/components-harmony-ets/icon.ets +31 -19
  22. package/dist/components-harmony-ets/image.ets +27 -14
  23. package/dist/components-harmony-ets/index.ets +85 -0
  24. package/dist/components-harmony-ets/innerHtml.ets +11 -6
  25. package/dist/components-harmony-ets/input.ets +41 -40
  26. package/dist/components-harmony-ets/label.ets +69 -42
  27. package/dist/components-harmony-ets/movableArea.ets +126 -0
  28. package/dist/components-harmony-ets/movableView.ets +73 -0
  29. package/dist/components-harmony-ets/navigationBar.ets +25 -0
  30. package/dist/components-harmony-ets/pageMeta.ets +28 -0
  31. package/dist/components-harmony-ets/picker.ets +42 -38
  32. package/dist/components-harmony-ets/progress.ets +52 -0
  33. package/dist/components-harmony-ets/pseudo.ets +80 -0
  34. package/dist/components-harmony-ets/radio.ets +71 -64
  35. package/dist/components-harmony-ets/richText.ets +14 -30
  36. package/dist/components-harmony-ets/scrollView.ets +61 -57
  37. package/dist/components-harmony-ets/slider.ets +15 -14
  38. package/dist/components-harmony-ets/style.ets +390 -130
  39. package/dist/components-harmony-ets/swiper.ets +38 -20
  40. package/dist/components-harmony-ets/switch.ets +30 -28
  41. package/dist/components-harmony-ets/{index.ts → tag.ts} +2 -0
  42. package/dist/components-harmony-ets/text.ets +121 -51
  43. package/dist/components-harmony-ets/textArea.ets +35 -34
  44. package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
  45. package/dist/components-harmony-ets/utils/DynamicCenter.ts +1 -1
  46. package/dist/components-harmony-ets/utils/flexManager.ets +47 -19
  47. package/dist/components-harmony-ets/utils/helper.ets +17 -5
  48. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  49. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  50. package/dist/components-harmony-ets/utils/index.ts +50 -51
  51. package/dist/components-harmony-ets/utils/styles.ets +170 -93
  52. package/dist/components-harmony-ets/video.ets +34 -20
  53. package/dist/components-harmony-ets/view.ets +63 -52
  54. package/dist/components-harmony-ets/webView.ets +40 -34
  55. package/dist/index.d.ts +152 -0
  56. package/dist/index.js +82 -39
  57. package/dist/index.js.map +1 -1
  58. package/dist/runtime-ets/bom/document.ts +6 -4
  59. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
  60. package/dist/runtime-ets/bom/window.ts +7 -0
  61. package/dist/runtime-ets/current.ts +3 -0
  62. package/dist/runtime-ets/dom/bind.ts +31 -13
  63. package/dist/runtime-ets/dom/cssNesting.ts +393 -0
  64. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +25 -39
  65. package/dist/runtime-ets/dom/document.ts +22 -8
  66. package/dist/runtime-ets/dom/element/canvas.ts +136 -0
  67. package/dist/runtime-ets/dom/element/element.ts +317 -51
  68. package/dist/runtime-ets/dom/element/form.ts +23 -26
  69. package/dist/runtime-ets/dom/element/index.ts +24 -2
  70. package/dist/runtime-ets/dom/element/movableArea.ts +12 -0
  71. package/dist/runtime-ets/dom/element/movableView.ts +193 -0
  72. package/dist/runtime-ets/dom/element/normal.ts +35 -8
  73. package/dist/runtime-ets/dom/element/progress.ts +12 -0
  74. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  75. package/dist/runtime-ets/dom/element/text.ts +1 -8
  76. package/dist/runtime-ets/dom/element/video.ts +5 -3
  77. package/dist/runtime-ets/dom/element/webView.ts +11 -3
  78. package/dist/runtime-ets/dom/event.ts +0 -1
  79. package/dist/runtime-ets/dom/eventTarget.ts +0 -3
  80. package/dist/runtime-ets/dom/node.ts +46 -28
  81. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +334 -230
  82. package/dist/runtime-ets/dom/stylesheet/index.ts +28 -308
  83. package/dist/runtime-ets/dom/stylesheet/type.ts +40 -9
  84. package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
  85. package/dist/runtime-ets/index.ts +2 -2
  86. package/dist/runtime-ets/interface/event.ts +1 -1
  87. package/dist/runtime-ets/utils/index.ts +66 -11
  88. package/dist/runtime-ets/utils/info.ts +1 -1
  89. package/dist/runtime-framework/react/app.ts +7 -2
  90. package/dist/runtime-framework/react/index.ts +0 -2
  91. package/dist/runtime-framework/react/native-page.ts +32 -14
  92. package/dist/runtime-framework/react/page.ts +3 -8
  93. package/dist/runtime-framework/solid/app.ts +25 -45
  94. package/dist/runtime-framework/solid/connect.ts +21 -3
  95. package/dist/runtime-framework/solid/hooks.ts +16 -11
  96. package/dist/runtime-framework/solid/index.ts +6 -2
  97. package/dist/runtime-framework/solid/page.ts +84 -30
  98. package/dist/runtime-framework/solid/reconciler/props.ts +65 -20
  99. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  100. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  101. package/dist/runtime-framework/solid/utils/index.ts +0 -2
  102. package/dist/runtime-utils.d.ts +827 -0
  103. package/dist/runtime-utils.js +399 -188
  104. package/dist/runtime-utils.js.map +1 -1
  105. package/dist/runtime.d.ts +1 -0
  106. package/dist/runtime.js +399 -188
  107. package/dist/runtime.js.map +1 -1
  108. package/index.js +3 -1
  109. package/package.json +13 -13
  110. package/static/media/cancel.svg +1 -1
  111. package/static/media/circle.svg +1 -1
  112. package/static/media/clear.svg +1 -1
  113. package/static/media/download.svg +1 -1
  114. package/static/media/info.svg +1 -1
  115. package/static/media/info_circle.svg +1 -1
  116. package/static/media/search.svg +1 -1
  117. package/static/media/success.svg +1 -1
  118. package/static/media/success_no_circle.svg +1 -1
  119. package/static/media/warn.svg +1 -1
  120. package/types/harmony.d.ts +4 -0
  121. package/types/index.d.ts +4 -0
  122. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
@@ -1,4 +1,5 @@
1
1
  import matrix4 from '@ohos.matrix4'
2
+ import { isUndefined } from '@tarojs/shared'
2
3
 
3
4
  import { temporarilyNotSupport } from '../../utils'
4
5
 
@@ -71,6 +72,9 @@ export class Animation implements Taro.Animation {
71
72
  transformOrigin,
72
73
  rule: Object.assign({}, this.rule)
73
74
  })
75
+ if (this.rule.transform) {
76
+ this.rule.transform = Object.assign({}, this.rule.transform)
77
+ }
74
78
  return this
75
79
  }
76
80
 
@@ -85,92 +89,137 @@ export class Animation implements Taro.Animation {
85
89
  }
86
90
 
87
91
  rotate (angle: number): Taro.Animation {
88
- this.rule.rotate = { x: 0, y: 0, z: 1, angle }
92
+ if (!this.rule.transform) {
93
+ this.rule.transform = {}
94
+ }
95
+ this.rule.transform.Rotate = { x: 0, y: 0, z: 1, angle }
89
96
  return this
90
97
  }
91
98
 
92
99
  rotate3d (x: number, y?: number | undefined, z?: number | undefined, angle?: number | undefined): Taro.Animation {
93
- this.rule.rotate = { x, y, z, angle }
100
+ if (!this.rule.transform) {
101
+ this.rule.transform = {}
102
+ }
103
+ this.rule.transform.Rotate = { x, y, z, angle }
94
104
  return this
95
105
  }
96
106
 
97
107
  rotateX (angle: number): Taro.Animation {
98
- this.rule.rotate = { x: 1, y: 0, z: 0, angle }
108
+ if (!this.rule.transform) {
109
+ this.rule.transform = {}
110
+ }
111
+ this.rule.transform.Rotate = { x: 1, y: 0, z: 0, angle }
99
112
  return this
100
113
  }
101
114
 
102
115
  rotateY (angle: number): Taro.Animation {
103
- this.rule.rotate = { x: 0, y: 1, z: 0, angle }
116
+ if (!this.rule.transform) {
117
+ this.rule.transform = {}
118
+ }
119
+ this.rule.transform.Rotate = { x: 0, y: 1, z: 0, angle }
104
120
  return this
105
121
  }
106
122
 
107
123
  rotateZ (angle: number): Taro.Animation {
108
- this.rule.rotate = { x: 0, y: 0, z: 1, angle }
124
+ if (!this.rule.transform) {
125
+ this.rule.transform = {}
126
+ }
127
+ this.rule.transform.Rotate = { x: 0, y: 0, z: 1, angle }
109
128
  return this
110
129
  }
111
130
 
112
131
  scale (sx: number, sy?: number | undefined): Taro.Animation {
113
- this.rule.scale = { x: sx, y: sy }
132
+ if (!this.rule.transform) {
133
+ this.rule.transform = {}
134
+ }
135
+ this.rule.transform.Scale = { x: sx, y: isUndefined(sy) ? sx : sy }
114
136
  return this
115
137
  }
116
138
 
117
139
  scale3d (sx: number, sy: number, sz: number): Taro.Animation {
118
- this.rule.scale = { x: sx, y: sy, z: sz }
140
+ if (!this.rule.transform) {
141
+ this.rule.transform = {}
142
+ }
143
+ this.rule.transform.Scale = { x: sx, y: sy, z: sz }
119
144
  return this
120
145
  }
121
146
 
122
147
  scaleX (scale: number): Taro.Animation {
123
- this.rule.scale = { x: scale }
148
+ if (!this.rule.transform) {
149
+ this.rule.transform = {}
150
+ }
151
+ this.rule.transform.Scale = { x: scale }
124
152
  return this
125
153
  }
126
154
 
127
155
  scaleY (scale: number): Taro.Animation {
128
- this.rule.scale = { y: scale }
156
+ if (!this.rule.transform) {
157
+ this.rule.transform = {}
158
+ }
159
+ this.rule.transform.Scale = { y: scale }
129
160
  return this
130
161
  }
131
162
 
132
163
  scaleZ (scale: number): Taro.Animation {
133
- this.rule.scale = { z: scale }
164
+ if (!this.rule.transform) {
165
+ this.rule.transform = {}
166
+ }
167
+ this.rule.transform.Scale = { z: scale }
134
168
  return this
135
169
  }
136
170
 
137
171
  skew (ax: number, ay: number): Taro.Animation {
138
- this.rule.skew = { x: ax, y: ay }
172
+ temporarilyNotSupport('animation.skew:' + `${ax}, ${ay}`)(ax, ay)
139
173
  return this
140
174
  }
141
175
 
142
176
  skewX (angle: number): Taro.Animation {
143
- this.rule.skew = { x: angle }
177
+ temporarilyNotSupport('animation.skewX:' + angle)(angle)
144
178
  return this
145
179
  }
146
180
 
147
181
  skewY (angle: number): Taro.Animation {
148
- this.rule.skew = { y: angle }
182
+ temporarilyNotSupport('animation.skewY:' + angle)(angle)
149
183
  return this
150
184
  }
151
185
 
152
186
  translate (tx?: number | undefined, ty?: number | undefined): Taro.Animation {
153
- this.rule.translate = { x: tx, y: ty }
187
+ if (!this.rule.transform) {
188
+ this.rule.transform = {}
189
+ }
190
+ this.rule.transform.Translate = { x: tx, y: ty }
154
191
  return this
155
192
  }
156
193
 
157
194
  translate3d (tx?: number | undefined, ty?: number | undefined, tz?: number | undefined): Taro.Animation {
158
- this.rule.translate = { x: tx, y: ty, z: tz }
195
+ if (!this.rule.transform) {
196
+ this.rule.transform = {}
197
+ }
198
+ this.rule.transform.Translate = { x: tx, y: ty, z: tz }
159
199
  return this
160
200
  }
161
201
 
162
202
  translateX (translation: number): Taro.Animation {
163
- this.rule.translate = { x: translation }
203
+ if (!this.rule.transform) {
204
+ this.rule.transform = {}
205
+ }
206
+ this.rule.transform.Translate = { x: translation }
164
207
  return this
165
208
  }
166
209
 
167
210
  translateY (translation: number): Taro.Animation {
168
- this.rule.translate = { y: translation }
211
+ if (!this.rule.transform) {
212
+ this.rule.transform = {}
213
+ }
214
+ this.rule.transform.Translate = { y: translation }
169
215
  return this
170
216
  }
171
217
 
172
218
  translateZ (translation: number): Taro.Animation {
173
- this.rule.translate = { z: translation }
219
+ if (!this.rule.transform) {
220
+ this.rule.transform = {}
221
+ }
222
+ this.rule.transform.Translate = { z: translation }
174
223
  return this
175
224
  }
176
225
 
@@ -185,23 +234,17 @@ export class Animation implements Taro.Animation {
185
234
  }
186
235
 
187
236
  width (value: string | number): Taro.Animation {
188
- this.rule.size = {
189
- ...this.rule.size,
190
- width: value
191
- }
237
+ this.rule.width = value
192
238
  return this
193
239
  }
194
240
 
195
241
  height (value: string | number): Taro.Animation {
196
- this.rule.size = {
197
- ...this.rule.size,
198
- height: value
199
- }
242
+ this.rule.height = value
200
243
  return this
201
244
  }
202
245
 
203
246
  left (value: string | number): Taro.Animation {
204
- temporarilyNotSupport('animation.left:' + value)(value)
247
+ this.rule.left = value
205
248
  return this
206
249
  }
207
250
 
@@ -211,7 +254,7 @@ export class Animation implements Taro.Animation {
211
254
  }
212
255
 
213
256
  top (value: string | number): Taro.Animation {
214
- temporarilyNotSupport('animation.top:' + value)(value)
257
+ this.rule.top = value
215
258
  return this
216
259
  }
217
260
 
@@ -11,7 +11,8 @@ export function setBackgroundColor(options: Taro.setBackgroundColor.Option) {
11
11
 
12
12
  return new Promise((resolve, reject) => {
13
13
  eventCenter.trigger('__taroPageStyle', {
14
- backgroundColor: options.backgroundColor || options.backgroundColorTop || options.backgroundColorBottom,
14
+ backgroundColor: options.backgroundColorBottom || options.backgroundColor,
15
+ backgroundColorContext: options.backgroundColorTop || options.backgroundColor
15
16
  })
16
17
 
17
18
  return handle.success({}, { resolve, reject })
@@ -1,4 +1,4 @@
1
- import prompt from '@ohos.prompt'
1
+ import promptAction from '@ohos.promptAction'
2
2
 
3
3
  import { callAsyncFail, callAsyncSuccess, temporarilyNotSupport, validateParams } from '../../utils'
4
4
 
@@ -29,7 +29,7 @@ export function showToast (options) {
29
29
  return callAsyncFail(reject, res, options)
30
30
  }
31
31
 
32
- prompt.showToast({
32
+ promptAction.showToast({
33
33
  message: options.title,
34
34
  duration: options.duration,
35
35
  bottom: options.bottom
@@ -72,37 +72,20 @@ export function showModal (options) {
72
72
  })
73
73
  }
74
74
 
75
- return new Promise(resolve => {
75
+ return new Promise((resolve, reject) => {
76
76
  const modalOptions = {
77
77
  title,
78
78
  message: content,
79
79
  buttons: buttons,
80
- success: (data) => {
81
- if (data.index === 1 || !showCancel) {
82
- callAsyncSuccess(
83
- resolve,
84
- {
85
- ...resCallback('showModal'),
86
- confirm: true,
87
- cancel: false,
88
- content: null
89
- },
90
- options
91
- )
92
- } else {
93
- callAsyncSuccess(
94
- resolve,
95
- {
96
- ...resCallback('showModal'),
97
- confirm: false,
98
- cancel: true
99
- },
100
- options
101
- )
102
- }
103
- },
104
- // 鸿蒙没有失败方法,只有取消
105
- cancel: (_) => {
80
+ }
81
+
82
+ promptAction.showDialog(modalOptions, (error, data) => {
83
+ if (error) {
84
+ const res = { errMsg: error }
85
+ callAsyncFail(reject, res, options)
86
+ }
87
+
88
+ if (data.index === 0 && showCancel) {
106
89
  callAsyncSuccess(
107
90
  resolve,
108
91
  {
@@ -112,10 +95,19 @@ export function showModal (options) {
112
95
  },
113
96
  options
114
97
  )
98
+ } else {
99
+ callAsyncSuccess(
100
+ resolve,
101
+ {
102
+ ...resCallback('showModal'),
103
+ confirm: true,
104
+ cancel: false,
105
+ content: null
106
+ },
107
+ options
108
+ )
115
109
  }
116
- }
117
-
118
- prompt.showDialog(modalOptions)
110
+ })
119
111
  })
120
112
  }
121
113
 
@@ -152,37 +144,36 @@ export function showActionSheet (options) {
152
144
 
153
145
  const actionSheetOptions = {
154
146
  title,
155
- buttons,
156
- success: (data) => {
157
- callAsyncSuccess(
158
- resolve,
159
- {
160
- ...data,
161
- ...resCallback('showActionSheet')
162
- },
163
- options
164
- )
165
- },
166
- // 取消方法,并非失败
167
- fail: (data) => {
147
+ buttons
148
+ }
149
+
150
+ promptAction.showActionMenu(actionSheetOptions, (error, data) => {
151
+ if (error) {
168
152
  callAsyncFail(
169
153
  reject,
170
154
  {
171
155
  ...data,
172
- errMsg: data.errMsg.replace('showActionMenu', 'showActionSheet')
156
+ errMsg: data.errMsg?.replace('showActionMenu', 'showActionSheet')
173
157
  },
174
158
  options
175
159
  )
176
160
  }
177
- }
178
161
 
179
- prompt.showActionMenu(actionSheetOptions)
162
+ callAsyncSuccess(
163
+ resolve,
164
+ {
165
+ ...data,
166
+ ...resCallback('showActionSheet')
167
+ },
168
+ options
169
+ )
170
+ })
180
171
  })
181
172
  }
182
173
 
183
174
  export function hideToast (options) {
184
175
  return new Promise(resolve => {
185
- prompt.showToast({
176
+ promptAction.showToast({
186
177
  message: '关闭中',
187
178
  duration: 10,
188
179
  bottom: '9999px'
@@ -19,7 +19,7 @@ export const setNavigationBarTitle: typeof Taro.setNavigationBarTitle = function
19
19
 
20
20
  export const setNavigationBarColor: typeof Taro.setNavigationBarColor = function (options) {
21
21
  const { success, fail, complete } = options || {}
22
- const handle = new MethodHandler({ name: 'setNavigationBarTitle', success, fail, complete })
22
+ const handle = new MethodHandler({ name: 'setNavigationBarColor', success, fail, complete })
23
23
 
24
24
  return new Promise((resolve, reject) => {
25
25
  eventCenter.trigger('__taroNavigationStyle', {
@@ -19,7 +19,7 @@ export function temporarilyNotSupport (name: string, recommended?: string) {
19
19
  return (option = {}, ...args) => {
20
20
  const { success, fail, complete } = option as any
21
21
  const handle = new MethodHandler({ name, success, fail, complete })
22
- let errMsg = '暂时不支持 API'
22
+ let errMsg = `暂时不支持 API ${name}`
23
23
  if (recommended) {
24
24
  errMsg += `, 请使用 ${recommended}`
25
25
  }
@@ -19,31 +19,33 @@ export class IntersectionObserver implements Taro.IntersectionObserver {
19
19
  constructor(component: any, options: Taro.createIntersectionObserver.Option = {}) {
20
20
  const taro = (Current as any).taro
21
21
  const page = taro.getCurrentInstance().page
22
- const currentPage = getPageScrollerOrNode(page.node, page)
23
- this._component = component || currentPage
22
+
23
+ this._component = component || getPageScrollerOrNode(page?.node, page)
24
24
  Object.assign(this._options, options)
25
25
  }
26
26
 
27
27
  public disconnect (): void {
28
- if (this._observerNodes) {
28
+ if (this._observerNodes && this._component) {
29
29
  if (this._observerNodes instanceof Array) {
30
30
  this._observerNodes.forEach((n: TaroElement & any) => {
31
31
  disconnectEvent(n, VISIBLE_CHANGE_EVENT_NAME)
32
32
  // @ts-ignore
33
- n._nodeInfo?.thresholds = null
33
+ n._nodeInfo.thresholds = null
34
34
  })
35
35
  } else {
36
36
  disconnectEvent(this._observerNodes, VISIBLE_CHANGE_EVENT_NAME)
37
37
  // @ts-ignore
38
38
  if (this._observerNodes._nodeInfo) {
39
39
  // @ts-ignore
40
- this._observerNodes._nodeInfo?.thresholds = null
40
+ this._observerNodes._nodeInfo.thresholds = null
41
41
  }
42
42
  }
43
43
  }
44
44
  }
45
45
 
46
46
  public observe (targetSelector: string, callback: Taro.IntersectionObserver.ObserveCallback): void {
47
+ if (!this._component) return
48
+
47
49
  const { observeAll, thresholds } = this._options
48
50
  const node = findChildNodeWithDFS(this._component, targetSelector, observeAll)
49
51
  this._observerNodes = node
@@ -52,20 +54,24 @@ export class IntersectionObserver implements Taro.IntersectionObserver {
52
54
  if (node instanceof Array) {
53
55
  node.forEach(n => {
54
56
  // @ts-ignore
55
- n._nodeInfo?.thresholds = thresholds
57
+ n._nodeInfo.thresholds = thresholds
56
58
 
57
59
  setNodeEventCallbackAndTriggerComponentUpdate(n, VISIBLE_CHANGE_EVENT_NAME, (isVisible: boolean, currentRatio: number) => {
58
- callback(this.handleResult(isVisible, currentRatio))
60
+ callback(this.handleResult(isVisible, currentRatio, n))
59
61
  })
60
62
  })
61
63
  } else {
62
64
  // @ts-ignore
63
- node._nodeInfo?.thresholds = thresholds
65
+ node._nodeInfo.thresholds = thresholds
64
66
 
65
67
  setNodeEventCallbackAndTriggerComponentUpdate(node, VISIBLE_CHANGE_EVENT_NAME, (isVisible: boolean, currentRatio: number) => {
66
- callback(this.handleResult(isVisible, currentRatio))
68
+ callback(this.handleResult(isVisible, currentRatio, node))
67
69
  })
68
70
  }
71
+ } else {
72
+ callback({
73
+ errMsg: 'IntersectionObserver.observe:fail cannot find the node for selector.'
74
+ })
69
75
  }
70
76
  }
71
77
 
@@ -80,8 +86,10 @@ export class IntersectionObserver implements Taro.IntersectionObserver {
80
86
  }
81
87
 
82
88
  // @ts-ignore
83
- private handleResult (isVisible: boolean, currentRatio: number): Taro.IntersectionObserver.ObserveCallbackResult {
89
+ private handleResult (isVisible: boolean, currentRatio: number, node: TaroElement): Taro.IntersectionObserver.ObserveCallbackResult {
84
90
  const result = {
91
+ id: node.id,
92
+ dataset: node.dataset,
85
93
  intersectionRatio: currentRatio,
86
94
  // TODO 未做,等待能拿到element的info信息
87
95
  boundingClientRect: {
@@ -13,3 +13,5 @@ export const createIntersectionObserver: typeof Taro.createIntersectionObserver
13
13
  }
14
14
 
15
15
  export const createMediaQueryObserver = /* @__PURE__ */ temporarilyNotSupport('createMediaQueryObserver')
16
+
17
+ export { IntersectionObserver }
@@ -194,22 +194,31 @@ function queryBat (queue, cb) {
194
194
 
195
195
  arr = []
196
196
  traversalDFSDom(element)
197
- queue.forEach(item => {
197
+ queue.forEach((item) => {
198
198
  const { selector, single, fields } = item
199
- const nodeList = querySelector(selector, !single)
200
-
201
- result.push(nodeList.map(dom => {
199
+
200
+ if (single) {
201
+ const dom = querySelector(selector, !single)[0]
202
202
  // eslint-disable-next-line no-async-promise-executor
203
- return new Promise(async resolve => {
203
+ result.push(new Promise(async resolve => {
204
204
  await setNodeEventCallbackAndTriggerComponentUpdate(dom, AREA_CHANGE_EVENT_NAME, null, true)
205
-
206
205
  resolve(filter(fields, dom))
207
- })
208
- }))
206
+ }))
207
+ } else {
208
+ const nodeList = querySelector(selector, !single)
209
+ result.push(nodeList.map(dom => {
210
+ // eslint-disable-next-line no-async-promise-executor
211
+ return new Promise(async resolve => {
212
+ await setNodeEventCallbackAndTriggerComponentUpdate(dom, AREA_CHANGE_EVENT_NAME, null, true)
213
+
214
+ resolve(filter(fields, dom))
215
+ })
216
+ }))
217
+ }
209
218
  })
210
219
 
211
220
  Promise.all(result.map(item => {
212
- return Promise.all(item)
221
+ return item instanceof Array ? Promise.all(item) : item
213
222
  })).then(data => {
214
223
  cb(data)
215
224
  })
@@ -1,5 +1,4 @@
1
1
  import { eventHandler, createTaroEvent, convertNumber2VP, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME } from '@tarojs/runtime'
2
- import { createLazyChildren } from './render'
3
2
  import commonStyleModify from './style'
4
3
  import { BUTTON_THEME_COLOR } from './utils/constant/style'
5
4
  import { TOUCH_EVENT_MAP } from './utils/constant/event'
@@ -66,13 +65,13 @@ function getThemeAttributes (node: TaroButtonElement): TaroStyleType {
66
65
  }
67
66
  }
68
67
 
69
- function getButtonWidth (node: TaroButtonElement) {
68
+ function getButtonWidth (node: TaroButtonElement): string | number {
70
69
  const isMini = node._attrs.size === 'mini'
71
70
 
72
71
  return isMini ? convertNumber2VP(120) : '100%'
73
72
  }
74
73
 
75
- function getButtonHeight (node: TaroButtonElement) {
74
+ function getButtonHeight (node: TaroButtonElement): string | number {
76
75
  const isMini = node._attrs.size === 'mini'
77
76
 
78
77
  return isMini ? convertNumber2VP(60) : convertNumber2VP(92)
@@ -94,38 +93,53 @@ function getButtonMinHeight (node: TaroButtonElement): string | number | undefin
94
93
  return getButtonHeight(node)
95
94
  }
96
95
 
97
- @Builder
98
- export default function TaroButton (node: TaroButtonElement) {
99
- Button({ stateEffect: !node._attrs.disabled }) {
100
- Row() {
101
- if (node._attrs.loading) {
102
- LoadingProgress()
103
- .width(20).height(20)
104
- .color(getThemeAttributes(node).color)
105
- }
106
- createLazyChildren(node)
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
107
106
  }
108
107
  }
109
- .themeStyles(getThemeAttributes(node))
110
- .attributeModifier(commonStyleModify.setNode(node))
111
- .constraintSize({
112
- minWidth: node.hmStyle?.minWidth || getButtonMinWidth(node),
113
- minHeight: node.hmStyle?.minHeight || getButtonMinHeight(node),
114
- maxWidth: node.hmStyle?.maxWidth,
115
- maxHeight: node.hmStyle?.maxHeight,
116
- })
117
- .type(ButtonType.Normal)
118
- .onClick((e: ClickEvent) => {
119
- if (node._attrs.formType && ['submit', 'reset'].includes(node._attrs.formType)) {
120
- const eventName = node._attrs.formType + '-btn'
121
- const event: TaroEvent = createTaroEvent(eventName, {}, node)
122
- eventHandler(event, eventName, node)
108
+
109
+ build() {
110
+ Button({ stateEffect: !this.node._attrs.disabled }) {
111
+ if (this.node._attrs.loading) {
112
+ Row() {
113
+ LoadingProgress()
114
+ .width(20).height(20)
115
+ .color(getThemeAttributes(this.node).color)
116
+ this.createLazyChildren(this.node)
117
+ }
118
+ } else {
119
+ this.createLazyChildren(this.node)
120
+ }
123
121
  }
124
- eventHandler(e, 'click', node)
125
- })
126
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
127
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
128
- node._nodeInfo.areaInfo = res[1]
129
- }))
130
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
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))
144
+ }
131
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
+ }