@tarojs/taro-h5 3.3.13 → 3.3.17

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 (169) hide show
  1. package/dist/index.cjs.js +6134 -8352
  2. package/dist/index.js +9044 -0
  3. package/dist/taroApis.js +1 -1
  4. package/package.json +9 -9
  5. package/src/api/ad/index.ts +5 -0
  6. package/src/api/ai/facial.ts +6 -0
  7. package/src/api/ai/index.ts +2 -0
  8. package/src/api/ai/visual.ts +4 -0
  9. package/src/api/alipay/index.ts +4 -0
  10. package/src/api/base/crypto.ts +4 -0
  11. package/src/api/base/debug.ts +5 -0
  12. package/src/api/base/index.ts +23 -0
  13. package/src/api/base/performance.ts +5 -0
  14. package/src/api/base/system/index.ts +2 -0
  15. package/src/api/base/system/info.ts +64 -0
  16. package/src/api/base/system/network.ts +70 -0
  17. package/src/api/base/update.ts +5 -0
  18. package/src/api/base/weapp/app-event.ts +19 -0
  19. package/src/api/base/weapp/life-cycle.ts +5 -0
  20. package/src/api/canvas/CanvasContext.ts +230 -0
  21. package/src/api/canvas/canvasGetImageData.ts +29 -0
  22. package/src/api/canvas/canvasPutImageData.ts +26 -0
  23. package/src/api/canvas/canvasToTempFilePath.ts +26 -0
  24. package/src/api/canvas/createCanvasContext.ts +20 -0
  25. package/src/api/canvas/{index.js → index.ts} +9 -3
  26. package/src/api/cloud/index.ts +27 -0
  27. package/src/api/data-analysis/index.ts +6 -0
  28. package/src/api/device/accelerometer.ts +89 -0
  29. package/src/api/device/accessibility.ts +4 -0
  30. package/src/api/device/battery.ts +5 -0
  31. package/src/api/device/bluetooth-ble.ts +19 -0
  32. package/src/api/device/bluetooth-peripheral.ts +6 -0
  33. package/src/api/device/bluetooth.ts +16 -0
  34. package/src/api/device/calendar.ts +5 -0
  35. package/src/api/device/clipboard.ts +67 -0
  36. package/src/api/device/compass.ts +74 -0
  37. package/src/api/device/contact.ts +5 -0
  38. package/src/api/device/crypto.ts +4 -0
  39. package/src/api/device/gyroscope.ts +7 -0
  40. package/src/api/device/iBeacon.ts +10 -0
  41. package/src/api/device/index.ts +22 -0
  42. package/src/api/device/keyboard.ts +7 -0
  43. package/src/api/device/memory.ts +5 -0
  44. package/src/api/device/motion.ts +92 -0
  45. package/src/api/device/nfc.ts +10 -0
  46. package/src/api/device/phone.ts +30 -0
  47. package/src/api/device/scan.ts +7 -0
  48. package/src/api/device/screen.ts +9 -0
  49. package/src/api/device/vibrate.ts +36 -0
  50. package/src/api/device/wifi.ts +13 -0
  51. package/src/api/ext/index.ts +5 -0
  52. package/src/api/files/index.ts +11 -0
  53. package/src/api/framework/index.ts +10 -0
  54. package/src/api/index.ts +25 -0
  55. package/src/api/location/chooseLocation.ts +106 -0
  56. package/src/api/location/index.ts +19 -0
  57. package/src/api/location/style.css +8 -8
  58. package/src/api/media/audio/index.ts +99 -0
  59. package/src/api/media/background-audio.ts +12 -0
  60. package/src/api/media/camera.ts +4 -0
  61. package/src/api/media/editor.ts +29 -0
  62. package/src/api/media/image/chooseImage.ts +80 -0
  63. package/src/api/{image → media/image}/getImageInfo.js +0 -0
  64. package/src/api/media/image/index.ts +13 -0
  65. package/src/api/{image → media/image}/previewImage.js +4 -0
  66. package/src/api/media/index.ts +13 -0
  67. package/src/api/media/live.ts +5 -0
  68. package/src/api/media/map.ts +4 -0
  69. package/src/api/media/media-recorder.ts +4 -0
  70. package/src/api/media/recorder.ts +6 -0
  71. package/src/api/media/video/index.ts +82 -0
  72. package/src/api/media/video-decoder.ts +4 -0
  73. package/src/api/media/video-processing.ts +4 -0
  74. package/src/api/media/voip.ts +17 -0
  75. package/src/api/navigate/index.ts +7 -0
  76. package/src/api/{fileTransfer/downloadFile.js → network/download.ts} +16 -25
  77. package/src/api/network/index.ts +7 -0
  78. package/src/api/network/mdns.ts +13 -0
  79. package/src/api/{request/index.js → network/request/index.ts} +9 -6
  80. package/src/api/network/tcp.ts +4 -0
  81. package/src/api/network/udp.ts +4 -0
  82. package/src/api/{fileTransfer/uploadFile.js → network/upload.ts} +28 -30
  83. package/src/api/{fileTransfer/utils.js → network/utils.ts} +0 -0
  84. package/src/api/{webSocket/index.js → network/websocket/index.ts} +50 -57
  85. package/src/api/{webSocket/socketTask.js → network/websocket/socketTask.ts} +16 -6
  86. package/src/api/open-api/account.ts +4 -0
  87. package/src/api/open-api/address.ts +4 -0
  88. package/src/api/open-api/authorize.ts +5 -0
  89. package/src/api/open-api/card.ts +5 -0
  90. package/src/api/open-api/channels-live.ts +9 -0
  91. package/src/api/open-api/customer-service.ts +4 -0
  92. package/src/api/open-api/facial.ts +7 -0
  93. package/src/api/open-api/favorites.ts +5 -0
  94. package/src/api/open-api/group.ts +4 -0
  95. package/src/api/open-api/index.ts +18 -0
  96. package/src/api/open-api/invoice.ts +5 -0
  97. package/src/api/open-api/license-plate.ts +4 -0
  98. package/src/api/open-api/login.ts +6 -0
  99. package/src/api/open-api/red-package.ts +4 -0
  100. package/src/api/open-api/settings.ts +5 -0
  101. package/src/api/open-api/soter.ts +6 -0
  102. package/src/api/open-api/subscribe-message.ts +4 -0
  103. package/src/api/open-api/user-info.ts +5 -0
  104. package/src/api/open-api/werun.ts +5 -0
  105. package/src/api/payment/index.ts +5 -0
  106. package/src/api/route/index.ts +10 -0
  107. package/src/api/share/index.ts +13 -0
  108. package/src/api/storage/background-fetch.ts +7 -0
  109. package/src/api/storage/index.ts +193 -0
  110. package/src/api/swan/index.ts +31 -0
  111. package/src/{taro/index.js → api/taro.ts} +133 -149
  112. package/src/api/{createAnimation/index.js → ui/animation/index.ts} +26 -14
  113. package/src/api/ui/background.ts +5 -0
  114. package/src/api/ui/custom-component.ts +4 -0
  115. package/src/api/ui/fonts.ts +4 -0
  116. package/src/api/ui/index.ts +12 -0
  117. package/src/api/ui/interaction/actionSheet.ts +212 -0
  118. package/src/api/{interactive/index.js → ui/interaction/index.ts} +102 -90
  119. package/src/api/ui/interaction/modal.ts +237 -0
  120. package/src/api/{interactive/toast.js → ui/interaction/toast.ts} +35 -33
  121. package/src/api/ui/menu.ts +4 -0
  122. package/src/api/ui/navigation-bar/index.ts +52 -0
  123. package/src/api/ui/pull-down-refresh.ts +32 -0
  124. package/src/api/{scroll/index.js → ui/scroll/index.ts} +16 -28
  125. package/src/api/ui/sticky.ts +4 -0
  126. package/src/api/ui/tab-bar.ts +326 -0
  127. package/src/api/ui/window.ts +37 -0
  128. package/src/api/utils/handler.ts +105 -0
  129. package/src/api/utils/{index.js → index.ts} +24 -87
  130. package/src/api/worker/index.ts +4 -0
  131. package/src/api/wxml/index.ts +9 -0
  132. package/src/api/{createSelectorQuery/index.js → wxml/selectorQuery.ts} +86 -59
  133. package/src/index.ts +6 -0
  134. package/src/types/api.d.ts +4 -0
  135. package/src/types/define.d.ts +2 -0
  136. package/{types → src/types}/index.d.ts +0 -0
  137. package/{types → src/types}/type.ts +1 -1
  138. package/src/api/accelerometer/index.js +0 -105
  139. package/src/api/audio/index.js +0 -137
  140. package/src/api/canvas/canvasGetImageData.js +0 -44
  141. package/src/api/canvas/canvasPutImageData.js +0 -45
  142. package/src/api/canvas/canvasToTempFilePath.js +0 -49
  143. package/src/api/canvas/createCanvasContext.js +0 -340
  144. package/src/api/clipboard/index.js +0 -113
  145. package/src/api/compass/index.js +0 -99
  146. package/src/api/deviceMotion/index.js +0 -105
  147. package/src/api/fileTransfer/index.js +0 -2
  148. package/src/api/image/chooseImage.js +0 -87
  149. package/src/api/image/index.js +0 -7
  150. package/src/api/index.js +0 -29
  151. package/src/api/interactive/actionSheet.js +0 -214
  152. package/src/api/interactive/modal.js +0 -256
  153. package/src/api/location/chooseLocation.js +0 -143
  154. package/src/api/location/index.js +0 -5
  155. package/src/api/navigationBar/index.js +0 -57
  156. package/src/api/open/index.js +0 -5
  157. package/src/api/others/index.js +0 -43
  158. package/src/api/pullDownRefresh/index.js +0 -51
  159. package/src/api/storage/index.js +0 -211
  160. package/src/api/system/index.js +0 -9
  161. package/src/api/system/info.js +0 -36
  162. package/src/api/system/network.js +0 -68
  163. package/src/api/tabBar/index.js +0 -424
  164. package/src/api/unsupportedApi/index.js +0 -278
  165. package/src/api/vibrate/index.js +0 -49
  166. package/src/api/video/index.js +0 -87
  167. package/src/api/window/index.js +0 -38
  168. package/src/index.cjs.js +0 -11
  169. package/src/index.js +0 -6
