@tarojs/plugin-platform-harmony-ets 4.0.0-beta.2 → 4.0.0-beta.20

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 (87) hide show
  1. package/dist/apis/base/system.ts +53 -20
  2. package/dist/apis/framework/index.ts +1 -5
  3. package/dist/apis/index.ts +3 -1
  4. package/dist/apis/network/request.ts +5 -5
  5. package/dist/apis/route/index.ts +15 -0
  6. package/dist/apis/storage/index.ts +124 -60
  7. package/dist/apis/wxml/IntersectionObserver.ts +5 -3
  8. package/dist/apis/wxml/index.ts +2 -0
  9. package/dist/components-harmony-ets/button.ets +41 -78
  10. package/dist/components-harmony-ets/checkbox.ets +19 -209
  11. package/dist/components-harmony-ets/form.ets +38 -160
  12. package/dist/components-harmony-ets/icon.ets +31 -83
  13. package/dist/components-harmony-ets/image.ets +22 -78
  14. package/dist/components-harmony-ets/innerHtml.ets +11 -6
  15. package/dist/components-harmony-ets/input.ets +10 -67
  16. package/dist/components-harmony-ets/label.ets +52 -173
  17. package/dist/components-harmony-ets/movableArea.ets +89 -0
  18. package/dist/components-harmony-ets/movableView.ets +67 -0
  19. package/dist/components-harmony-ets/picker.ets +32 -147
  20. package/dist/components-harmony-ets/progress.ets +47 -0
  21. package/dist/components-harmony-ets/pseudo.ets +80 -0
  22. package/dist/components-harmony-ets/radio.ets +19 -210
  23. package/dist/components-harmony-ets/richText.ets +22 -102
  24. package/dist/components-harmony-ets/scrollView.ets +66 -169
  25. package/dist/components-harmony-ets/slider.ets +10 -72
  26. package/dist/components-harmony-ets/style.ets +244 -0
  27. package/dist/components-harmony-ets/swiper.ets +30 -87
  28. package/dist/components-harmony-ets/switch.ets +9 -71
  29. package/dist/components-harmony-ets/text.ets +38 -89
  30. package/dist/components-harmony-ets/textArea.ets +10 -67
  31. package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
  32. package/dist/components-harmony-ets/utils/DynamicCenter.ts +1 -1
  33. package/dist/components-harmony-ets/utils/flexManager.ets +8 -7
  34. package/dist/components-harmony-ets/utils/helper.ets +5 -4
  35. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  36. package/dist/components-harmony-ets/utils/index.ts +55 -2
  37. package/dist/components-harmony-ets/utils/styles.ets +45 -85
  38. package/dist/components-harmony-ets/video.ets +33 -88
  39. package/dist/components-harmony-ets/view.ets +47 -160
  40. package/dist/components-harmony-ets/webView.ets +44 -99
  41. package/dist/index.d.ts +151 -0
  42. package/dist/index.js +56 -28
  43. package/dist/index.js.map +1 -1
  44. package/dist/runtime-ets/bom/window.ts +4 -2
  45. package/dist/runtime-ets/current.ts +2 -0
  46. package/dist/runtime-ets/dom/bind.ts +0 -1
  47. package/dist/runtime-ets/dom/cssNesting.ts +245 -0
  48. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +15 -40
  49. package/dist/runtime-ets/dom/document.ts +21 -8
  50. package/dist/runtime-ets/dom/element/element.ts +53 -9
  51. package/dist/runtime-ets/dom/element/form.ts +11 -4
  52. package/dist/runtime-ets/dom/element/index.ts +12 -1
  53. package/dist/runtime-ets/dom/element/movableArea.ts +12 -0
  54. package/dist/runtime-ets/dom/element/movableView.ts +193 -0
  55. package/dist/runtime-ets/dom/element/normal.ts +8 -3
  56. package/dist/runtime-ets/dom/element/progress.ts +13 -0
  57. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  58. package/dist/runtime-ets/dom/element/text.ts +1 -0
  59. package/dist/runtime-ets/dom/element/video.ts +1 -0
  60. package/dist/runtime-ets/dom/element/webView.ts +8 -0
  61. package/dist/runtime-ets/dom/event.ts +0 -1
  62. package/dist/runtime-ets/dom/eventTarget.ts +0 -3
  63. package/dist/runtime-ets/dom/node.ts +18 -17
  64. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +184 -207
  65. package/dist/runtime-ets/dom/stylesheet/index.ts +27 -307
  66. package/dist/runtime-ets/dom/stylesheet/type.ts +18 -6
  67. package/dist/runtime-ets/dom/stylesheet/util.ts +19 -15
  68. package/dist/runtime-ets/index.ts +2 -2
  69. package/dist/runtime-ets/interface/event.ts +1 -1
  70. package/dist/runtime-ets/utils/index.ts +24 -9
  71. package/dist/runtime-framework/react/app.ts +5 -1
  72. package/dist/runtime-framework/react/hooks.ts +3 -3
  73. package/dist/runtime-framework/react/native-page.ts +14 -9
  74. package/dist/runtime-framework/react/page.ts +1 -0
  75. package/dist/runtime-framework/solid/hooks.ts +3 -3
  76. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  77. package/dist/runtime-framework/solid/utils/index.ts +0 -2
  78. package/dist/runtime-utils.d.ts +825 -0
  79. package/dist/runtime-utils.js +185 -91
  80. package/dist/runtime-utils.js.map +1 -1
  81. package/dist/runtime.d.ts +1 -0
  82. package/dist/runtime.js +185 -91
  83. package/dist/runtime.js.map +1 -1
  84. package/index.js +3 -1
  85. package/package.json +10 -10
  86. package/types/index.d.ts +4 -0
  87. package/dist/runtime-ets/utils/bind.ts +0 -24
