@tarojs/taro-h5 3.4.0-beta.0 → 3.4.0-beta.1

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 (175) hide show
  1. package/dist/index.cjs.js +7971 -9468
  2. package/dist/index.js +10767 -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 +27 -0
  22. package/src/api/canvas/canvasPutImageData.ts +24 -0
  23. package/src/api/canvas/canvasToTempFilePath.ts +24 -0
  24. package/src/api/canvas/createCanvasContext.ts +18 -0
  25. package/src/api/canvas/index.ts +10 -0
  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 +87 -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 +67 -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 +85 -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 +105 -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 +78 -0
  63. package/src/api/media/image/getImageInfo.ts +35 -0
  64. package/src/api/media/image/index.ts +13 -0
  65. package/src/api/media/image/previewImage.ts +101 -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 -27
  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 -32
  83. package/src/api/{fileTransfer/utils.js → network/utils.ts} +0 -0
  84. package/src/api/network/websocket/index.ts +88 -0
  85. package/src/api/{webSocket/socketTask.js → network/websocket/socketTask.ts} +17 -7
  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 +181 -0
  110. package/src/api/swan/index.ts +31 -0
  111. package/src/{taro/index.js → api/taro.ts} +89 -104
  112. package/src/api/{createAnimation/index.js → ui/animation/index.ts} +51 -35
  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} +93 -77
  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 +27 -0
  124. package/src/api/ui/scroll/index.ts +85 -0
  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} +36 -115
  130. package/src/api/worker/index.ts +4 -0
  131. package/src/api/wxml/index.ts +9 -0
  132. package/src/api/wxml/nodesRef.ts +49 -0
  133. package/src/api/{createSelectorQuery/index.js → wxml/selectorQuery.ts} +75 -94
  134. package/src/index.ts +6 -0
  135. package/src/types/api.d.ts +4 -0
  136. package/src/types/define.d.ts +2 -0
  137. package/{types → src/types}/index.d.ts +0 -0
  138. package/{types → src/types}/type.ts +1 -1
  139. package/src/api/accelerometer/index.js +0 -105
  140. package/src/api/audio/index.js +0 -137
  141. package/src/api/canvas/canvasGetImageData.js +0 -44
  142. package/src/api/canvas/canvasPutImageData.js +0 -45
  143. package/src/api/canvas/canvasToTempFilePath.js +0 -49
  144. package/src/api/canvas/createCanvasContext.js +0 -340
  145. package/src/api/canvas/index.js +0 -4
  146. package/src/api/clipboard/index.js +0 -113
  147. package/src/api/compass/index.js +0 -99
  148. package/src/api/deviceMotion/index.js +0 -105
  149. package/src/api/fileTransfer/index.js +0 -2
  150. package/src/api/image/chooseImage.js +0 -87
  151. package/src/api/image/getImageInfo.js +0 -74
  152. package/src/api/image/index.js +0 -7
  153. package/src/api/image/previewImage.js +0 -94
  154. package/src/api/index.js +0 -29
  155. package/src/api/interactive/actionSheet.js +0 -214
  156. package/src/api/interactive/modal.js +0 -256
  157. package/src/api/location/chooseLocation.js +0 -143
  158. package/src/api/location/index.js +0 -5
  159. package/src/api/navigationBar/index.js +0 -57
  160. package/src/api/open/index.js +0 -5
  161. package/src/api/others/index.js +0 -43
  162. package/src/api/pullDownRefresh/index.js +0 -51
  163. package/src/api/scroll/index.js +0 -99
  164. package/src/api/storage/index.js +0 -211
  165. package/src/api/system/index.js +0 -9
  166. package/src/api/system/info.js +0 -36
  167. package/src/api/system/network.js +0 -68
  168. package/src/api/tabBar/index.js +0 -402
  169. package/src/api/unsupportedApi/index.js +0 -278
  170. package/src/api/vibrate/index.js +0 -49
  171. package/src/api/video/index.js +0 -87
  172. package/src/api/webSocket/index.js +0 -103
  173. package/src/api/window/index.js +0 -38
  174. package/src/index.cjs.js +0 -11
  175. package/src/index.js +0 -6