@@ -0,0 +1,13 @@
1
+ import { temporarilyNotSupport } from '../utils'
2
+
3
+ // 转发
4
+ export const updateShareMenu = temporarilyNotSupport('updateShareMenu')
5
+ export const showShareMenu = temporarilyNotSupport('showShareMenu')
6
+ export const showShareImageMenu = temporarilyNotSupport('showShareImageMenu')
7
+ export const shareVideoMessage = temporarilyNotSupport('shareVideoMessage')
8
+ export const shareFileMessage = temporarilyNotSupport('shareFileMessage')
9
+ export const onCopyUrl = temporarilyNotSupport('onCopyUrl')
10
+ export const offCopyUrl = temporarilyNotSupport('offCopyUrl')
11
+ export const hideShareMenu = temporarilyNotSupport('hideShareMenu')
12
+ export const getShareInfo = temporarilyNotSupport('getShareInfo')
13
+ export const authPrivateMessage = temporarilyNotSupport('authPrivateMessage')
@@ -0,0 +1,7 @@
1
+ import { temporarilyNotSupport } from '../utils'
2
+
3
+ // 周期性更新
4
+ export const setBackgroundFetchToken = temporarilyNotSupport('setBackgroundFetchToken')
5
+ export const onBackgroundFetchData = temporarilyNotSupport('onBackgroundFetchData')
6
+ export const getBackgroundFetchToken = temporarilyNotSupport('getBackgroundFetchToken')
7
+ export const getBackgroundFetchData = temporarilyNotSupport('getBackgroundFetchData')
@@ -0,0 +1,193 @@
1
+ import Taro from '@tarojs/api'
2
+ import { shouldBeObject, getParameterError, temporarilyNotSupport } from '../utils'
3
+ import { MethodHandler } from '../utils/handler'
4
+
5
+ // 数据缓存
6
+ const setStorageSync: typeof Taro.setStorageSync = (key, data = '') => {
7
+ if (typeof key !== 'string') {
8
+ console.error(getParameterError({
9
+ name: 'setStorage',
10
+ correct: 'String',
11
+ wrong: key
12
+ }))
13
+ return
14
+ }
15
+
16
+ const type = typeof data
17
+ let obj = {}
18
+
19
+ if (type === 'symbol') {
20
+ obj = { data: '' }
21
+ } else {
22
+ obj = { data }
23
+ }
24
+ localStorage.setItem(key, JSON.stringify(obj))
25
+ }
26
+
27
+ const setStorage: typeof Taro.setStorage = (options) => {
28
+ // options must be an Object
29
+ const isObject = shouldBeObject(options)
30
+ if (!isObject.flag) {
31
+ const res = { errMsg: `setStorage:fail ${isObject.msg}` }
32
+ console.error(res.errMsg)
33
+ return Promise.reject(res)
34
+ }
35
+
36
+ const { key, data, success, fail, complete } = options
37
+ const handle = new MethodHandler({ name: 'setStorage', success, fail, complete })
38
+
39
+ if (typeof key !== 'string') {
40
+ return handle.fail({
41
+ errMsg: getParameterError({
42
+ para: 'key',
43
+ correct: 'String',
44
+ wrong: key
45
+ })
46
+ })
47
+ }
48
+
49
+ setStorageSync(key, data)
50
+ return handle.success()
51
+ }
52
+
53
+ const getStorage: typeof Taro.getStorage = <T>(options) => {
54
+ // options must be an Object
55
+ const isObject = shouldBeObject(options)
56
+ if (!isObject.flag) {
57
+ const res = { errMsg: `getStorage:fail ${isObject.msg}` }
58
+ console.error(res.errMsg)
59
+ return Promise.reject(res)
60
+ }
61
+
62
+ const { key, success, fail, complete } = options
63
+ const handle = new MethodHandler<Taro.getStorage.SuccessCallbackResult<T>>({ name: 'getStorage', success, fail, complete })
64
+
65
+ if (typeof key !== 'string') {
66
+ return handle.fail({
67
+ errMsg: getParameterError({
68
+ para: 'key',
69
+ correct: 'String',
70
+ wrong: key
71
+ })
72
+ })
73
+ }
74
+
75
+ const { result, data } = getItem(key)
76
+ if (result) {
77
+ return handle.success({ data })
78
+ } else {
79
+ return handle.fail({
80
+ errMsg: 'data not found'
81
+ })
82
+ }
83
+ }
84
+
85
+ const getStorageSync: typeof Taro.getStorageSync = (key) => {
86
+ if (typeof key !== 'string') {
87
+ console.error(getParameterError({
88
+ name: 'getStorageSync',
89
+ correct: 'String',
90
+ wrong: key
91
+ }))
92
+ return
93
+ }
94
+
95
+ const res = getItem(key)
96
+ if (res.result) return res.data
97
+
98
+ return ''
99
+ }
100
+
101
+ function getItem (key) {
102
+ let item
103
+ try {
104
+ item = JSON.parse(localStorage.getItem(key) || '')
105
+ } catch (e) {}
106
+
107
+ // 只返回使用 Taro.setStorage API 存储的数据
108
+ if (item && typeof item === 'object' && item.hasOwnProperty('data')) {
109
+ return { result: true, data: item.data }
110
+ } else {
111
+ return { result: false }
112
+ }
113
+ }
114
+
115
+ const getStorageInfoSync: typeof Taro.getStorageInfoSync = () => {
116
+ const res: Taro.getStorageInfoSync.Option = {
117
+ keys: Object.keys(localStorage),
118
+ limitSize: NaN,
119
+ currentSize: NaN
120
+ }
121
+ return res
122
+ }
123
+
124
+ const getStorageInfo: typeof Taro.getStorageInfo = ({ success, fail, complete } = {}) => {
125
+ const handle = new MethodHandler<Taro.getStorageInfo.SuccessCallbackOption>({ name: 'getStorageInfo', success, fail, complete })
126
+ return handle.success(getStorageInfoSync())
127
+ }
128
+
129
+ const removeStorageSync: typeof Taro.removeStorageSync = (key: string) => {
130
+ if (typeof key !== 'string') {
131
+ console.error(getParameterError({
132
+ name: 'removeStorage',
133
+ correct: 'String',
134
+ wrong: key
135
+ }))
136
+ return
137
+ }
138
+
139
+ localStorage.removeItem(key)
140
+ }
141
+
142
+ const removeStorage: typeof Taro.removeStorage = (options: Taro.removeStorage.Option) => {
143
+ // options must be an Object
144
+ const isObject = shouldBeObject(options)
145
+ if (!isObject.flag) {
146
+ const res = { errMsg: `removeStorage:fail ${isObject.msg}` }
147
+ console.error(res.errMsg)
148
+ return Promise.reject(res)
149
+ }
150
+ const { key, success, fail, complete } = options
151
+ const handle = new MethodHandler({ name: 'removeStorage', success, fail, complete })
152
+
153
+ if (typeof key !== 'string') {
154
+ return handle.fail({
155
+ errMsg: getParameterError({
156
+ para: 'key',
157
+ correct: 'String',
158
+ wrong: key
159
+ })
160
+ })
161
+ }
162
+
163
+ removeStorageSync(key)
164
+ return handle.success()
165
+ }
166
+
167
+ const clearStorage: typeof Taro.clearStorage = ({ success, fail, complete } = {}) => {
168
+ const handle = new MethodHandler({ name: 'clearStorage', success, fail, complete })
169
+ localStorage.clear()
170
+ return handle.success()
171
+ }
172
+
173
+ const clearStorageSync: typeof Taro.clearStorageSync = () => {
174
+ clearStorage()
175
+ }
176
+
177
+ const revokeBufferURL = temporarilyNotSupport('revokeBufferURL')
178
+
179
+ export {
180
+ setStorageSync,
181
+ setStorage,
182
+ revokeBufferURL,
183
+ removeStorageSync,
184
+ removeStorage,
185
+ getStorageSync,
186
+ getStorageInfoSync,
187
+ getStorageInfo,
188
+ getStorage,
189
+ clearStorageSync,
190
+ clearStorage
191
+ }
192
+
193
+ export * from './background-fetch'
@@ -0,0 +1,31 @@
1
+ import { temporarilyNotSupport } from '../utils'
2
+
3
+ export const setPageInfo = temporarilyNotSupport('setPageInfo')
4
+
5
+ // 百度小程序 AI 相关
6
+ export const ocrIdCard = temporarilyNotSupport('ocrIdCard')
7
+ export const ocrBankCard = temporarilyNotSupport('ocrBankCard')
8
+ export const ocrDrivingLicense = temporarilyNotSupport('ocrDrivingLicense')
9
+ export const ocrVehicleLicense = temporarilyNotSupport('ocrVehicleLicense')
10
+ export const textReview = temporarilyNotSupport('textReview')
11
+ export const textToAudio = temporarilyNotSupport('textToAudio')
12
+ export const imageAudit = temporarilyNotSupport('imageAudit')
13
+ export const advancedGeneralIdentify = temporarilyNotSupport('advancedGeneralIdentify')
14
+ export const objectDetectIdentify = temporarilyNotSupport('objectDetectIdentify')
15
+ export const carClassify = temporarilyNotSupport('carClassify')
16
+ export const dishClassify = temporarilyNotSupport('dishClassify')
17
+ export const logoClassify = temporarilyNotSupport('logoClassify')
18
+ export const animalClassify = temporarilyNotSupport('animalClassify')
19
+ export const plantClassify = temporarilyNotSupport('plantClassify')
20
+
21
+ // 用户信息
22
+ export const getSwanId = temporarilyNotSupport('getSwanId')
23
+
24
+ // 百度收银台支付
25
+ export const requestPolymerPayment = temporarilyNotSupport('requestPolymerPayment')
26
+
27
+ // 打开小程序
28
+ export const navigateToSmartGameProgram = temporarilyNotSupport('navigateToSmartGameProgram')
29
+ export const navigateToSmartProgram = temporarilyNotSupport('navigateToSmartProgram')
30
+ export const navigateBackSmartProgram = temporarilyNotSupport('navigateBackSmartProgram')
31
+ export const preloadSubPackage = temporarilyNotSupport('preloadSubPackage')
@@ -1,149 +1,133 @@
1
- import Taro from '@tarojs/api'
2
-
3
- import {
4
- history,
5
- navigateBack,
6
- navigateTo,
7
- createRouter,
8
- reLaunch,
9
- redirectTo,
10
- getCurrentPages,
11
- switchTab
12
- } from '@tarojs/router'
13
- import { permanentlyNotSupport } from '../api/utils'
14
-
15
- const {
16
- Behavior,
17
- getEnv,
18
- ENV_TYPE,
19
- Link,
20
- interceptors,
21
- getInitPxTransform,
22
- Current,
23
- getCurrentInstance,
24
- options,
25
- nextTick,
26
- eventCenter,
27
- Events,
28
- preload,
29
- useDidShow,
30
- useDidHide,
31
- usePullDownRefresh,
32
- useReachBottom,
33
- usePageScroll,
34
- useResize,
35
- useShareAppMessage,
36
- useTabItemTap,
37
- useTitleClick,
38
- useOptionMenuClick,
39
- usePullIntercept,
40
- useShareTimeline,
41
- useAddToFavorites,
42
- useReady,
43
- useRouter
44
- } = Taro
45
-
46
- const taro = {
47
- Behavior,
48
- getEnv,
49
- ENV_TYPE,
50
- Link,
51
- interceptors,
52
- Current,
53
- getCurrentInstance,
54
- options,
55
- nextTick,
56
- eventCenter,
57
- Events,
58
- preload,
59
- history,
60
- navigateBack,
61
- navigateTo,
62
- createRouter,
63
- reLaunch,
64
- redirectTo,
65
- getCurrentPages,
66
- switchTab,
67
- useDidShow,
68
- useDidHide,
69
- usePullDownRefresh,
70
- useReachBottom,
71
- usePageScroll,
72
- useResize,
73
- useShareAppMessage,
74
- useTabItemTap,
75
- useTitleClick,
76
- useOptionMenuClick,
77
- usePullIntercept,
78
- useShareTimeline,
79
- useAddToFavorites,
80
- useReady,
81
- useRouter
82
- }
83
-
84
- const initPxTransform = getInitPxTransform(taro)
85
-
86
- const requirePlugin = permanentlyNotSupport('requirePlugin')
87
- const getApp = function () {
88
- return getCurrentInstance().app
89
- }
90
-
91
- const pxTransform = function (size) {
92
- const { designWidth } = taro.config
93
- return Math.ceil((((parseInt(size, 10) / 40) * 640) / designWidth) * 10000) / 10000 + 'rem'
94
- }
95
- const canIUseWebp = function () {
96
- const canvas = document.createElement('canvas')
97
- return canvas.toDataURL('image/webp').indexOf('data:image/webp') === 0
98
- }
99
-
100
- taro.requirePlugin = requirePlugin
101
- taro.getApp = getApp
102
- taro.pxTransform = pxTransform
103
- taro.initPxTransform = initPxTransform
104
- taro.canIUseWebp = canIUseWebp
105
-
106
- export default taro
107
-
108
- export {
109
- Behavior,
110
- getEnv,
111
- ENV_TYPE,
112
- Link,
113
- interceptors,
114
- initPxTransform,
115
- Current,
116
- getCurrentInstance,
117
- options,
118
- nextTick,
119
- eventCenter,
120
- Events,
121
- preload,
122
- requirePlugin,
123
- getApp,
124
- pxTransform,
125
- canIUseWebp,
126
- history,
127
- navigateBack,
128
- navigateTo,
129
- createRouter,
130
- reLaunch,
131
- redirectTo,
132
- getCurrentPages,
133
- switchTab,
134
- useDidShow,
135
- useDidHide,
136
- usePullDownRefresh,
137
- useReachBottom,
138
- usePageScroll,
139
- useResize,
140
- useShareAppMessage,
141
- useTabItemTap,
142
- useTitleClick,
143
- useOptionMenuClick,
144
- usePullIntercept,
145
- useShareTimeline,
146
- useAddToFavorites,
147
- useReady,
148
- useRouter
149
- }
1
+ import Taro from '@tarojs/api'
2
+
3
+ import {
4
+ history,
5
+ createRouter
6
+ } from '@tarojs/router'
7
+ import { getApp, getCurrentInstance, getCurrentPages, nextTick, navigateBack, navigateTo, reLaunch, redirectTo, switchTab } from '../api'
8
+ import { permanentlyNotSupport } from '../api/utils'
9
+
10
+ const {
11
+ Behavior,
12
+ getEnv,
13
+ ENV_TYPE,
14
+ Link,
15
+ interceptors,
16
+ getInitPxTransform,
17
+ Current,
18
+ options,
19
+ eventCenter,
20
+ Events,
21
+ preload,
22
+ useDidShow,
23
+ useDidHide,
24
+ usePullDownRefresh,
25
+ useReachBottom,
26
+ usePageScroll,
27
+ useResize,
28
+ useShareAppMessage,
29
+ useTabItemTap,
30
+ useTitleClick,
31
+ useOptionMenuClick,
32
+ usePullIntercept,
33
+ useShareTimeline,
34
+ useAddToFavorites,
35
+ useReady,
36
+ useRouter
37
+ } = Taro as any
38
+
39
+ const taro: typeof Taro = {
40
+ // @ts-ignore
41
+ Behavior,
42
+ getEnv,
43
+ ENV_TYPE,
44
+ Link,
45
+ interceptors,
46
+ Current,
47
+ getCurrentInstance,
48
+ options,
49
+ nextTick,
50
+ eventCenter,
51
+ Events,
52
+ preload,
53
+ history,
54
+ createRouter,
55
+ navigateBack,
56
+ navigateTo,
57
+ reLaunch,
58
+ redirectTo,
59
+ getCurrentPages,
60
+ switchTab,
61
+ useDidShow,
62
+ useDidHide,
63
+ usePullDownRefresh,
64
+ useReachBottom,
65
+ usePageScroll,
66
+ useResize,
67
+ useShareAppMessage,
68
+ useTabItemTap,
69
+ useTitleClick,
70
+ useOptionMenuClick,
71
+ usePullIntercept,
72
+ useShareTimeline,
73
+ useAddToFavorites,
74
+ useReady,
75
+ useRouter
76
+ }
77
+
78
+ const initPxTransform = getInitPxTransform(taro)
79
+
80
+ const requirePlugin = permanentlyNotSupport('requirePlugin')
81
+
82
+ const pxTransform = function (size) {
83
+ // @ts-ignore
84
+ const { designWidth } = taro.config
85
+ return Math.ceil((((parseInt(size, 10) / 40) * 640) / designWidth) * 10000) / 10000 + 'rem'
86
+ }
87
+ const canIUseWebp = function () {
88
+ const canvas = document.createElement('canvas')
89
+ return canvas.toDataURL('image/webp').indexOf('data:image/webp') === 0
90
+ }
91
+
92
+ taro.requirePlugin = requirePlugin
93
+ taro.getApp = getApp
94
+ taro.pxTransform = pxTransform
95
+ taro.initPxTransform = initPxTransform
96
+ // @ts-ignore
97
+ taro.canIUseWebp = canIUseWebp
98
+
99
+ export default taro
100
+
101
+ export {
102
+ Behavior,
103
+ getEnv,
104
+ ENV_TYPE,
105
+ Link,
106
+ interceptors,
107
+ initPxTransform,
108
+ Current,
109
+ options,
110
+ eventCenter,
111
+ Events,
112
+ preload,
113
+ requirePlugin,
114
+ pxTransform,
115
+ canIUseWebp,
116
+ history,
117
+ createRouter,
118
+ useDidShow,
119
+ useDidHide,
120
+ usePullDownRefresh,
121
+ useReachBottom,
122
+ usePageScroll,
123
+ useResize,
124
+ useShareAppMessage,
125
+ useTabItemTap,
126
+ useTitleClick,
127
+ useOptionMenuClick,
128
+ usePullIntercept,
129
+ useShareTimeline,
130
+ useAddToFavorites,
131
+ useReady,
132
+ useRouter
133
+ }
@@ -7,14 +7,14 @@ class StyleSheet {
7
7
  this.$style = document.createElement('style')
8
8
  }