@@ -1,24 +1,56 @@
1
+ import ConfigurationConstant from '@ohos.app.ability.ConfigurationConstant'
1
2
  // 设备信息,从 API Version 6 开始支持
2
3
  import deviceInfo from '@ohos.deviceInfo'
3
4
  // 显示设备属性,从 API Version 7 开始支持
4
5
  import _display from '@ohos.display'
5
6
  // 从 API Version 7 开始支持
6
7
  import i18n from '@ohos.i18n'
7
- // 设备信息 从API Version 6开始,该接口不再维护,推荐使用新接口'@ohos.deviceInfo'进行设备信息查询
8
- import deviceMethod from '@system.device'
8
+ import { Current, window } from '@tarojs/runtime'
9
9
 
10
10
  import { callAsyncFail, callAsyncSuccess } from '../utils'
11
11
 
12
12
  import type Taro from '@tarojs/taro/types'
13
13
 
14
- const display = _display.getDefaultDisplaySync()
14
+ let display
15
+ let navigationIndicatorRect
16
+ let safeArea: TaroGeneral.SafeAreaResult | null = null
17
+ let statusBarHeight
18
+ let windowRect
15
19
 
16
- let device
20
+ (Current as any).contextPromise.then((context) => {
21
+ const win = window.__ohos.getLastWindow(context)
22
+ win.then(mainWindow => {
23
+ const topRect = mainWindow.getWindowAvoidArea(window.__ohos.AvoidAreaType.TYPE_SYSTEM).topRect
24
+ navigationIndicatorRect = mainWindow.getWindowAvoidArea(window.__ohos.AvoidAreaType.TYPE_NAVIGATION_INDICATOR).bottomRect
25
+ statusBarHeight = topRect.top + topRect.height
26
+ windowRect = mainWindow.getWindowProperties().windowRect
17
27
 
18
- deviceMethod.getInfo({
19
- success: data => {
20
- device = data
21
- }
28
+ try {
29
+ display = _display.getDefaultDisplaySync()
30
+ // @ts-ignore
31
+ display.getCutoutInfo((err, { boundingRects = [], waterfallDisplayAreaRects = {} }: _display.CutoutInfo = {}) => {
32
+ if (err?.code) {
33
+ console.error('Failed to get cutout info', JSON.stringify(err))
34
+ return
35
+ }
36
+
37
+ const top = Math.max(...boundingRects.map(rect => rect.top + rect.height), waterfallDisplayAreaRects.top?.top + waterfallDisplayAreaRects.top?.height, statusBarHeight)
38
+ const bottom = display.height - Math.min(waterfallDisplayAreaRects.bottom?.top, navigationIndicatorRect?.top)
39
+ const left = waterfallDisplayAreaRects.left?.left + waterfallDisplayAreaRects.left?.width
40
+ const right = display.width - waterfallDisplayAreaRects.right?.left
41
+ safeArea = {
42
+ top,
43
+ bottom,
44
+ left,
45
+ right,
46
+ height: bottom - top,
47
+ width: right - left,
48
+ }
49
+ })
50
+ } catch (e) {
51
+ console.error('Failed to get display', e)
52
+ }
53
+ })
22
54
  })
23
55
 
24
56
  /* 同步版本 */
@@ -32,7 +64,7 @@ export const getSystemInfoSync: typeof Taro.getSystemInfoSync = function () {
32
64
  res.cameraAuthorized = null // 允许使用摄像头的开关 boolean
33
65
  res.enableDebug = null // 是否已打开调试 boolean
34
66
  res.fontSizeSetting = null // 用户字体大小(单位px) number
35
- res.language = i18n && i18n.getSystemLanguage && i18n.getSystemLanguage() // string
67
+ res.language = i18n?.getSystemLanguage?.() // string
36
68
  res.locationAuthorized = null // 定位的开关 boolean
37
69
  res.locationEnabled = null // 地理位置的系统开关 boolean
38
70
  res.microphoneAuthorized = null // 麦克风的开关 boolean
@@ -43,17 +75,18 @@ export const getSystemInfoSync: typeof Taro.getSystemInfoSync = function () {
43
75
  res.notificationSoundAuthorized = false // 通知带有声音的开关(仅 iOS 有效)boolean
44
76
  res.phoneCalendarAuthorized = null // 使用日历的开关 boolean
45
77
  res.wifiEnabled = false // Wi-Fi 的系统开关 boolean
46
- res.pixelRatio = null // 设备像素比,number
47
- res.platform = 'android' // 客户端平台 string
48
- res.safeArea = null // 在竖屏正方向下的安全区域 General.SafeAreaResult
49
- res.screenHeight = display && display.height // 屏幕高度,单位px number
50
- res.screenWidth = display && display.width // 屏幕宽度,单位px number
51
- res.statusBarHeight = null // 状态栏的高度,单位px number
52
- res.system = deviceInfo && deviceInfo.osFullName // 操作系统及版本 string
53
- res.theme = null // 系统当前主题,取值为light或dark 'light' | 'dark'
54
- res.windowWidth = device && device.windowWidth // 可使用窗口宽度,单位px number
55
- res.windowHeight = device && device.windowHeight // 可使用窗口高度,单位px number
56
- res.version = deviceInfo && deviceInfo.displayVersion // 版本号 string
78
+ res.pixelRatio = display && (Math.round(display.xDPI / display.width * 100) / 100) // 设备像素比,number
79
+ res.platform = 'harmony' // 客户端平台 string
80
+ res.safeArea = safeArea // 在竖屏正方向下的安全区域 General.SafeAreaResult
81
+ res.screenHeight = display?.height // 屏幕高度,单位px number
82
+ res.screenWidth = display?.width // 屏幕宽度,单位px number
83
+ res.statusBarHeight = statusBarHeight // 状态栏的高度,单位px number
84
+ res.system = deviceInfo?.osFullName // 操作系统及版本 string
85
+ // Note: 更新配置时才能记录
86
+ res.theme = AppStorage.get('__TARO_APP_CONFIG')?.colorMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK ? 'dark' : 'light' // 系统当前主题,取值为light或dark 'light' | 'dark'
87
+ res.windowHeight = windowRect?.height // 可使用窗口高度,单位px number
88
+ res.windowWidth = windowRect?.width // 可使用窗口宽度,单位px number
89
+ res.version = deviceInfo?.displayVersion // 版本号 string
57
90
 
58
91
  return res
59
92
  }
@@ -1,5 +1,3 @@
1
- import { Current } from '@tarojs/runtime'
2
-
3
1
  import { temporarilyNotSupport } from '../utils'
4
2
 
5
3
  export const ENV_TYPE = {
@@ -19,12 +17,10 @@ export function getEnv () {
19
17
  return ENV_TYPE.HARMONY
20
18
  }
21
19
 
22
- export { Current }
23
-
24
20
  // TODO
25
21
  export const getCurrentPages = () => []
26
22
 
27
- export const getCurrentInstance = () => Current
23
+ export { Current, getCurrentInstance } from '@tarojs/runtime'
28
24
 
29
25
  export const requirePlugin = temporarilyNotSupport('requirePlugin')
30
26
 
@@ -33,7 +33,7 @@ const defaultUnitPrecision = 5
33
33
  const defaultTargetUnit = 'vp'
34
34
 
35
35
  export function getApp () {
36
- return Current.app
36
+ return Current.app || {}
37
37
  }
38
38
 
39
39
  export function initPxTransform ({
@@ -120,5 +120,7 @@ export function getAppInfo () {
120
120
  }
121
121
  }
122
122
 
123
+ initNativeApi(taro)
124
+
123
125
  export * from './apis'
124
126
  export default taro
@@ -6,7 +6,7 @@
6
6
  // ✅ RequestTask.onHeadersReceived
7
7
 
8
8
  import http from '@ohos.net.http'
9
- import { isString, isUndefined } from '@tarojs/shared'
9
+ import { isString } from '@tarojs/shared'
10
10
 
11
11
  import { callAsyncFail, callAsyncSuccess, validateParams } from '../utils'
12
12
 
@@ -59,10 +59,10 @@ export const request: typeof Taro.request = function (options) {
59
59
  }
60
60
 
61
61
  // 检查 Header 是否有 Referer
62
- if (isUndefined(header.Referer)) {
63
- const error = { errMsg: 'request fail parameter error: the header doesn‘t support Referer property' }
64
- callAsyncFail(reject, error, options)
65
- }
62
+ // if (isUndefined(header.Referer)) {
63
+ // const error = { errMsg: 'request fail parameter error: the header doesn‘t support Referer property' }
64
+ // callAsyncFail(reject, error, options)
65
+ // }
66
66
 
67
67
  // 检查 method 是否正确
68
68
  if (method) {
@@ -16,6 +16,21 @@ function parseURL (raw = ''): [string, Record<string, unknown>] {
16
16
  const [urlStr, queryStr = ''] = raw.split('?')
17
17
  const query: Record<string, unknown> = queryToJson(queryStr)
18
18
  let url = urlStr.replace(/^\//, '')
19
+
20
+ // 处理相对路径
21
+ if (url.indexOf('.') === 0) {
22
+ const page = router.getState()
23
+ const parts = page.path.split('/')
24
+ parts.pop()
25
+ url.split('/').forEach((item) => {
26
+ if (item === '.') {
27
+ return
28
+ }
29
+ item === '..' ? parts.pop() : parts.push(item)
30
+ })
31
+ url = parts.join('/')
32
+ }
33
+
19
34
  if (isTabPage(url)) {
20
35
  query.$page = url
21
36
  url = TARO_TABBAR_PAGE_PATH
@@ -7,32 +7,30 @@ import dataPreferences from '@ohos.data.preferences'
7
7
  import hilog from '@ohos.hilog'
8
8
  import { Current } from '@tarojs/runtime'
9
9
 
10
- import { callAsyncFail, callAsyncSuccess, temporarilyNotSupport, validateParams } from '../utils'
10
+ import { temporarilyNotSupport, validateParams } from '../utils'
11
+ import { MethodHandler } from '../utils/handler'
11
12
 
12
13
  import type Taro from '@tarojs/taro/types'
13
14
 
14
- const preferencesPromise = (Current as any).contextPromise
15
- .then((context) => {
16
- return bundleManager
17
- .getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION)
18
- .then(data => {
19
- return dataPreferences
20
- .getPreferences(context, `${data.appInfo.uid}Store`)
21
- })
22
- })
23
- .catch((error) => {
24
- hilog.error(0x0000, 'TaroFailedTag', 'Failed to load the storage. Cause: %{public}s', error.code ? JSON.stringify(error) : error.message || error)
25
- })
15
+ let context
16
+ let preferences: any
26
17
 
27
- async function getItem (key: string): Promise<{ result: boolean, data?: number | string | boolean }> {
28
- try {
29
- const preferences = await preferencesPromise
30
- const item = await preferences.get(key, null)
18
+ (Current as any).contextPromise.then((ctx) => {
19
+ context = ctx
20
+ return context
21
+ })
31
22
 
32
- return { result: true, data: item }
23
+ function getPreferences () {
24
+ try {
25
+ if (!preferences) {
26
+ const data = bundleManager.getBundleInfoForSelfSync(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION)
27
+ preferences = dataPreferences.getPreferencesSync(context, { name: `${data.appInfo.uid}Store` })
28
+ }
33
29
  } catch (error) {
34
- return { result: false }
30
+ hilog.error(0x0000, 'TaroFailedTag', 'Failed to load the storage. Cause: %{public}s', error.code ? JSON.stringify(error) : error.message || error)
35
31
  }
32
+
33
+ return preferences
36
34
  }
37
35
 
38
36
  const storageSchema = {
@@ -40,89 +38,155 @@ const storageSchema = {
40
38
  }
41
39
 
42
40
  export function getStorage<T = any> (options: Taro.getStorage.Option<T>) {
41
+ const { key, success, fail, complete } = options || {}
42
+ const handle = new MethodHandler<{data: any}>({ name: 'getStorage', success, fail, complete })
43
+
43
44
  return new Promise((resolve, reject) => {
44
45
  try {
45
46
  validateParams('getStorage', options, storageSchema)
46
47
  } catch (error) {
47
48
  const res = { errMsg: error.message }
48
- return callAsyncFail(reject, res, options)
49
+ return handle.fail(res, { resolve, reject })
50
+ }
51
+
52
+ const preferences = getPreferences()
53
+
54
+ if (!preferences) return handle.fail({}, { resolve, reject })
55
+
56
+ const data = preferences.getSync(key, null)
57
+ if (data) {
58
+ return handle.success({ data }, { resolve, reject })
59
+ } else {
60
+ return handle.success({ errMsg: 'data not found' }, { resolve, reject })
49
61
  }
50
- getItem(options.key).then(({ result, data }) => {
51
- const res: Record<string, any> = { errMsg: 'getStorage:ok' }
52
-
53
- if (result) {
54
- res.data = data
55
- callAsyncSuccess(resolve, res, options)
56
- } else {
57
- res.errMsg = 'getStorage:fail data not found'
58
- callAsyncFail(reject, res, options)
59
- }
60
- })
61
62
  })
62
63
  }
63
64
 
65
+ export function getStorageSync (key: string) {
66
+ if (!key) {
67
+ throw new Error('getStorageSync:fail parameter error: parameter should be String')
68
+ }
69
+
70
+ const preferences = getPreferences()
71
+
72
+ if (!preferences) {
73
+ throw new Error('getStorageSync:fail:preferences is null')
74
+ }
75
+
76
+ const data = preferences.getSync(key, null)
77
+ if (data) {
78
+ return data
79
+ } else {
80
+ throw new Error('data not found')
81
+ }
82
+ }
83
+
64
84
  export function setStorage (options: Taro.setStorage.Option) {
85
+ const { key, data, success, fail, complete } = options || {}
86
+ const handle = new MethodHandler({ name: 'setStorage', success, fail, complete })
87
+
65
88
  return new Promise((resolve, reject) => {
66
89
  try {
67
90
  validateParams('setStorage', options, storageSchema)
68
91
  } catch (error) {
69
92
  const res = { errMsg: error.message }
70
- return callAsyncFail(reject, res, options)
93
+ return handle.fail(res, { resolve, reject })
71
94
  }
72
95
 
73
- const { key, data } = options
74
- const res = { errMsg: 'setStorage:ok' }
96
+ const preferences = getPreferences()
75
97
 
76
- preferencesPromise.then(async (preferences) => {
77
- await preferences.put(key, data)
78
- await preferences.flush()
98
+ if (!preferences) return handle.fail({}, { resolve, reject })
79
99
 
80
- callAsyncSuccess(resolve, res, options)
81
- })
100
+ preferences.putSync(key, data)
101
+ preferences.flush()
102
+
103
+ return handle.success({}, { resolve, reject })
82
104
  })
83
105
  }
84
106
 
107
+ export function setStorageSync (key: string, data: any) {
108
+ if (!key) {
109
+ throw new Error('setStorageSync:fail key error: key should be String')
110
+ }
111
+
112
+ const preferences = getPreferences()
113
+
114
+ if (!preferences) {
115
+ throw new Error('setStorageSync:fail:preferences is null')
116
+ }
117
+
118
+ preferences.putSync(key, data)
119
+ preferences.flush()
120
+ }
121
+
85
122
  export function removeStorage (options: Taro.removeStorage.Option) {
123
+ const { key, success, fail, complete } = options || {}
124
+ const handle = new MethodHandler({ name: 'removeStorage', success, fail, complete })
125
+
86
126
  return new Promise((resolve, reject) => {
87
127
  try {
88
128
  validateParams('removeStorage', options, storageSchema)
89
129
  } catch (error) {
90
130
  const res = { errMsg: error.message }
91
- return callAsyncFail(reject, res, options)
131
+ return handle.fail(res, { resolve, reject })
92
132
  }
93
133
 
94
- const { key } = options
134
+ const preferences = getPreferences()
95
135
 
96
- preferencesPromise.then(async (preferences) => {
97
- await preferences.delete(key)
98
- await preferences.flush()
136
+ if (!preferences) return handle.fail({}, { resolve, reject })
99
137
 
100
- const res = { errMsg: 'removeStorage:ok' }
101
- callAsyncSuccess(resolve, res, options)
102
- })
138
+ preferences.deleteSync(key)
139
+ preferences.flush()
140
+
141
+ return handle.success({}, { resolve, reject })
103
142
  })
104
143
  }
105
144
 
145
+ export function removeStorageSync (key: string) {
146
+ if (!key) {
147
+ throw new Error('removeStorageSync:fail key error: key should be String')
148
+ }
149
+
150
+ const preferences = getPreferences()
151
+
152
+ if (!preferences) {
153
+ throw new Error('removeStorageSync:fail:preferences is null')
154
+ }
155
+
156
+ preferences.deleteSync(key)
157
+ preferences.flush()
158
+ }
159
+
106
160
  export function clearStorage (options: Taro.clearStorage.Option) {
107
- return new Promise(resolve => {
108
- preferencesPromise.then(async (preferences) => {
109
- await preferences.clear()
110
- await preferences.flush()
111
-
112
- const res = { errMsg: 'clearStorage:ok' }
113
- callAsyncSuccess(resolve, res, options)
114
- })
161
+ const { success, fail, complete } = options || {}
162
+ const handle = new MethodHandler({ name: 'clearStorage', success, fail, complete })
163
+
164
+ return new Promise((resolve, reject) => {
165
+ const preferences = getPreferences()
166
+
167
+ if (!preferences) return handle.fail({}, { resolve, reject })
168
+
169
+ preferences.clearSync()
170
+ preferences.flush()
171
+
172
+ return handle.success({}, { resolve, reject })
115
173
  })
116
174
  }
117
175
 
176
+ export function clearStorageSync () {
177
+ const preferences = getPreferences()
178
+
179
+ if (!preferences) {
180
+ throw new Error('clearStorageSync:fail:preferences is null')
181
+ }
182
+
183
+ preferences.clearSync()
184
+ preferences.flush()
185
+ }
186
+
118
187
  export const getStorageInfoSync = temporarilyNotSupport('getStorageInfoSync')
119
188
  export const getStorageInfo = temporarilyNotSupport('getStorageInfo')
120
189
 
121
- export const getStorageSync = temporarilyNotSupport('getStorageSync', 'getStorage')
122
- export const setStorageSync = temporarilyNotSupport('setStorageSync', 'setStorage')
123
- export const clearStorageSync = temporarilyNotSupport('clearStorageSync', 'clearStorage')
124
- export const removeStorageSync = temporarilyNotSupport('removeStorageSync', 'removeStorage')
125
-
126
190
  export const createBufferURL = /* @__PURE__ */ temporarilyNotSupport('createBufferURL')
127
191
  export const revokeBufferURL = /* @__PURE__ */ temporarilyNotSupport('revokeBufferURL')
128
192
 
@@ -19,13 +19,13 @@ 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)
@@ -44,6 +44,8 @@ export class IntersectionObserver implements Taro.IntersectionObserver {
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
@@ -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 }
@@ -1,56 +1,11 @@
1
1
  import { eventHandler, createTaroEvent, convertNumber2VP, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME } from '@tarojs/runtime'
2
- import { createLazyChildren } from './render'
2
+ import commonStyleModify from './style'
3
3
  import { BUTTON_THEME_COLOR } from './utils/constant/style'
4
4
  import { TOUCH_EVENT_MAP } from './utils/constant/event'
5
- import { getNormalAttributes, shouldBindEvent, getNodeThresholds } from './utils/helper'
5
+ import { shouldBindEvent, getNodeThresholds } from './utils/helper'
6
6
 
7
7
  import type { TaroAny, TaroEvent, TaroButtonElement, TaroStyleType } from '@tarojs/runtime'
8
8
 
9
- @Extend(Button)
10
- function attrs (style: TaroStyleType) {
11
- .id(style.id)
12
- .key(style.id)
13
- .flexGrow(style.flexGrow)
14
- .flexShrink(style.flexShrink)
15
- .flexBasis(style.flexBasis)
16
- .alignSelf(style.alignSelf)
17
- .padding({
18
- top: style.paddingTop,
19
- right: style.paddingRight || 10,
20
- bottom: style.paddingBottom,
21
- left: style.paddingLeft || 10
22
- })
23
- .margin({
24
- top: style.marginTop,
25
- right: style.marginRight,
26
- bottom: style.marginBottom,
27
- left: style.marginLeft
28
- })
29
- .width(style.width)
30
- .height(style.height)
31
- .constraintSize({
32
- minWidth: style.minWidth,
33
- maxWidth: style.maxWidth,
34
- minHeight: style.minHeight,
35
- maxHeight: style.maxHeight
36
- })
37
- .backgroundImage(style.backgroundImage?.src, style.backgroundRepeat)
38
- .backgroundImageSize(style.backgroundSize)
39
- .backgroundImagePosition(style.backgroundPosition)
40
- .borderStyle({
41
- top: style.borderTopStyle,
42
- right: style.borderRightStyle,
43
- bottom: style.borderBottomStyle,
44
- left: style.borderLeftStyle
45
- })
46
- .zIndex(style.zIndex)
47
- .linearGradient(style.linearGradient)
48
- .clip(style.overflow)
49
- .rotate({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y, angle: 0 })
50
- .scale({ centerX: style.transformOrigin?.x, centerY: style.transformOrigin?.y })
51
- .transform(style.transform)
52
- }
53
-
54
9
  @Extend(Button)
55
10
  function themeStyles(style: TaroStyleType) {
56
11
  .fontColor(style.color)
@@ -138,38 +93,46 @@ function getButtonMinHeight (node: TaroButtonElement): string | number | undefin
138
93
  return getButtonHeight(node)
139
94
  }
140
95
 
141
- @Builder
142
- export default function TaroButton (node: TaroButtonElement) {
143
- Button({ stateEffect: !node._attrs.disabled }) {
144
- Row() {
145
- if (node._attrs.loading) {
146
- LoadingProgress()
147
- .width(20).height(20)
148
- .color(getThemeAttributes(node).color)
96
+ @Component
97
+ export default struct TaroButton {
98
+ @Builder customBuilder() {}
99
+ @BuilderParam createLazyChildren: (node: TaroButtonElement) => void = this.customBuilder
100
+ @ObjectLink node: TaroButtonElement
101
+
102
+ build() {
103
+ if (this.node?.hmStyle?.display !== 'none') {
104
+ Button({ stateEffect: !this.node._attrs.disabled }) {
105
+ Row() {
106
+ if (this.node._attrs.loading) {
107
+ LoadingProgress()
108
+ .width(20).height(20)
109
+ .color(getThemeAttributes(this.node).color)
110
+ }
111
+ this.createLazyChildren(this.node)
112
+ }
149
113
  }
150
- createLazyChildren(node)
114
+ .themeStyles(getThemeAttributes(this.node))
115
+ .attributeModifier(commonStyleModify.setNode(this.node))
116
+ .constraintSize({
117
+ minWidth: this.node.hmStyle?.minWidth || getButtonMinWidth(this.node),
118
+ minHeight: this.node.hmStyle?.minHeight || getButtonMinHeight(this.node),
119
+ maxWidth: this.node.hmStyle?.maxWidth,
120
+ maxHeight: this.node.hmStyle?.maxHeight,
121
+ })
122
+ .type(ButtonType.Normal)
123
+ .onClick((e: ClickEvent) => {
124
+ if (this.node._attrs.formType && ['submit', 'reset'].includes(this.node._attrs.formType)) {
125
+ const eventName = this.node._attrs.formType + '-btn'
126
+ const event: TaroEvent = createTaroEvent(eventName, {}, this.node)
127
+ eventHandler(event, eventName, this.node)
128
+ }
129
+ eventHandler(e, 'click', this.node)
130
+ })
131
+ .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node), this.node, TOUCH_EVENT_MAP.values()))
132
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
133
+ this.node._nodeInfo.areaInfo = res[1]
134
+ }))
135
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
151
136
  }
152
137
  }
153
- .themeStyles(getThemeAttributes(node))
154
- .attrs(getNormalAttributes(node))
155
- .constraintSize({
156
- minWidth: node.hmStyle?.minWidth || getButtonMinWidth(node),
157
- minHeight: node.hmStyle?.minHeight || getButtonMinHeight(node),
158
- maxWidth: node.hmStyle?.maxWidth,
159
- maxHeight: node.hmStyle?.maxHeight,
160
- })
161
- .type(ButtonType.Normal)
162
- .onClick((e: ClickEvent) => {
163
- if (node._attrs.formType && ['submit', 'reset'].includes(node._attrs.formType)) {
164
- const eventName = node._attrs.formType + '-btn'
165
- const event: TaroEvent = createTaroEvent(eventName, {}, node)
166
- eventHandler(event, eventName, node)
167
- }
168
- eventHandler(e, 'click', node)
169
- })
170
- .onTouch(shouldBindEvent((e: TouchEvent) => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), node), node, TOUCH_EVENT_MAP.values()))
171
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
172
- node._nodeInfo.areaInfo = res[1]
173
- }))
174
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
175
138
  }