@@ -0,0 +1,6 @@
1
+ import { temporarilyNotSupport } from '../utils'
2
+
3
+ // 生物认证
4
+ export const startSoterAuthentication = temporarilyNotSupport('startSoterAuthentication')
5
+ export const checkIsSupportSoterAuthentication = temporarilyNotSupport('checkIsSupportSoterAuthentication')
6
+ export const checkIsSoterEnrolledInDevice = temporarilyNotSupport('checkIsSoterEnrolledInDevice')
@@ -0,0 +1,4 @@
1
+ import { temporarilyNotSupport } from '../utils'
2
+
3
+ // 订阅消息
4
+ export const requestSubscribeMessage = temporarilyNotSupport('requestSubscribeMessage')
@@ -0,0 +1,5 @@
1
+ import { temporarilyNotSupport } from '../utils'
2
+
3
+ // 用户信息
4
+ export const getUserProfile = temporarilyNotSupport('getUserProfile')
5
+ export const getUserInfo = temporarilyNotSupport('getUserInfo')
@@ -0,0 +1,5 @@
1
+ import { temporarilyNotSupport } from '../utils'
2
+
3
+ // 微信运动
4
+ export const shareToWeRun = temporarilyNotSupport('shareToWeRun')
5
+ export const getWeRunData = temporarilyNotSupport('getWeRunData')
@@ -0,0 +1,5 @@
1
+ import { temporarilyNotSupport } from '../utils'
2
+
3
+ // 支付
4
+ export const requestPayment = temporarilyNotSupport('requestPayment')
5
+ export const requestOrderPayment = temporarilyNotSupport('requestOrderPayment')
@@ -0,0 +1,10 @@
1
+ // 路由
2
+ export {
3
+ switchTab,
4
+ reLaunch,
5
+ redirectTo,
6
+ navigateTo,
7
+ navigateBack
8
+ } from '@tarojs/router'
9
+
10
+ // FIXME 方法导出类型未对齐,后续修复
@@ -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,181 @@
1
+ import Taro from '@tarojs/api'
2
+ import { shouldBeObject, getParameterError, temporarilyNotSupport } from '../utils'
3
+ import { MethodHandler } from '../utils/handler'
4
+
5
+ function getItem (key) {
6
+ let item
7
+ try {
8
+ item = JSON.parse(localStorage.getItem(key) || '')
9
+ } catch (e) {}
10
+
11
+ // 只返回使用 Taro.setStorage API 存储的数据
12
+ if (item && typeof item === 'object' && item.hasOwnProperty('data')) {
13
+ return { result: true, data: item.data }
14
+ } else {
15
+ return { result: false }
16
+ }
17
+ }
18
+
19
+ // 数据缓存
20
+ export const setStorageSync: typeof Taro.setStorageSync = (key, data = '') => {
21
+ if (typeof key !== 'string') {
22
+ console.error(getParameterError({
23
+ name: 'setStorage',
24
+ correct: 'String',
25
+ wrong: key
26
+ }))
27
+ return
28
+ }
29
+
30
+ const type = typeof data
31
+ let obj = {}
32
+
33
+ if (type === 'symbol') {
34
+ obj = { data: '' }
35
+ } else {
36
+ obj = { data }
37
+ }
38
+ localStorage.setItem(key, JSON.stringify(obj))
39
+ }
40
+
41
+ export const setStorage: typeof Taro.setStorage = (options) => {
42
+ // options must be an Object
43
+ const isObject = shouldBeObject(options)
44
+ if (!isObject.flag) {
45
+ const res = { errMsg: `setStorage:fail ${isObject.msg}` }
46
+ console.error(res.errMsg)
47
+ return Promise.reject(res)
48
+ }
49
+
50
+ const { key, data, success, fail, complete } = options
51
+ const handle = new MethodHandler({ name: 'setStorage', success, fail, complete })
52
+
53
+ if (typeof key !== 'string') {
54
+ return handle.fail({
55
+ errMsg: getParameterError({
56
+ para: 'key',
57
+ correct: 'String',
58
+ wrong: key
59
+ })
60
+ })
61
+ }
62
+
63
+ setStorageSync(key, data)
64
+ return handle.success()
65
+ }
66
+
67
+ export const revokeBufferURL = temporarilyNotSupport('revokeBufferURL')
68
+
69
+ export const removeStorageSync: typeof Taro.removeStorageSync = (key: string) => {
70
+ if (typeof key !== 'string') {
71
+ console.error(getParameterError({
72
+ name: 'removeStorage',
73
+ correct: 'String',
74
+ wrong: key
75
+ }))
76
+ return
77
+ }
78
+
79
+ localStorage.removeItem(key)
80
+ }
81
+
82
+ export const removeStorage: typeof Taro.removeStorage = (options: Taro.removeStorage.Option) => {
83
+ // options must be an Object
84
+ const isObject = shouldBeObject(options)
85
+ if (!isObject.flag) {
86
+ const res = { errMsg: `removeStorage:fail ${isObject.msg}` }
87
+ console.error(res.errMsg)
88
+ return Promise.reject(res)
89
+ }
90
+ const { key, success, fail, complete } = options
91
+ const handle = new MethodHandler({ name: 'removeStorage', success, fail, complete })
92
+
93
+ if (typeof key !== 'string') {
94
+ return handle.fail({
95
+ errMsg: getParameterError({
96
+ para: 'key',
97
+ correct: 'String',
98
+ wrong: key
99
+ })
100
+ })
101
+ }
102
+
103
+ removeStorageSync(key)
104
+ return handle.success()
105
+ }
106
+
107
+ export const getStorageSync: typeof Taro.getStorageSync = (key) => {
108
+ if (typeof key !== 'string') {
109
+ console.error(getParameterError({
110
+ name: 'getStorageSync',
111
+ correct: 'String',
112
+ wrong: key
113
+ }))
114
+ return
115
+ }
116
+
117
+ const res = getItem(key)
118
+ if (res.result) return res.data
119
+
120
+ return ''
121
+ }
122
+
123
+ export const getStorageInfoSync: typeof Taro.getStorageInfoSync = () => {
124
+ const res: Taro.getStorageInfoSync.Option = {
125
+ keys: Object.keys(localStorage),
126
+ limitSize: NaN,
127
+ currentSize: NaN
128
+ }
129
+ return res
130
+ }
131
+
132
+ export const getStorageInfo: typeof Taro.getStorageInfo = ({ success, fail, complete } = {}) => {
133
+ const handle = new MethodHandler<Taro.getStorageInfo.SuccessCallbackOption>({ name: 'getStorageInfo', success, fail, complete })
134
+ return handle.success(getStorageInfoSync())
135
+ }
136
+
137
+ export const getStorage: typeof Taro.getStorage = <T>(options) => {
138
+ // options must be an Object
139
+ const isObject = shouldBeObject(options)
140
+ if (!isObject.flag) {
141
+ const res = { errMsg: `getStorage:fail ${isObject.msg}` }
142
+ console.error(res.errMsg)
143
+ return Promise.reject(res)
144
+ }
145
+
146
+ const { key, success, fail, complete } = options
147
+ const handle = new MethodHandler<Taro.getStorage.SuccessCallbackResult<T>>({ name: 'getStorage', success, fail, complete })
148
+
149
+ if (typeof key !== 'string') {
150
+ return handle.fail({
151
+ errMsg: getParameterError({
152
+ para: 'key',
153
+ correct: 'String',
154
+ wrong: key
155
+ })
156
+ })
157
+ }
158
+
159
+ const { result, data } = getItem(key)
160
+ if (result) {
161
+ return handle.success({ data })
162
+ } else {
163
+ return handle.fail({
164
+ errMsg: 'data not found'
165
+ })
166
+ }
167
+ }
168
+
169
+ export const createBufferURL = temporarilyNotSupport('createBufferURL')
170
+
171
+ export const clearStorageSync: typeof Taro.clearStorageSync = () => {
172
+ localStorage.clear()
173
+ }
174
+
175
+ export const clearStorage: typeof Taro.clearStorage = ({ success, fail, complete } = {}) => {
176
+ const handle = new MethodHandler({ name: 'clearStorage', success, fail, complete })
177
+ clearStorageSync()
178
+ return handle.success()
179
+ }
180
+
181
+ 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,104 +1,89 @@
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
- } = Taro
30
-
31
- const taro = {
32
- Behavior,
33
- getEnv,
34
- ENV_TYPE,
35
- Link,
36
- interceptors,
37
- Current,
38
- getCurrentInstance,
39
- options,
40
- nextTick,
41
- eventCenter,
42
- Events,
43
- preload,
44
- history,
45
- navigateBack,
46
- navigateTo,
47
- createRouter,
48
- reLaunch,
49
- redirectTo,
50
- getCurrentPages,
51
- switchTab
52
- }
53
-
54
- const initPxTransform = getInitPxTransform(taro)
55
-
56
- const requirePlugin = permanentlyNotSupport('requirePlugin')
57
- const getApp = function () {
58
- return getCurrentInstance().app
59
- }
60
-
61
- const pxTransform = function (size) {
62
- const { designWidth } = taro.config
63
- return Math.ceil((((parseInt(size, 10) / 40) * 640) / designWidth) * 10000) / 10000 + 'rem'
64
- }
65
- const canIUseWebp = function () {
66
- const canvas = document.createElement('canvas')
67
- return canvas.toDataURL('image/webp').indexOf('data:image/webp') === 0
68
- }
69
-
70
- taro.requirePlugin = requirePlugin
71
- taro.getApp = getApp
72
- taro.pxTransform = pxTransform
73
- taro.initPxTransform = initPxTransform
74
- taro.canIUseWebp = canIUseWebp
75
-
76
- export default taro
77
-
78
- export {
79
- Behavior,
80
- getEnv,
81
- ENV_TYPE,
82
- Link,
83
- interceptors,
84
- initPxTransform,
85
- Current,
86
- getCurrentInstance,
87
- options,
88
- nextTick,
89
- eventCenter,
90
- Events,
91
- preload,
92
- requirePlugin,
93
- getApp,
94
- pxTransform,
95
- canIUseWebp,
96
- history,
97
- navigateBack,
98
- navigateTo,
99
- createRouter,
100
- reLaunch,
101
- redirectTo,
102
- getCurrentPages,
103
- switchTab
104
- }
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
+ } = Taro as any
23
+
24
+ const taro: typeof Taro = {
25
+ // @ts-ignore
26
+ Behavior,
27
+ getEnv,
28
+ ENV_TYPE,
29
+ Link,
30
+ interceptors,
31
+ Current,
32
+ getCurrentInstance,
33
+ options,
34
+ nextTick,
35
+ eventCenter,
36
+ Events,
37
+ preload,
38
+ history,
39
+ createRouter,
40
+ navigateBack,
41
+ navigateTo,
42
+ reLaunch,
43
+ redirectTo,
44
+ getCurrentPages,
45
+ switchTab
46
+ }
47
+
48
+ const initPxTransform = getInitPxTransform(taro)
49
+
50
+ const requirePlugin = permanentlyNotSupport('requirePlugin')
51
+
52
+ const pxTransform = function (size) {
53
+ // @ts-ignore
54
+ const { designWidth } = taro.config
55
+ return Math.ceil((((parseInt(size, 10) / 40) * 640) / designWidth) * 10000) / 10000 + 'rem'
56
+ }
57
+
58
+ const canIUseWebp = function () {
59
+ const canvas = document.createElement('canvas')
60
+ return canvas.toDataURL('image/webp').indexOf('data:image/webp') === 0
61
+ }
62
+
63
+ taro.requirePlugin = requirePlugin
64
+ taro.getApp = getApp
65
+ taro.pxTransform = pxTransform
66
+ taro.initPxTransform = initPxTransform
67
+ // @ts-ignore
68
+ taro.canIUseWebp = canIUseWebp
69
+
70
+ export default taro
71
+
72
+ export {
73
+ Behavior,
74
+ getEnv,
75
+ ENV_TYPE,
76
+ Link,
77
+ interceptors,
78
+ initPxTransform,
79
+ Current,
80
+ options,
81
+ eventCenter,
82
+ Events,
83
+ preload,
84
+ requirePlugin,
85
+ pxTransform,
86
+ canIUseWebp,
87
+ history,
88
+ createRouter
89
+ }
@@ -1,3 +1,5 @@
1
+ import Taro from '@tarojs/api'
2
+
1
3
  /**
2
4
  * H5 下的 styleSheet 操作
3
5
  * @author leeenx
@@ -7,14 +9,14 @@ class StyleSheet {
7
9
  this.$style = document.createElement('style')
8
10
  }
9
11
 
10
- $style = null
11
- sheet = null
12
+ $style: HTMLStyleElement
13
+ sheet?: CSSStyleSheet | null
12
14
  appendStyleSheet = () => {
13
- this.$style.setAttribute('type', 'text/css')
14
- this.$style.setAttribute('data-type', 'Taro')
15
+ this.$style?.setAttribute('type', 'text/css')
16
+ this.$style?.setAttribute('data-type', 'Taro')
15
17
  document.getElementsByTagName('head')[0].appendChild(this.$style)
16
- this.sheet = this.$style.sheet
17
- if (!('insertRule' in this.sheet)) {
18
+ this.sheet = this.$style?.sheet
19
+ if (this.sheet && !('insertRule' in this.sheet)) {
18
20
  console.warn('当前浏览器不支持 stylesheet.insertRule 接口')
19
21
  }
20
22
  }
@@ -25,7 +27,7 @@ class StyleSheet {
25
27
  // $style 未插入到 DOM
26
28
  this.appendStyleSheet()
27
29
  }
28
- this.sheet.insertRule(cssText, index)
30
+ this.sheet?.insertRule(cssText, index)
29
31
  }
30
32
  }
31
33
 
@@ -48,22 +50,32 @@ if ($detect.style['animation-name'] === 'standard') {
48
50
  TRANSFORM = 'transform'
49
51
  } else if ($detect.style['-webkit-animation-name'] === 'webkit') {
50
52
  // webkit 前缀
51
- TRANSITION_END = 'webkitTransionEnd'
53
+ TRANSITION_END = 'webkitTransitionEnd'
52
54
  TRANSFORM = '-webkit-transform'
53
55
  } else if ($detect.style['-moz-animation-name'] === 'moz') {
54
- // webkit 前缀
55
- TRANSITION_END = 'mozTransionEnd'
56
+ // moz 前缀
57
+ TRANSITION_END = 'mozTransitionEnd'
56
58
  TRANSFORM = '-moz-transform'
57
59
  } else if ($detect.style['-ms-animation-name'] === 'ms') {
58
- // webkit 前缀
59
- TRANSITION_END = 'MSTransionEnd'
60
+ // ms 前缀
61
+ TRANSITION_END = 'msTransitionEnd'
60
62
  TRANSFORM = '-ms-transform'
61
63
  }
62
64
 
63
65
  let animId = 0
64
66
 
65
- // Animation
66
- class Animation {
67
+ interface IAnimationAttr {
68
+ duration: number
69
+ delay: number
70
+ timingFunction: string
71
+ transformOrigin: string
72
+ }
73
+
74
+ class Animation implements Taro.Animation {
75
+ unit: string
76
+ id: number
77
+ DEFAULT: IAnimationAttr
78
+
67
79
  constructor (
68
80
  {
69
81
  duration = 400,
@@ -71,7 +83,7 @@ class Animation {
71
83
  timingFunction = 'linear',
72
84
  transformOrigin = '50% 50% 0',
73
85
  unit = 'px'
74
- } = {}
86
+ }: Taro.createAnimation.Option = {}
75
87
  ) {
76
88
  // 默认值
77
89
  this.setDefault(duration, delay, timingFunction, transformOrigin)
@@ -81,8 +93,8 @@ class Animation {
81
93
  // 动画 id
82
94
  this.id = ++animId
83
95
  // 监听事件
84
- document.body.addEventListener(TRANSITION_END, e => {
85
- const { target } = e
96
+ document.body.addEventListener(TRANSITION_END, (e: TransitionEvent) => {
97
+ const target = e.target as HTMLElement
86
98
  if (target.getAttribute(animAttr) === null) {
87
99
  animAttr = 'data-animation'
88
100
  }
@@ -91,12 +103,13 @@ class Animation {
91
103
  if (animData === null) return
92
104
  const [animName, animPath] = animData.split('__')
93
105
  if (animName === `taro-h5-poly-fill/${this.id}/create-animation`) {
94
- const [animIndex, stepIndex = 0] = animPath.split('--')
106
+ const [animIndex, __stepIndex = 0] = animPath.split('--')
107
+ const stepIndex = Number(__stepIndex)
95
108
  // 动画总的关键帧
96
109
  const animStepsCount = this.animationMap[`${animName}__${animIndex}`]
97
110
  const animStepsMaxIndex = animStepsCount - 1
98
111
  if (stepIndex < animStepsMaxIndex) {
99
- // 播放下一个关键帧(因为 nevr 和 react 有差异所以 animation & data-animation 都需要写)
112
+ // 播放下一个关键帧(因为 nerv 和 react 有差异所以 animation & data-animation 都需要写)
100
113
  target.setAttribute(animAttr, `${animName}__${animIndex}--${stepIndex + 1}`)
101
114
  if (animAttr === 'animation') {
102
115
  // Nerv 环境,animation & data-animation 双重保险
@@ -108,7 +121,7 @@ class Animation {
108
121
  }
109
122
 
110
123
  transformUnit (...args) {
111
- const ret = []
124
+ const ret: string[] = []
112
125
  args.forEach(each => {
113
126
  ret.push(isNaN(each) ? each : `${each}${this.unit}`)
114
127
  })
@@ -121,32 +134,37 @@ class Animation {
121
134
  }
122
135
 
123
136
  // 属性组合
124
- rules = []
137
+ rules: string[] = []
125
138
  // transform 对象
126
139
  transform = [`${TRANSFORM}:`]
127
140
  // 组合动画
128
- steps = []
141
+ steps: string[] = []
129
142
  // 动画 map ----- 永久保留
130
143
  animationMap = {}
131
144
  // animationMap 的长度
132
145
  animationMapCount = 0
133
- matrix (a, b, c, d, e, f) {
134
- this.transform.push(`matrix(${a}, ${b}, ${c}, ${d}, ${e}, ${f})`)
146
+
147
+ matrix (a: number, b: number, c: number, d: number, tx: number, ty: number) {
148
+ this.transform.push(`matrix(${a}, ${b}, ${c}, ${d}, ${tx}, ${ty})`)
135
149
  return this
136
150
  }
137
151
 
138
- matrix3d (a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4) {
152
+ matrix3d (a1: number, b1: number, c1: number, d1: number, a2: number, b2: number, c2: number, d2: number, a3: number, b3: number, c3: number, d3: number, a4: number, b4: number, c4: number, d4: number) {
139
153
  this.transform.push(`matrix3d(${a1}, ${b1}, ${c1}, ${d1}, ${a2}, ${b2}, ${c2}, ${d2}, ${a3}, ${b3}, ${c3}, ${d3}, ${a4}, ${b4}, ${c4}, ${d4})`)
140
154
  return this
141
155
  }
142
156
 
143
- rotate (angle) {
157
+ rotate (angle: number) {
144
158
  this.transform.push(`rotate(${angle}deg)`)
145
159
  return this
146
160
  }
147
161
 
148
- rotate3d (x, y, z, angle) {
149
- this.transform.push(`rotate3d(${x}, ${y}, ${z}, ${angle}deg)`)
162
+ rotate3d (x: number, y?: number, z?: number, angle?: number) {
163
+ if (typeof y !== 'number') {
164
+ this.transform.push(`rotate3d(${x})`)
165
+ } else {
166
+ this.transform.push(`rotate3d(${x}, ${y || 0}, ${z || 0}, ${angle || 0}deg)`)
167
+ }
150
168
  return this
151
169
  }
152
170
 
@@ -284,7 +302,7 @@ class Animation {
284
302
  }
285
303
 
286
304
  // 关键帧载入
287
- step (arg = {}) {
305
+ step (arg: Partial<IAnimationAttr> = {}) {
288
306
  const { DEFAULT } = this
289
307
  const {
290
308
  duration = DEFAULT.duration,
@@ -306,7 +324,7 @@ class Animation {
306
324
  // 清空 rules 和 transform
307
325
  this.rules = []
308
326
  this.transform = [`${TRANSFORM}:`]
309
- return this
327
+ return this as Taro.Animation
310
328
  }
311
329
 
312
330
  // 创建底层数据
@@ -329,13 +347,11 @@ class Animation {
329
347
 
330
348
  // 动画数据产出
331
349
  export () {
332
- return this.createAnimationData()
350
+ return this.createAnimationData() as unknown as ReturnType<Taro.Animation['export']>
333
351
  }
334
352
  }
335
353
 
336
354
  // h5 的 createAnimation
337
- function createAnimation (...arg) {
338
- return new Animation(...arg)
355
+ export const createAnimation: typeof Taro.createAnimation = (option) => {
356
+ return new Animation(option)
339
357
  }
340
-
341
- export { createAnimation }
@@ -0,0 +1,5 @@
1
+ import { temporarilyNotSupport } from '../utils'
2
+
3
+ // 背景
4
+ export const setBackgroundTextStyle = temporarilyNotSupport('setBackgroundTextStyle')
5
+ export const setBackgroundColor = temporarilyNotSupport('setBackgroundColor')