9
9
 
10
- $style = null
11
- sheet = null
10
+ $style: HTMLStyleElement
11
+ sheet?: CSSStyleSheet | null
12
12
  appendStyleSheet = () => {
13
- this.$style.setAttribute('type', 'text/css')
14
- this.$style.setAttribute('data-type', 'Taro')
13
+ this.$style?.setAttribute('type', 'text/css')
14
+ this.$style?.setAttribute('data-type', 'Taro')
15
15
  document.getElementsByTagName('head')[0].appendChild(this.$style)
16
- this.sheet = this.$style.sheet
17
- if (!('insertRule' in this.sheet)) {
16
+ this.sheet = this.$style?.sheet
17
+ if (this.sheet && !('insertRule' in this.sheet)) {
18
18
  console.warn('当前浏览器不支持 stylesheet.insertRule 接口')
19
19
  }
20
20
  }
@@ -25,7 +25,7 @@ class StyleSheet {
25
25
  // $style 未插入到 DOM
26
26
  this.appendStyleSheet()
27
27
  }
28
- this.sheet.insertRule(cssText, index)
28
+ this.sheet?.insertRule(cssText, index)
29
29
  }
30
30
  }
31
31
 
@@ -62,8 +62,19 @@ if ($detect.style['animation-name'] === 'standard') {
62
62
 
63
63
  let animId = 0
64
64
 
65
+ interface IAnimationAttr {
66
+ duration: number
67
+ delay: number
68
+ timingFunction: string
69
+ transformOrigin: string
70
+ }
71
+
65
72
  // Animation 类
66
73
  class Animation {
74
+ unit: string
75
+ id: number
76
+ DEFAULT: IAnimationAttr
77
+
67
78
  constructor (
68
79
  {
69
80
  duration = 400,
@@ -81,8 +92,8 @@ class Animation {
81
92
  // 动画 id
82
93
  this.id = ++animId
83
94
  // 监听事件
84
- document.body.addEventListener(TRANSITION_END, e => {
85
- const { target } = e
95
+ document.body.addEventListener(TRANSITION_END, (e: TransitionEvent) => {
96
+ const target = e.target as HTMLElement
86
97
  if (target.getAttribute(animAttr) === null) {
87
98
  animAttr = 'data-animation'
88
99
  }
@@ -91,7 +102,8 @@ class Animation {
91
102
  if (animData === null) return
92
103
  const [animName, animPath] = animData.split('__')
93
104
  if (animName === `taro-h5-poly-fill/${this.id}/create-animation`) {
94
- const [animIndex, stepIndex = 0] = animPath.split('--')
105
+ const [animIndex, __stepIndex = 0] = animPath.split('--')
106
+ const stepIndex = Number(__stepIndex)
95
107
  // 动画总的关键帧
96
108
  const animStepsCount = this.animationMap[`${animName}__${animIndex}`]
97
109
  const animStepsMaxIndex = animStepsCount - 1
@@ -108,7 +120,7 @@ class Animation {
108
120
  }
109
121
 
110
122
  transformUnit (...args) {
111
- const ret = []
123
+ const ret: string[] = []
112
124
  args.forEach(each => {
113
125
  ret.push(isNaN(each) ? each : `${each}${this.unit}`)
114
126
  })
@@ -121,11 +133,11 @@ class Animation {
121
133
  }
122
134
 
123
135
  // 属性组合
124
- rules = []
136
+ rules: string[] = []
125
137
  // transform 对象
126
138
  transform = [`${TRANSFORM}:`]
127
139
  // 组合动画
128
- steps = []
140
+ steps: string[] = []
129
141
  // 动画 map ----- 永久保留
130
142
  animationMap = {}
131
143
  // animationMap 的长度
@@ -284,7 +296,7 @@ class Animation {
284
296
  }
285
297
 
286
298
  // 关键帧载入
287
- step (arg = {}) {
299
+ step (arg: Partial<IAnimationAttr> = {}) {
288
300
  const { DEFAULT } = this
289
301
  const {
290
302
  duration = DEFAULT.duration,
@@ -0,0 +1,5 @@
1
+ import { temporarilyNotSupport } from '../utils'
2
+
3
+ // 背景
4
+ export const setBackgroundTextStyle = temporarilyNotSupport('setBackgroundTextStyle')
5
+ export const setBackgroundColor = temporarilyNotSupport('setBackgroundColor')
@@ -0,0 +1,4 @@
1
+ import Taro from '@tarojs/api'
2
+
3
+ // 自定义组件
4
+ export const nextTick = Taro.nextTick
@@ -0,0 +1,4 @@
1
+ import { temporarilyNotSupport } from '../utils'
2
+
3
+ // 字体
4
+ export const loadFontFace = temporarilyNotSupport('loadFontFace')
@@ -0,0 +1,12 @@
1
+ export * from './animation'
2
+ export * from './background'
3
+ export * from './custom-component'
4
+ export * from './fonts'
5
+ export * from './menu'
6
+ export * from './navigation-bar'
7
+ export * from './pull-down-refresh'
8
+ export * from './scroll'
9
+ export * from './sticky'
10
+ export * from './tab-bar'
11
+ export * from './window'
12
+ export * from './interaction'